ICU 4.2.1
Main Page
Related Pages
Modules
Data Structures
Files
File List
Globals
All
Data Structures
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
common
unicode
utf16.h
Go to the documentation of this file.
1
/*
2
*******************************************************************************
3
*
4
* Copyright (C) 1999-2008, International Business Machines
5
* Corporation and others. All Rights Reserved.
6
*
7
*******************************************************************************
8
* file name: utf16.h
9
* encoding: US-ASCII
10
* tab size: 8 (not used)
11
* indentation:4
12
*
13
* created on: 1999sep09
14
* created by: Markus W. Scherer
15
*/
16
34
#ifndef __UTF16_H__
35
#define __UTF16_H__
36
37
/* utf.h must be included first. */
38
#ifndef __UTF_H__
39
# include "
unicode/utf.h
"
40
#endif
41
42
/* single-code point definitions -------------------------------------------- */
43
50
#define U16_IS_SINGLE(c) !U_IS_SURROGATE(c)
51
58
#define U16_IS_LEAD(c) (((c)&0xfffffc00)==0xd800)
59
66
#define U16_IS_TRAIL(c) (((c)&0xfffffc00)==0xdc00)
67
74
#define U16_IS_SURROGATE(c) U_IS_SURROGATE(c)
75
83
#define U16_IS_SURROGATE_LEAD(c) (((c)&0x400)==0)
84
92
#define U16_IS_SURROGATE_TRAIL(c) (((c)&0x400)!=0)
93
98
#define U16_SURROGATE_OFFSET ((0xd800<<10UL)+0xdc00-0x10000)
99
111
#define U16_GET_SUPPLEMENTARY(lead, trail) \
112
(((UChar32)(lead)<<10UL)+(UChar32)(trail)-U16_SURROGATE_OFFSET)
113
114
122
#define U16_LEAD(supplementary) (UChar)(((supplementary)>>10)+0xd7c0)
123
131
#define U16_TRAIL(supplementary) (UChar)(((supplementary)&0x3ff)|0xdc00)
132
140
#define U16_LENGTH(c) ((uint32_t)(c)<=0xffff ? 1 : 2)
141
147
#define U16_MAX_LENGTH 2
148
166
#define U16_GET_UNSAFE(s, i, c) { \
167
(c)=(s)[i]; \
168
if(U16_IS_SURROGATE(c)) { \
169
if(U16_IS_SURROGATE_LEAD(c)) { \
170
(c)=U16_GET_SUPPLEMENTARY((c), (s)[(i)+1]); \
171
} else { \
172
(c)=U16_GET_SUPPLEMENTARY((s)[(i)-1], (c)); \
173
} \
174
} \
175
}
176
197
#define U16_GET(s, start, i, length, c) { \
198
(c)=(s)[i]; \
199
if(U16_IS_SURROGATE(c)) { \
200
uint16_t __c2; \
201
if(U16_IS_SURROGATE_LEAD(c)) { \
202
if((i)+1<(length) && U16_IS_TRAIL(__c2=(s)[(i)+1])) { \
203
(c)=U16_GET_SUPPLEMENTARY((c), __c2); \
204
} \
205
} else { \
206
if((i)-1>=(start) && U16_IS_LEAD(__c2=(s)[(i)-1])) { \
207
(c)=U16_GET_SUPPLEMENTARY(__c2, (c)); \
208
} \
209
} \
210
} \
211
}
212
213
/* definitions with forward iteration --------------------------------------- */
214
234
#define U16_NEXT_UNSAFE(s, i, c) { \
235
(c)=(s)[(i)++]; \
236
if(U16_IS_LEAD(c)) { \
237
(c)=U16_GET_SUPPLEMENTARY((c), (s)[(i)++]); \
238
} \
239
}
240
261
#define U16_NEXT(s, i, length, c) { \
262
(c)=(s)[(i)++]; \
263
if(U16_IS_LEAD(c)) { \
264
uint16_t __c2; \
265
if((i)<(length) && U16_IS_TRAIL(__c2=(s)[(i)])) { \
266
++(i); \
267
(c)=U16_GET_SUPPLEMENTARY((c), __c2); \
268
} \
269
} \
270
}
271
285
#define U16_APPEND_UNSAFE(s, i, c) { \
286
if((uint32_t)(c)<=0xffff) { \
287
(s)[(i)++]=(uint16_t)(c); \
288
} else { \
289
(s)[(i)++]=(uint16_t)(((c)>>10)+0xd7c0); \
290
(s)[(i)++]=(uint16_t)(((c)&0x3ff)|0xdc00); \
291
} \
292
}
293
311
#define U16_APPEND(s, i, capacity, c, isError) { \
312
if((uint32_t)(c)<=0xffff) { \
313
(s)[(i)++]=(uint16_t)(c); \
314
} else if((uint32_t)(c)<=0x10ffff && (i)+1<(capacity)) { \
315
(s)[(i)++]=(uint16_t)(((c)>>10)+0xd7c0); \
316
(s)[(i)++]=(uint16_t)(((c)&0x3ff)|0xdc00); \
317
} else
/* c>0x10ffff or not enough space */
{ \
318
(isError)=TRUE; \
319
} \
320
}
321
332
#define U16_FWD_1_UNSAFE(s, i) { \
333
if(U16_IS_LEAD((s)[(i)++])) { \
334
++(i); \
335
} \
336
}
337
349
#define U16_FWD_1(s, i, length) { \
350
if(U16_IS_LEAD((s)[(i)++]) && (i)<(length) && U16_IS_TRAIL((s)[i])) { \
351
++(i); \
352
} \
353
}
354
367
#define U16_FWD_N_UNSAFE(s, i, n) { \
368
int32_t __N=(n); \
369
while(__N>0) { \
370
U16_FWD_1_UNSAFE(s, i); \
371
--__N; \
372
} \
373
}
374
388
#define U16_FWD_N(s, i, length, n) { \
389
int32_t __N=(n); \
390
while(__N>0 && (i)<(length)) { \
391
U16_FWD_1(s, i, length); \
392
--__N; \
393
} \
394
}
395
409
#define U16_SET_CP_START_UNSAFE(s, i) { \
410
if(U16_IS_TRAIL((s)[i])) { \
411
--(i); \
412
} \
413
}
414
429
#define U16_SET_CP_START(s, start, i) { \
430
if(U16_IS_TRAIL((s)[i]) && (i)>(start) && U16_IS_LEAD((s)[(i)-1])) { \
431
--(i); \
432
} \
433
}
434
435
/* definitions with backward iteration -------------------------------------- */
436
457
#define U16_PREV_UNSAFE(s, i, c) { \
458
(c)=(s)[--(i)]; \
459
if(U16_IS_TRAIL(c)) { \
460
(c)=U16_GET_SUPPLEMENTARY((s)[--(i)], (c)); \
461
} \
462
}
463
485
#define U16_PREV(s, start, i, c) { \
486
(c)=(s)[--(i)]; \
487
if(U16_IS_TRAIL(c)) { \
488
uint16_t __c2; \
489
if((i)>(start) && U16_IS_LEAD(__c2=(s)[(i)-1])) { \
490
--(i); \
491
(c)=U16_GET_SUPPLEMENTARY(__c2, (c)); \
492
} \
493
} \
494
}
495
507
#define U16_BACK_1_UNSAFE(s, i) { \
508
if(U16_IS_TRAIL((s)[--(i)])) { \
509
--(i); \
510
} \
511
}
512
525
#define U16_BACK_1(s, start, i) { \
526
if(U16_IS_TRAIL((s)[--(i)]) && (i)>(start) && U16_IS_LEAD((s)[(i)-1])) { \
527
--(i); \
528
} \
529
}
530
544
#define U16_BACK_N_UNSAFE(s, i, n) { \
545
int32_t __N=(n); \
546
while(__N>0) { \
547
U16_BACK_1_UNSAFE(s, i); \
548
--__N; \
549
} \
550
}
551
566
#define U16_BACK_N(s, start, i, n) { \
567
int32_t __N=(n); \
568
while(__N>0 && (i)>(start)) { \
569
U16_BACK_1(s, start, i); \
570
--__N; \
571
} \
572
}
573
587
#define U16_SET_CP_LIMIT_UNSAFE(s, i) { \
588
if(U16_IS_LEAD((s)[(i)-1])) { \
589
++(i); \
590
} \
591
}
592
608
#define U16_SET_CP_LIMIT(s, start, i, length) { \
609
if((start)<(i) && (i)<(length) && U16_IS_LEAD((s)[(i)-1]) && U16_IS_TRAIL((s)[i])) { \
610
++(i); \
611
} \
612
}
613
614
#endif
utf.h
C API: Code point macros.
Generated by
1.8.5