utf16.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00034
00035
#ifndef __UTF_H__
00036
# include "unicode/utf.h"
00037
#endif
00038
00039
#ifndef __UTF16_H__
00040
#define __UTF16_H__
00041
00042
00043
00050 #define U16_IS_SINGLE(c) !U_IS_SURROGATE(c)
00051
00058 #define U16_IS_LEAD(c) (((c)&0xfffffc00)==0xd800)
00059
00066 #define U16_IS_TRAIL(c) (((c)&0xfffffc00)==0xdc00)
00067
00074 #define U16_IS_SURROGATE(c) U_IS_SURROGATE(c)
00075
00083 #define U16_IS_SURROGATE_LEAD(c) (((c)&0x400)==0)
00084
00089 #define U16_SURROGATE_OFFSET ((0xd800<<10UL)+0xdc00-0x10000)
00090
00102 #define U16_GET_SUPPLEMENTARY(lead, trail) \
00103
(((lead)<<10UL)+(trail)-U16_SURROGATE_OFFSET)
00104
00105
00113 #define U16_LEAD(supplementary) (UChar)(((supplementary)>>10)+0xd7c0)
00114
00122 #define U16_TRAIL(supplementary) (UChar)(((supplementary)&0x3ff)|0xdc00)
00123
00131 #define U16_LENGTH(c) ((uint32_t)(c)<=0xffff ? 1 : 2)
00132
00138 #define U16_MAX_LENGTH 2
00139
00157 #define U16_GET_UNSAFE(s, i, c) { \
00158
(c)=(s)[i]; \
00159
if(U16_IS_SURROGATE(c)) { \
00160
if(U16_IS_SURROGATE_LEAD(c)) { \
00161
(c)=U16_GET_SUPPLEMENTARY((c), (s)[(i)+1]); \
00162
} else { \
00163
(c)=U16_GET_SUPPLEMENTARY((s)[(i)-1], (c)); \
00164
} \
00165
} \
00166
}
00167
00188 #define U16_GET(s, start, i, length, c) { \
00189
(c)=(s)[i]; \
00190
if(U16_IS_SURROGATE(c)) { \
00191
uint16_t __c2; \
00192
if(U16_IS_SURROGATE_LEAD(c)) { \
00193
if((i)+1<(length) && U16_IS_TRAIL(__c2=(s)[(i)+1])) { \
00194
(c)=U16_GET_SUPPLEMENTARY((c), __c2); \
00195
} \
00196
} else { \
00197
if((i)-1>=(start) && U16_IS_LEAD(__c2=(s)[(i)-1])) { \
00198
(c)=U16_GET_SUPPLEMENTARY(__c2, (c)); \
00199
} \
00200
} \
00201
} \
00202
}
00203
00204
00205
00225 #define U16_NEXT_UNSAFE(s, i, c) { \
00226
(c)=(s)[(i)++]; \
00227
if(U16_IS_LEAD(c)) { \
00228
(c)=U16_GET_SUPPLEMENTARY((c), (s)[(i)++]); \
00229
} \
00230
}
00231
00252 #define U16_NEXT(s, i, length, c) { \
00253
(c)=(s)[(i)++]; \
00254
if(U16_IS_LEAD(c)) { \
00255
uint16_t __c2; \
00256
if((i)<(length) && U16_IS_TRAIL(__c2=(s)[(i)])) { \
00257
++(i); \
00258
(c)=U16_GET_SUPPLEMENTARY((c), __c2); \
00259
} \
00260
} \
00261
}
00262
00276 #define U16_APPEND_UNSAFE(s, i, c) { \
00277
if((uint32_t)(c)<=0xffff) { \
00278
(s)[(i)++]=(uint16_t)(c); \
00279
} else { \
00280
(s)[(i)++]=(uint16_t)(((c)>>10)+0xd7c0); \
00281
(s)[(i)++]=(uint16_t)(((c)&0x3ff)|0xdc00); \
00282
} \
00283
}
00284
00302 #define U16_APPEND(s, i, capacity, c, isError) { \
00303
if((uint32_t)(c)<=0xffff) { \
00304
(s)[(i)++]=(uint16_t)(c); \
00305
} else if((uint32_t)(c)<=0x10ffff && (i)+1<(capacity)) { \
00306
(s)[(i)++]=(uint16_t)(((c)>>10)+0xd7c0); \
00307
(s)[(i)++]=(uint16_t)(((c)&0x3ff)|0xdc00); \
00308
} else { \
00309 (isError)=TRUE; \
00310 } \
00311 }
00312
00323 #define U16_FWD_1_UNSAFE(s, i) { \
00324
if(U16_IS_LEAD((s)[(i)++])) { \
00325
++(i); \
00326
} \
00327
}
00328
00340 #define U16_FWD_1(s, i, length) { \
00341
if(U16_IS_LEAD((s)[(i)++]) && (i)<(length) && U16_IS_TRAIL((s)[i])) { \
00342
++(i); \
00343
} \
00344
}
00345
00358 #define U16_FWD_N_UNSAFE(s, i, n) { \
00359
int32_t __N=(n); \
00360
while(__N>0) { \
00361
U16_FWD_1_UNSAFE(s, i); \
00362
--__N; \
00363
} \
00364
}
00365
00379 #define U16_FWD_N(s, i, length, n) { \
00380
int32_t __N=(n); \
00381
while(__N>0 && (i)<(length)) { \
00382
U16_FWD_1(s, i, length); \
00383
--__N; \
00384
} \
00385
}
00386
00400 #define U16_SET_CP_START_UNSAFE(s, i) { \
00401
if(U16_IS_TRAIL((s)[i])) { \
00402
--(i); \
00403
} \
00404
}
00405
00420 #define U16_SET_CP_START(s, start, i) { \
00421
if(U16_IS_TRAIL((s)[i]) && (i)>(start) && U16_IS_LEAD((s)[(i)-1])) { \
00422
--(i); \
00423
} \
00424
}
00425
00426
00427
00448 #define U16_PREV_UNSAFE(s, i, c) { \
00449
(c)=(s)[--(i)]; \
00450
if(U16_IS_TRAIL(c)) { \
00451
(c)=U16_GET_SUPPLEMENTARY((s)[--(i)], (c)); \
00452
} \
00453
}
00454
00476 #define U16_PREV(s, start, i, c) { \
00477
(c)=(s)[--(i)]; \
00478
if(U16_IS_TRAIL(c)) { \
00479
uint16_t __c2; \
00480
if((i)>(start) && U16_IS_LEAD(__c2=(s)[(i)-1])) { \
00481
--(i); \
00482
(c)=U16_GET_SUPPLEMENTARY(__c2, (c)); \
00483
} \
00484
} \
00485
}
00486
00498 #define U16_BACK_1_UNSAFE(s, i) { \
00499
if(U16_IS_TRAIL((s)[--(i)])) { \
00500
--(i); \
00501
} \
00502
}
00503
00516 #define U16_BACK_1(s, start, i) { \
00517
if(U16_IS_TRAIL((s)[--(i)]) && (i)>(start) && U16_IS_LEAD((s)[(i)-1])) { \
00518
--(i); \
00519
} \
00520
}
00521
00535 #define U16_BACK_N_UNSAFE(s, i, n) { \
00536
int32_t __N=(n); \
00537
while(__N>0) { \
00538
U16_BACK_1_UNSAFE(s, i); \
00539
--__N; \
00540
} \
00541
}
00542
00557 #define U16_BACK_N(s, start, i, n) { \
00558
int32_t __N=(n); \
00559
while(__N>0 && (i)>(start)) { \
00560
U16_BACK_1(s, start, i); \
00561
--__N; \
00562
} \
00563
}
00564
00578 #define U16_SET_CP_LIMIT_UNSAFE(s, i) { \
00579
if(U16_IS_LEAD((s)[(i)-1])) { \
00580
++(i); \
00581
} \
00582
}
00583
00599 #define U16_SET_CP_LIMIT(s, start, i, length) { \
00600
if((start)<(i) && (i)<(length) && U16_IS_LEAD((s)[(i)-1]) && U16_IS_TRAIL((s)[i])) { \
00601
++(i); \
00602
} \
00603
}
00604
00605
#endif
Generated on Wed Sep 15 17:18:10 2004 for ICU 2.8 by
1.3.8