| OLD | NEW |
| 1 /* | 1 /* |
| 2 ******************************************************************************* | 2 ******************************************************************************* |
| 3 * | 3 * |
| 4 * Copyright (C) 1999-2004, International Business Machines | 4 * Copyright (C) 1999-2004, International Business Machines |
| 5 * Corporation and others. All Rights Reserved. | 5 * Corporation and others. All Rights Reserved. |
| 6 * | 6 * |
| 7 ******************************************************************************* | 7 ******************************************************************************* |
| 8 * file name: utf.h | 8 * file name: utf.h |
| 9 * encoding: US-ASCII | 9 * encoding: US-ASCII |
| 10 * tab size: 8 (not used) | 10 * tab size: 8 (not used) |
| 11 * indentation:4 | 11 * indentation:4 |
| 12 * | 12 * |
| 13 * created on: 1999sep09 | 13 * created on: 1999sep09 |
| 14 * created by: Markus W. Scherer | 14 * created by: Markus W. Scherer |
| 15 */ | 15 */ |
| 16 | 16 |
| 17 #ifndef BASE_THIRD_PARTY_ICU_ICU_UTF_H_ | 17 #ifndef BASE_THIRD_PARTY_ICU_ICU_UTF_H_ |
| 18 #define BASE_THIRD_PARTY_ICU_ICU_UTF_H_ | 18 #define BASE_THIRD_PARTY_ICU_ICU_UTF_H_ |
| 19 | 19 |
| 20 #include "base/basictypes.h" | 20 #include <stdint.h> |
| 21 | 21 |
| 22 namespace base_icu { | 22 namespace base_icu { |
| 23 | 23 |
| 24 typedef int32 UChar32; | 24 typedef int32_t UChar32; |
| 25 typedef uint16 UChar; | 25 typedef uint16_t UChar; |
| 26 typedef int8 UBool; | 26 typedef int8_t UBool; |
| 27 | 27 |
| 28 // General --------------------------------------------------------------------- | 28 // General --------------------------------------------------------------------- |
| 29 // from utf.h | 29 // from utf.h |
| 30 | 30 |
| 31 /** | 31 /** |
| 32 * This value is intended for sentinel values for APIs that | 32 * This value is intended for sentinel values for APIs that |
| 33 * (take or) return single code points (UChar32). | 33 * (take or) return single code points (UChar32). |
| 34 * It is outside of the Unicode code point range 0..0x10ffff. | 34 * It is outside of the Unicode code point range 0..0x10ffff. |
| 35 * | 35 * |
| 36 * For example, a "done" or "error" value in a new API | 36 * For example, a "done" or "error" value in a new API |
| (...skipping 10 matching lines...) Expand all Loading... |
| 47 * @stable ICU 2.4 | 47 * @stable ICU 2.4 |
| 48 */ | 48 */ |
| 49 #define CBU_SENTINEL (-1) | 49 #define CBU_SENTINEL (-1) |
| 50 | 50 |
| 51 /** | 51 /** |
| 52 * Is this code point a Unicode noncharacter? | 52 * Is this code point a Unicode noncharacter? |
| 53 * @param c 32-bit code point | 53 * @param c 32-bit code point |
| 54 * @return TRUE or FALSE | 54 * @return TRUE or FALSE |
| 55 * @stable ICU 2.4 | 55 * @stable ICU 2.4 |
| 56 */ | 56 */ |
| 57 #define CBU_IS_UNICODE_NONCHAR(c) \ | 57 #define CBU_IS_UNICODE_NONCHAR(c) \ |
| 58 ((c)>=0xfdd0 && \ | 58 ((c) >= 0xfdd0 && ((uint32_t)(c) <= 0xfdef || ((c)&0xfffe) == 0xfffe) && \ |
| 59 ((uint32)(c)<=0xfdef || ((c)&0xfffe)==0xfffe) && \ | 59 (uint32_t)(c) <= 0x10ffff) |
| 60 (uint32)(c)<=0x10ffff) | |
| 61 | 60 |
| 62 /** | 61 /** |
| 63 * Is c a Unicode code point value (0..U+10ffff) | 62 * Is c a Unicode code point value (0..U+10ffff) |
| 64 * that can be assigned a character? | 63 * that can be assigned a character? |
| 65 * | 64 * |
| 66 * Code points that are not characters include: | 65 * Code points that are not characters include: |
| 67 * - single surrogate code points (U+d800..U+dfff, 2048 code points) | 66 * - single surrogate code points (U+d800..U+dfff, 2048 code points) |
| 68 * - the last two code points on each plane (U+__fffe and U+__ffff, 34 code poin
ts) | 67 * - the last two code points on each plane (U+__fffe and U+__ffff, 34 code poin
ts) |
| 69 * - U+fdd0..U+fdef (new with Unicode 3.1, 32 code points) | 68 * - U+fdd0..U+fdef (new with Unicode 3.1, 32 code points) |
| 70 * - the highest Unicode code point value is U+10ffff | 69 * - the highest Unicode code point value is U+10ffff |
| 71 * | 70 * |
| 72 * This means that all code points below U+d800 are character code points, | 71 * This means that all code points below U+d800 are character code points, |
| 73 * and that boundary is tested first for performance. | 72 * and that boundary is tested first for performance. |
| 74 * | 73 * |
| 75 * @param c 32-bit code point | 74 * @param c 32-bit code point |
| 76 * @return TRUE or FALSE | 75 * @return TRUE or FALSE |
| 77 * @stable ICU 2.4 | 76 * @stable ICU 2.4 |
| 78 */ | 77 */ |
| 79 #define CBU_IS_UNICODE_CHAR(c) \ | 78 #define CBU_IS_UNICODE_CHAR(c) \ |
| 80 ((uint32)(c)<0xd800 || \ | 79 ((uint32_t)(c) < 0xd800 || \ |
| 81 ((uint32)(c)>0xdfff && \ | 80 ((uint32_t)(c) > 0xdfff && (uint32_t)(c) <= 0x10ffff && \ |
| 82 (uint32)(c)<=0x10ffff && \ | 81 !CBU_IS_UNICODE_NONCHAR(c))) |
| 83 !CBU_IS_UNICODE_NONCHAR(c))) | |
| 84 | 82 |
| 85 /** | 83 /** |
| 86 * Is this code point a surrogate (U+d800..U+dfff)? | 84 * Is this code point a surrogate (U+d800..U+dfff)? |
| 87 * @param c 32-bit code point | 85 * @param c 32-bit code point |
| 88 * @return TRUE or FALSE | 86 * @return TRUE or FALSE |
| 89 * @stable ICU 2.4 | 87 * @stable ICU 2.4 |
| 90 */ | 88 */ |
| 91 #define CBU_IS_SURROGATE(c) (((c)&0xfffff800)==0xd800) | 89 #define CBU_IS_SURROGATE(c) (((c)&0xfffff800)==0xd800) |
| 92 | 90 |
| 93 /** | 91 /** |
| 94 * Assuming c is a surrogate code point (U_IS_SURROGATE(c)), | 92 * Assuming c is a surrogate code point (U_IS_SURROGATE(c)), |
| 95 * is it a lead surrogate? | 93 * is it a lead surrogate? |
| 96 * @param c 32-bit code point | 94 * @param c 32-bit code point |
| 97 * @return TRUE or FALSE | 95 * @return TRUE or FALSE |
| 98 * @stable ICU 2.4 | 96 * @stable ICU 2.4 |
| 99 */ | 97 */ |
| 100 #define CBU_IS_SURROGATE_LEAD(c) (((c)&0x400)==0) | 98 #define CBU_IS_SURROGATE_LEAD(c) (((c)&0x400)==0) |
| 101 | 99 |
| 102 | 100 |
| 103 // UTF-8 macros ---------------------------------------------------------------- | 101 // UTF-8 macros ---------------------------------------------------------------- |
| 104 // from utf8.h | 102 // from utf8.h |
| 105 | 103 |
| 106 extern const uint8 utf8_countTrailBytes[256]; | 104 extern const uint8_t utf8_countTrailBytes[256]; |
| 107 | 105 |
| 108 /** | 106 /** |
| 109 * Count the trail bytes for a UTF-8 lead byte. | 107 * Count the trail bytes for a UTF-8 lead byte. |
| 110 * @internal | 108 * @internal |
| 111 */ | 109 */ |
| 112 #define CBU8_COUNT_TRAIL_BYTES(leadByte) (base_icu::utf8_countTrailBytes[(uint8)
leadByte]) | 110 #define CBU8_COUNT_TRAIL_BYTES(leadByte) \ |
| 111 (base_icu::utf8_countTrailBytes[(uint8_t)leadByte]) |
| 113 | 112 |
| 114 /** | 113 /** |
| 115 * Mask a UTF-8 lead byte, leave only the lower bits that form part of the code
point value. | 114 * Mask a UTF-8 lead byte, leave only the lower bits that form part of the code
point value. |
| 116 * @internal | 115 * @internal |
| 117 */ | 116 */ |
| 118 #define CBU8_MASK_LEAD_BYTE(leadByte, countTrailBytes) ((leadByte)&=(1<<(6-(coun
tTrailBytes)))-1) | 117 #define CBU8_MASK_LEAD_BYTE(leadByte, countTrailBytes) ((leadByte)&=(1<<(6-(coun
tTrailBytes)))-1) |
| 119 | 118 |
| 120 /** | 119 /** |
| 121 * Does this code unit (byte) encode a code point by itself (US-ASCII 0..0x7f)? | 120 * Does this code unit (byte) encode a code point by itself (US-ASCII 0..0x7f)? |
| 122 * @param c 8-bit code unit (byte) | 121 * @param c 8-bit code unit (byte) |
| 123 * @return TRUE or FALSE | 122 * @return TRUE or FALSE |
| 124 * @stable ICU 2.4 | 123 * @stable ICU 2.4 |
| 125 */ | 124 */ |
| 126 #define CBU8_IS_SINGLE(c) (((c)&0x80)==0) | 125 #define CBU8_IS_SINGLE(c) (((c)&0x80)==0) |
| 127 | 126 |
| 128 /** | 127 /** |
| 129 * Is this code unit (byte) a UTF-8 lead byte? | 128 * Is this code unit (byte) a UTF-8 lead byte? |
| 130 * @param c 8-bit code unit (byte) | 129 * @param c 8-bit code unit (byte) |
| 131 * @return TRUE or FALSE | 130 * @return TRUE or FALSE |
| 132 * @stable ICU 2.4 | 131 * @stable ICU 2.4 |
| 133 */ | 132 */ |
| 134 #define CBU8_IS_LEAD(c) ((uint8)((c)-0xc0)<0x3e) | 133 #define CBU8_IS_LEAD(c) ((uint8_t)((c)-0xc0) < 0x3e) |
| 135 | 134 |
| 136 /** | 135 /** |
| 137 * Is this code unit (byte) a UTF-8 trail byte? | 136 * Is this code unit (byte) a UTF-8 trail byte? |
| 138 * @param c 8-bit code unit (byte) | 137 * @param c 8-bit code unit (byte) |
| 139 * @return TRUE or FALSE | 138 * @return TRUE or FALSE |
| 140 * @stable ICU 2.4 | 139 * @stable ICU 2.4 |
| 141 */ | 140 */ |
| 142 #define CBU8_IS_TRAIL(c) (((c)&0xc0)==0x80) | 141 #define CBU8_IS_TRAIL(c) (((c)&0xc0)==0x80) |
| 143 | 142 |
| 144 /** | 143 /** |
| 145 * How many code units (bytes) are used for the UTF-8 encoding | 144 * How many code units (bytes) are used for the UTF-8 encoding |
| 146 * of this Unicode code point? | 145 * of this Unicode code point? |
| 147 * @param c 32-bit code point | 146 * @param c 32-bit code point |
| 148 * @return 1..4, or 0 if c is a surrogate or not a Unicode code point | 147 * @return 1..4, or 0 if c is a surrogate or not a Unicode code point |
| 149 * @stable ICU 2.4 | 148 * @stable ICU 2.4 |
| 150 */ | 149 */ |
| 151 #define CBU8_LENGTH(c) \ | 150 #define CBU8_LENGTH(c) \ |
| 152 ((uint32)(c)<=0x7f ? 1 : \ | 151 ((uint32_t)(c) <= 0x7f \ |
| 153 ((uint32)(c)<=0x7ff ? 2 : \ | 152 ? 1 \ |
| 154 ((uint32)(c)<=0xd7ff ? 3 : \ | 153 : ((uint32_t)(c) <= 0x7ff \ |
| 155 ((uint32)(c)<=0xdfff || (uint32)(c)>0x10ffff ? 0 : \ | 154 ? 2 \ |
| 156 ((uint32)(c)<=0xffff ? 3 : 4)\ | 155 : ((uint32_t)(c) <= 0xd7ff \ |
| 157 ) \ | 156 ? 3 \ |
| 158 ) \ | 157 : ((uint32_t)(c) <= 0xdfff || (uint32_t)(c) > 0x10ffff \ |
| 159 ) \ | 158 ? 0 \ |
| 160 ) | 159 : ((uint32_t)(c) <= 0xffff ? 3 : 4))))) |
| 161 | 160 |
| 162 /** | 161 /** |
| 163 * The maximum number of UTF-8 code units (bytes) per Unicode code point (U+0000
..U+10ffff). | 162 * The maximum number of UTF-8 code units (bytes) per Unicode code point (U+0000
..U+10ffff). |
| 164 * @return 4 | 163 * @return 4 |
| 165 * @stable ICU 2.4 | 164 * @stable ICU 2.4 |
| 166 */ | 165 */ |
| 167 #define CBU8_MAX_LENGTH 4 | 166 #define CBU8_MAX_LENGTH 4 |
| 168 | 167 |
| 169 /** | 168 /** |
| 170 * Function for handling "next code point" with error-checking. | 169 * Function for handling "next code point" with error-checking. |
| 171 * @internal | 170 * @internal |
| 172 */ | 171 */ |
| 173 UChar32 utf8_nextCharSafeBody(const uint8 *s, int32 *pi, int32 length, UChar32 c
, UBool strict); | 172 UChar32 utf8_nextCharSafeBody(const uint8_t* s, |
| 173 int32_t* pi, |
| 174 int32_t length, |
| 175 UChar32 c, |
| 176 UBool strict); |
| 174 | 177 |
| 175 /** | 178 /** |
| 176 * Get a code point from a string at a code point boundary offset, | 179 * Get a code point from a string at a code point boundary offset, |
| 177 * and advance the offset to the next code point boundary. | 180 * and advance the offset to the next code point boundary. |
| 178 * (Post-incrementing forward iteration.) | 181 * (Post-incrementing forward iteration.) |
| 179 * "Safe" macro, checks for illegal sequences and for string boundaries. | 182 * "Safe" macro, checks for illegal sequences and for string boundaries. |
| 180 * | 183 * |
| 181 * The offset may point to the lead byte of a multi-byte sequence, | 184 * The offset may point to the lead byte of a multi-byte sequence, |
| 182 * in which case the macro will read the whole sequence. | 185 * in which case the macro will read the whole sequence. |
| 183 * If the offset points to a trail byte or an illegal UTF-8 sequence, then | 186 * If the offset points to a trail byte or an illegal UTF-8 sequence, then |
| 184 * c is set to a negative value. | 187 * c is set to a negative value. |
| 185 * | 188 * |
| 186 * @param s const uint8 * string | 189 * @param s const uint8_t * string |
| 187 * @param i string offset, i<length | 190 * @param i string offset, i<length |
| 188 * @param length string length | 191 * @param length string length |
| 189 * @param c output UChar32 variable, set to <0 in case of an error | 192 * @param c output UChar32 variable, set to <0 in case of an error |
| 190 * @see CBU8_NEXT_UNSAFE | 193 * @see CBU8_NEXT_UNSAFE |
| 191 * @stable ICU 2.4 | 194 * @stable ICU 2.4 |
| 192 */ | 195 */ |
| 193 #define CBU8_NEXT(s, i, length, c) { \ | 196 #define CBU8_NEXT(s, i, length, c) \ |
| 194 (c)=(s)[(i)++]; \ | 197 { \ |
| 195 if(((uint8)(c))>=0x80) { \ | 198 (c) = (s)[(i)++]; \ |
| 196 if(CBU8_IS_LEAD(c)) { \ | 199 if (((uint8_t)(c)) >= 0x80) { \ |
| 197 (c)=base_icu::utf8_nextCharSafeBody((const uint8 *)s, &(i), (int32)(
length), c, -1); \ | 200 if (CBU8_IS_LEAD(c)) { \ |
| 198 } else { \ | 201 (c) = base_icu::utf8_nextCharSafeBody((const uint8_t*)s, &(i), \ |
| 199 (c)=CBU_SENTINEL; \ | 202 (int32_t)(length), c, -1); \ |
| 200 } \ | 203 } else { \ |
| 201 } \ | 204 (c) = CBU_SENTINEL; \ |
| 202 } | 205 } \ |
| 206 } \ |
| 207 } |
| 203 | 208 |
| 204 /** | 209 /** |
| 205 * Append a code point to a string, overwriting 1 to 4 bytes. | 210 * Append a code point to a string, overwriting 1 to 4 bytes. |
| 206 * The offset points to the current end of the string contents | 211 * The offset points to the current end of the string contents |
| 207 * and is advanced (post-increment). | 212 * and is advanced (post-increment). |
| 208 * "Unsafe" macro, assumes a valid code point and sufficient space in the string
. | 213 * "Unsafe" macro, assumes a valid code point and sufficient space in the |
| 214 * string. |
| 209 * Otherwise, the result is undefined. | 215 * Otherwise, the result is undefined. |
| 210 * | 216 * |
| 211 * @param s const uint8 * string buffer | 217 * @param s const uint8_t * string buffer |
| 212 * @param i string offset | 218 * @param i string offset |
| 213 * @param c code point to append | 219 * @param c code point to append |
| 214 * @see CBU8_APPEND | 220 * @see CBU8_APPEND |
| 215 * @stable ICU 2.4 | 221 * @stable ICU 2.4 |
| 216 */ | 222 */ |
| 217 #define CBU8_APPEND_UNSAFE(s, i, c) { \ | 223 #define CBU8_APPEND_UNSAFE(s, i, c) \ |
| 218 if((uint32)(c)<=0x7f) { \ | 224 { \ |
| 219 (s)[(i)++]=(uint8)(c); \ | 225 if ((uint32_t)(c) <= 0x7f) { \ |
| 220 } else { \ | 226 (s)[(i)++] = (uint8_t)(c); \ |
| 221 if((uint32)(c)<=0x7ff) { \ | 227 } else { \ |
| 222 (s)[(i)++]=(uint8)(((c)>>6)|0xc0); \ | 228 if ((uint32_t)(c) <= 0x7ff) { \ |
| 223 } else { \ | 229 (s)[(i)++] = (uint8_t)(((c) >> 6) | 0xc0); \ |
| 224 if((uint32)(c)<=0xffff) { \ | 230 } else { \ |
| 225 (s)[(i)++]=(uint8)(((c)>>12)|0xe0); \ | 231 if ((uint32_t)(c) <= 0xffff) { \ |
| 226 } else { \ | 232 (s)[(i)++] = (uint8_t)(((c) >> 12) | 0xe0); \ |
| 227 (s)[(i)++]=(uint8)(((c)>>18)|0xf0); \ | 233 } else { \ |
| 228 (s)[(i)++]=(uint8)((((c)>>12)&0x3f)|0x80); \ | 234 (s)[(i)++] = (uint8_t)(((c) >> 18) | 0xf0); \ |
| 229 } \ | 235 (s)[(i)++] = (uint8_t)((((c) >> 12) & 0x3f) | 0x80); \ |
| 230 (s)[(i)++]=(uint8)((((c)>>6)&0x3f)|0x80); \ | 236 } \ |
| 231 } \ | 237 (s)[(i)++] = (uint8_t)((((c) >> 6) & 0x3f) | 0x80); \ |
| 232 (s)[(i)++]=(uint8)(((c)&0x3f)|0x80); \ | 238 } \ |
| 233 } \ | 239 (s)[(i)++] = (uint8_t)(((c)&0x3f) | 0x80); \ |
| 234 } | 240 } \ |
| 241 } |
| 235 | 242 |
| 236 // UTF-16 macros --------------------------------------------------------------- | 243 // UTF-16 macros --------------------------------------------------------------- |
| 237 // from utf16.h | 244 // from utf16.h |
| 238 | 245 |
| 239 /** | 246 /** |
| 240 * Does this code unit alone encode a code point (BMP, not a surrogate)? | 247 * Does this code unit alone encode a code point (BMP, not a surrogate)? |
| 241 * @param c 16-bit code unit | 248 * @param c 16-bit code unit |
| 242 * @return TRUE or FALSE | 249 * @return TRUE or FALSE |
| 243 * @stable ICU 2.4 | 250 * @stable ICU 2.4 |
| 244 */ | 251 */ |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 #define CBU16_TRAIL(supplementary) \ | 325 #define CBU16_TRAIL(supplementary) \ |
| 319 (base_icu::UChar)(((supplementary)&0x3ff)|0xdc00) | 326 (base_icu::UChar)(((supplementary)&0x3ff)|0xdc00) |
| 320 | 327 |
| 321 /** | 328 /** |
| 322 * How many 16-bit code units are used to encode this Unicode code point? (1 or
2) | 329 * How many 16-bit code units are used to encode this Unicode code point? (1 or
2) |
| 323 * The result is not defined if c is not a Unicode code point (U+0000..U+10ffff)
. | 330 * The result is not defined if c is not a Unicode code point (U+0000..U+10ffff)
. |
| 324 * @param c 32-bit code point | 331 * @param c 32-bit code point |
| 325 * @return 1 or 2 | 332 * @return 1 or 2 |
| 326 * @stable ICU 2.4 | 333 * @stable ICU 2.4 |
| 327 */ | 334 */ |
| 328 #define CBU16_LENGTH(c) ((uint32)(c)<=0xffff ? 1 : 2) | 335 #define CBU16_LENGTH(c) ((uint32_t)(c) <= 0xffff ? 1 : 2) |
| 329 | 336 |
| 330 /** | 337 /** |
| 331 * The maximum number of 16-bit code units per Unicode code point (U+0000..U+10f
fff). | 338 * The maximum number of 16-bit code units per Unicode code point (U+0000..U+10f
fff). |
| 332 * @return 2 | 339 * @return 2 |
| 333 * @stable ICU 2.4 | 340 * @stable ICU 2.4 |
| 334 */ | 341 */ |
| 335 #define CBU16_MAX_LENGTH 2 | 342 #define CBU16_MAX_LENGTH 2 |
| 336 | 343 |
| 337 /** | 344 /** |
| 338 * Get a code point from a string at a code point boundary offset, | 345 * Get a code point from a string at a code point boundary offset, |
| 339 * and advance the offset to the next code point boundary. | 346 * and advance the offset to the next code point boundary. |
| 340 * (Post-incrementing forward iteration.) | 347 * (Post-incrementing forward iteration.) |
| 341 * "Safe" macro, handles unpaired surrogates and checks for string boundaries. | 348 * "Safe" macro, handles unpaired surrogates and checks for string boundaries. |
| 342 * | 349 * |
| 343 * The offset may point to the lead surrogate unit | 350 * The offset may point to the lead surrogate unit |
| 344 * for a supplementary code point, in which case the macro will read | 351 * for a supplementary code point, in which case the macro will read |
| 345 * the following trail surrogate as well. | 352 * the following trail surrogate as well. |
| 346 * If the offset points to a trail surrogate or | 353 * If the offset points to a trail surrogate or |
| 347 * to a single, unpaired lead surrogate, then that itself | 354 * to a single, unpaired lead surrogate, then that itself |
| 348 * will be returned as the code point. | 355 * will be returned as the code point. |
| 349 * | 356 * |
| 350 * @param s const UChar * string | 357 * @param s const UChar * string |
| 351 * @param i string offset, i<length | 358 * @param i string offset, i<length |
| 352 * @param length string length | 359 * @param length string length |
| 353 * @param c output UChar32 variable | 360 * @param c output UChar32 variable |
| 354 * @stable ICU 2.4 | 361 * @stable ICU 2.4 |
| 355 */ | 362 */ |
| 356 #define CBU16_NEXT(s, i, length, c) { \ | 363 #define CBU16_NEXT(s, i, length, c) \ |
| 357 (c)=(s)[(i)++]; \ | 364 { \ |
| 358 if(CBU16_IS_LEAD(c)) { \ | 365 (c) = (s)[(i)++]; \ |
| 359 uint16 __c2; \ | 366 if (CBU16_IS_LEAD(c)) { \ |
| 360 if((i)<(length) && CBU16_IS_TRAIL(__c2=(s)[(i)])) { \ | 367 uint16_t __c2; \ |
| 361 ++(i); \ | 368 if ((i) < (length) && CBU16_IS_TRAIL(__c2 = (s)[(i)])) { \ |
| 362 (c)=CBU16_GET_SUPPLEMENTARY((c), __c2); \ | 369 ++(i); \ |
| 363 } \ | 370 (c) = CBU16_GET_SUPPLEMENTARY((c), __c2); \ |
| 364 } \ | 371 } \ |
| 365 } | 372 } \ |
| 373 } |
| 366 | 374 |
| 367 /** | 375 /** |
| 368 * Append a code point to a string, overwriting 1 or 2 code units. | 376 * Append a code point to a string, overwriting 1 or 2 code units. |
| 369 * The offset points to the current end of the string contents | 377 * The offset points to the current end of the string contents |
| 370 * and is advanced (post-increment). | 378 * and is advanced (post-increment). |
| 371 * "Unsafe" macro, assumes a valid code point and sufficient space in the string
. | 379 * "Unsafe" macro, assumes a valid code point and sufficient space in the string
. |
| 372 * Otherwise, the result is undefined. | 380 * Otherwise, the result is undefined. |
| 373 * | 381 * |
| 374 * @param s const UChar * string buffer | 382 * @param s const UChar * string buffer |
| 375 * @param i string offset | 383 * @param i string offset |
| 376 * @param c code point to append | 384 * @param c code point to append |
| 377 * @see CBU16_APPEND | 385 * @see CBU16_APPEND |
| 378 * @stable ICU 2.4 | 386 * @stable ICU 2.4 |
| 379 */ | 387 */ |
| 380 #define CBU16_APPEND_UNSAFE(s, i, c) { \ | 388 #define CBU16_APPEND_UNSAFE(s, i, c) \ |
| 381 if((uint32)(c)<=0xffff) { \ | 389 { \ |
| 382 (s)[(i)++]=(uint16)(c); \ | 390 if ((uint32_t)(c) <= 0xffff) { \ |
| 383 } else { \ | 391 (s)[(i)++] = (uint16_t)(c); \ |
| 384 (s)[(i)++]=(uint16)(((c)>>10)+0xd7c0); \ | 392 } else { \ |
| 385 (s)[(i)++]=(uint16)(((c)&0x3ff)|0xdc00); \ | 393 (s)[(i)++] = (uint16_t)(((c) >> 10) + 0xd7c0); \ |
| 386 } \ | 394 (s)[(i)++] = (uint16_t)(((c)&0x3ff) | 0xdc00); \ |
| 387 } | 395 } \ |
| 396 } |
| 388 | 397 |
| 389 } // namesapce base_icu | 398 } // namesapce base_icu |
| 390 | 399 |
| 391 #endif // BASE_THIRD_PARTY_ICU_ICU_UTF_H_ | 400 #endif // BASE_THIRD_PARTY_ICU_ICU_UTF_H_ |
| OLD | NEW |