Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* |
michael@0 | 2 | ******************************************************************************* |
michael@0 | 3 | * |
michael@0 | 4 | * Copyright (C) 2002-2012, International Business Machines |
michael@0 | 5 | * Corporation and others. All Rights Reserved. |
michael@0 | 6 | * |
michael@0 | 7 | ******************************************************************************* |
michael@0 | 8 | * file name: utf_old.h |
michael@0 | 9 | * encoding: US-ASCII |
michael@0 | 10 | * tab size: 8 (not used) |
michael@0 | 11 | * indentation:4 |
michael@0 | 12 | * |
michael@0 | 13 | * created on: 2002sep21 |
michael@0 | 14 | * created by: Markus W. Scherer |
michael@0 | 15 | */ |
michael@0 | 16 | |
michael@0 | 17 | /** |
michael@0 | 18 | * \file |
michael@0 | 19 | * \brief C API: Deprecated macros for Unicode string handling |
michael@0 | 20 | */ |
michael@0 | 21 | |
michael@0 | 22 | /** |
michael@0 | 23 | * |
michael@0 | 24 | * The macros in utf_old.h are all deprecated and their use discouraged. |
michael@0 | 25 | * Some of the design principles behind the set of UTF macros |
michael@0 | 26 | * have changed or proved impractical. |
michael@0 | 27 | * Almost all of the old "UTF macros" are at least renamed. |
michael@0 | 28 | * If you are looking for a new equivalent to an old macro, please see the |
michael@0 | 29 | * comment at the old one. |
michael@0 | 30 | * |
michael@0 | 31 | * Brief summary of reasons for deprecation: |
michael@0 | 32 | * - Switch on UTF_SIZE (selection of UTF-8/16/32 default string processing) |
michael@0 | 33 | * was impractical. |
michael@0 | 34 | * - Switch on UTF_SAFE etc. (selection of unsafe/safe/strict default string processing) |
michael@0 | 35 | * was of little use and impractical. |
michael@0 | 36 | * - Whole classes of macros became obsolete outside of the UTF_SIZE/UTF_SAFE |
michael@0 | 37 | * selection framework: UTF32_ macros (all trivial) |
michael@0 | 38 | * and UTF_ default and intermediate macros (all aliases). |
michael@0 | 39 | * - The selection framework also caused many macro aliases. |
michael@0 | 40 | * - Change in Unicode standard: "irregular" sequences (3.0) became illegal (3.2). |
michael@0 | 41 | * - Change of language in Unicode standard: |
michael@0 | 42 | * Growing distinction between internal x-bit Unicode strings and external UTF-x |
michael@0 | 43 | * forms, with the former more lenient. |
michael@0 | 44 | * Suggests renaming of UTF16_ macros to U16_. |
michael@0 | 45 | * - The prefix "UTF_" without a width number confused some users. |
michael@0 | 46 | * - "Safe" append macros needed the addition of an error indicator output. |
michael@0 | 47 | * - "Safe" UTF-8 macros used legitimate (if rarely used) code point values |
michael@0 | 48 | * to indicate error conditions. |
michael@0 | 49 | * - The use of the "_CHAR" infix for code point operations confused some users. |
michael@0 | 50 | * |
michael@0 | 51 | * More details: |
michael@0 | 52 | * |
michael@0 | 53 | * Until ICU 2.2, utf.h theoretically allowed to choose among UTF-8/16/32 |
michael@0 | 54 | * for string processing, and among unsafe/safe/strict default macros for that. |
michael@0 | 55 | * |
michael@0 | 56 | * It proved nearly impossible to write non-trivial, high-performance code |
michael@0 | 57 | * that is UTF-generic. |
michael@0 | 58 | * Unsafe default macros would be dangerous for default string processing, |
michael@0 | 59 | * and the main reason for the "strict" versions disappeared: |
michael@0 | 60 | * Between Unicode 3.0 and 3.2 all "irregular" UTF-8 sequences became illegal. |
michael@0 | 61 | * The only other conditions that "strict" checked for were non-characters, |
michael@0 | 62 | * which are valid during processing. Only during text input/output should they |
michael@0 | 63 | * be checked, and at that time other well-formedness checks may be |
michael@0 | 64 | * necessary or useful as well. |
michael@0 | 65 | * This can still be done by using U16_NEXT and U_IS_UNICODE_NONCHAR |
michael@0 | 66 | * or U_IS_UNICODE_CHAR. |
michael@0 | 67 | * |
michael@0 | 68 | * The old UTF8_..._SAFE macros also used some normal Unicode code points |
michael@0 | 69 | * to indicate malformed sequences. |
michael@0 | 70 | * The new UTF8_ macros without suffix use negative values instead. |
michael@0 | 71 | * |
michael@0 | 72 | * The entire contents of utf32.h was moved here without replacement |
michael@0 | 73 | * because all those macros were trivial and |
michael@0 | 74 | * were meaningful only in the framework of choosing the UTF size. |
michael@0 | 75 | * |
michael@0 | 76 | * See Jitterbug 2150 and its discussion on the ICU mailing list |
michael@0 | 77 | * in September 2002. |
michael@0 | 78 | * |
michael@0 | 79 | * <hr> |
michael@0 | 80 | * |
michael@0 | 81 | * <em>Obsolete part</em> of pre-ICU 2.4 utf.h file documentation: |
michael@0 | 82 | * |
michael@0 | 83 | * <p>The original concept for these files was for ICU to allow |
michael@0 | 84 | * in principle to set which UTF (UTF-8/16/32) is used internally |
michael@0 | 85 | * by defining UTF_SIZE to either 8, 16, or 32. utf.h would then define the UChar type |
michael@0 | 86 | * accordingly. UTF-16 was the default.</p> |
michael@0 | 87 | * |
michael@0 | 88 | * <p>This concept has been abandoned. |
michael@0 | 89 | * A lot of the ICU source code assumes UChar strings are in UTF-16. |
michael@0 | 90 | * This is especially true for low-level code like |
michael@0 | 91 | * conversion, normalization, and collation. |
michael@0 | 92 | * The utf.h header enforces the default of UTF-16. |
michael@0 | 93 | * The UTF-8 and UTF-32 macros remain for now for completeness and backward compatibility.</p> |
michael@0 | 94 | * |
michael@0 | 95 | * <p>Accordingly, utf.h defines UChar to be an unsigned 16-bit integer. If this matches wchar_t, then |
michael@0 | 96 | * UChar is defined to be exactly wchar_t, otherwise uint16_t.</p> |
michael@0 | 97 | * |
michael@0 | 98 | * <p>UChar32 is defined to be a signed 32-bit integer (int32_t), large enough for a 21-bit |
michael@0 | 99 | * Unicode code point (Unicode scalar value, 0..0x10ffff). |
michael@0 | 100 | * Before ICU 2.4, the definition of UChar32 was similarly platform-dependent as |
michael@0 | 101 | * the definition of UChar. For details see the documentation for UChar32 itself.</p> |
michael@0 | 102 | * |
michael@0 | 103 | * <p>utf.h also defines a number of C macros for handling single Unicode code points and |
michael@0 | 104 | * for using UTF Unicode strings. It includes utf8.h, utf16.h, and utf32.h for the actual |
michael@0 | 105 | * implementations of those macros and then aliases one set of them (for UTF-16) for general use. |
michael@0 | 106 | * The UTF-specific macros have the UTF size in the macro name prefixes (UTF16_...), while |
michael@0 | 107 | * the general alias macros always begin with UTF_...</p> |
michael@0 | 108 | * |
michael@0 | 109 | * <p>Many string operations can be done with or without error checking. |
michael@0 | 110 | * Where such a distinction is useful, there are two versions of the macros, "unsafe" and "safe" |
michael@0 | 111 | * ones with ..._UNSAFE and ..._SAFE suffixes. The unsafe macros are fast but may cause |
michael@0 | 112 | * program failures if the strings are not well-formed. The safe macros have an additional, boolean |
michael@0 | 113 | * parameter "strict". If strict is FALSE, then only illegal sequences are detected. |
michael@0 | 114 | * Otherwise, irregular sequences and non-characters are detected as well (like single surrogates). |
michael@0 | 115 | * Safe macros return special error code points for illegal/irregular sequences: |
michael@0 | 116 | * Typically, U+ffff, or values that would result in a code unit sequence of the same length |
michael@0 | 117 | * as the erroneous input sequence.<br> |
michael@0 | 118 | * Note that _UNSAFE macros have fewer parameters: They do not have the strictness parameter, and |
michael@0 | 119 | * they do not have start/length parameters for boundary checking.</p> |
michael@0 | 120 | * |
michael@0 | 121 | * <p>Here, the macros are aliased in two steps: |
michael@0 | 122 | * In the first step, the UTF-specific macros with UTF16_ prefix and _UNSAFE and _SAFE suffixes are |
michael@0 | 123 | * aliased according to the UTF_SIZE to macros with UTF_ prefix and the same suffixes and signatures. |
michael@0 | 124 | * Then, in a second step, the default, general alias macros are set to use either the unsafe or |
michael@0 | 125 | * the safe/not strict (default) or the safe/strict macro; |
michael@0 | 126 | * these general macros do not have a strictness parameter.</p> |
michael@0 | 127 | * |
michael@0 | 128 | * <p>It is possible to change the default choice for the general alias macros to be unsafe, safe/not strict or safe/strict. |
michael@0 | 129 | * The default is safe/not strict. It is not recommended to select the unsafe macros as the basis for |
michael@0 | 130 | * Unicode string handling in ICU! To select this, define UTF_SAFE, UTF_STRICT, or UTF_UNSAFE.</p> |
michael@0 | 131 | * |
michael@0 | 132 | * <p>For general use, one should use the default, general macros with UTF_ prefix and no _SAFE/_UNSAFE suffix. |
michael@0 | 133 | * Only in some cases it may be necessary to control the choice of macro directly and use a less generic alias. |
michael@0 | 134 | * For example, if it can be assumed that a string is well-formed and the index will stay within the bounds, |
michael@0 | 135 | * then the _UNSAFE version may be used. |
michael@0 | 136 | * If a UTF-8 string is to be processed, then the macros with UTF8_ prefixes need to be used.</p> |
michael@0 | 137 | * |
michael@0 | 138 | * <hr> |
michael@0 | 139 | * |
michael@0 | 140 | * @deprecated ICU 2.4. Use the macros in utf.h, utf16.h, utf8.h instead. |
michael@0 | 141 | */ |
michael@0 | 142 | |
michael@0 | 143 | #ifndef __UTF_OLD_H__ |
michael@0 | 144 | #define __UTF_OLD_H__ |
michael@0 | 145 | |
michael@0 | 146 | #ifndef U_HIDE_DEPRECATED_API |
michael@0 | 147 | |
michael@0 | 148 | #include "unicode/utf.h" |
michael@0 | 149 | #include "unicode/utf8.h" |
michael@0 | 150 | #include "unicode/utf16.h" |
michael@0 | 151 | |
michael@0 | 152 | /* Formerly utf.h, part 1 --------------------------------------------------- */ |
michael@0 | 153 | |
michael@0 | 154 | #ifdef U_USE_UTF_DEPRECATES |
michael@0 | 155 | /** |
michael@0 | 156 | * Unicode string and array offset and index type. |
michael@0 | 157 | * ICU always counts Unicode code units (UChars) for |
michael@0 | 158 | * string offsets, indexes, and lengths, not Unicode code points. |
michael@0 | 159 | * |
michael@0 | 160 | * @obsolete ICU 2.6. Use int32_t directly instead since this API will be removed in that release. |
michael@0 | 161 | */ |
michael@0 | 162 | typedef int32_t UTextOffset; |
michael@0 | 163 | #endif |
michael@0 | 164 | |
michael@0 | 165 | /** Number of bits in a Unicode string code unit - ICU uses 16-bit Unicode. @deprecated ICU 2.4. Obsolete, see utf_old.h. */ |
michael@0 | 166 | #define UTF_SIZE 16 |
michael@0 | 167 | |
michael@0 | 168 | /** |
michael@0 | 169 | * The default choice for general Unicode string macros is to use the ..._SAFE macro implementations |
michael@0 | 170 | * with strict=FALSE. |
michael@0 | 171 | * |
michael@0 | 172 | * @deprecated ICU 2.4. Obsolete, see utf_old.h. |
michael@0 | 173 | */ |
michael@0 | 174 | #define UTF_SAFE |
michael@0 | 175 | /** @deprecated ICU 2.4. Obsolete, see utf_old.h. */ |
michael@0 | 176 | #undef UTF_UNSAFE |
michael@0 | 177 | /** @deprecated ICU 2.4. Obsolete, see utf_old.h. */ |
michael@0 | 178 | #undef UTF_STRICT |
michael@0 | 179 | |
michael@0 | 180 | /** |
michael@0 | 181 | * UTF8_ERROR_VALUE_1 and UTF8_ERROR_VALUE_2 are special error values for UTF-8, |
michael@0 | 182 | * which need 1 or 2 bytes in UTF-8: |
michael@0 | 183 | * \code |
michael@0 | 184 | * U+0015 = NAK = Negative Acknowledge, C0 control character |
michael@0 | 185 | * U+009f = highest C1 control character |
michael@0 | 186 | * \endcode |
michael@0 | 187 | * |
michael@0 | 188 | * These are used by UTF8_..._SAFE macros so that they can return an error value |
michael@0 | 189 | * that needs the same number of code units (bytes) as were seen by |
michael@0 | 190 | * a macro. They should be tested with UTF_IS_ERROR() or UTF_IS_VALID(). |
michael@0 | 191 | * |
michael@0 | 192 | * @deprecated ICU 2.4. Obsolete, see utf_old.h. |
michael@0 | 193 | */ |
michael@0 | 194 | #define UTF8_ERROR_VALUE_1 0x15 |
michael@0 | 195 | |
michael@0 | 196 | /** |
michael@0 | 197 | * See documentation on UTF8_ERROR_VALUE_1 for details. |
michael@0 | 198 | * |
michael@0 | 199 | * @deprecated ICU 2.4. Obsolete, see utf_old.h. |
michael@0 | 200 | */ |
michael@0 | 201 | #define UTF8_ERROR_VALUE_2 0x9f |
michael@0 | 202 | |
michael@0 | 203 | /** |
michael@0 | 204 | * Error value for all UTFs. This code point value will be set by macros with error |
michael@0 | 205 | * checking if an error is detected. |
michael@0 | 206 | * |
michael@0 | 207 | * @deprecated ICU 2.4. Obsolete, see utf_old.h. |
michael@0 | 208 | */ |
michael@0 | 209 | #define UTF_ERROR_VALUE 0xffff |
michael@0 | 210 | |
michael@0 | 211 | /** |
michael@0 | 212 | * Is a given 32-bit code an error value |
michael@0 | 213 | * as returned by one of the macros for any UTF? |
michael@0 | 214 | * |
michael@0 | 215 | * @deprecated ICU 2.4. Obsolete, see utf_old.h. |
michael@0 | 216 | */ |
michael@0 | 217 | #define UTF_IS_ERROR(c) \ |
michael@0 | 218 | (((c)&0xfffe)==0xfffe || (c)==UTF8_ERROR_VALUE_1 || (c)==UTF8_ERROR_VALUE_2) |
michael@0 | 219 | |
michael@0 | 220 | /** |
michael@0 | 221 | * This is a combined macro: Is c a valid Unicode value _and_ not an error code? |
michael@0 | 222 | * |
michael@0 | 223 | * @deprecated ICU 2.4. Obsolete, see utf_old.h. |
michael@0 | 224 | */ |
michael@0 | 225 | #define UTF_IS_VALID(c) \ |
michael@0 | 226 | (UTF_IS_UNICODE_CHAR(c) && \ |
michael@0 | 227 | (c)!=UTF8_ERROR_VALUE_1 && (c)!=UTF8_ERROR_VALUE_2) |
michael@0 | 228 | |
michael@0 | 229 | /** |
michael@0 | 230 | * Is this code unit or code point a surrogate (U+d800..U+dfff)? |
michael@0 | 231 | * @deprecated ICU 2.4. Renamed to U_IS_SURROGATE and U16_IS_SURROGATE, see utf_old.h. |
michael@0 | 232 | */ |
michael@0 | 233 | #define UTF_IS_SURROGATE(uchar) (((uchar)&0xfffff800)==0xd800) |
michael@0 | 234 | |
michael@0 | 235 | /** |
michael@0 | 236 | * Is a given 32-bit code point a Unicode noncharacter? |
michael@0 | 237 | * |
michael@0 | 238 | * @deprecated ICU 2.4. Renamed to U_IS_UNICODE_NONCHAR, see utf_old.h. |
michael@0 | 239 | */ |
michael@0 | 240 | #define UTF_IS_UNICODE_NONCHAR(c) \ |
michael@0 | 241 | ((c)>=0xfdd0 && \ |
michael@0 | 242 | ((uint32_t)(c)<=0xfdef || ((c)&0xfffe)==0xfffe) && \ |
michael@0 | 243 | (uint32_t)(c)<=0x10ffff) |
michael@0 | 244 | |
michael@0 | 245 | /** |
michael@0 | 246 | * Is a given 32-bit value a Unicode code point value (0..U+10ffff) |
michael@0 | 247 | * that can be assigned a character? |
michael@0 | 248 | * |
michael@0 | 249 | * Code points that are not characters include: |
michael@0 | 250 | * - single surrogate code points (U+d800..U+dfff, 2048 code points) |
michael@0 | 251 | * - the last two code points on each plane (U+__fffe and U+__ffff, 34 code points) |
michael@0 | 252 | * - U+fdd0..U+fdef (new with Unicode 3.1, 32 code points) |
michael@0 | 253 | * - the highest Unicode code point value is U+10ffff |
michael@0 | 254 | * |
michael@0 | 255 | * This means that all code points below U+d800 are character code points, |
michael@0 | 256 | * and that boundary is tested first for performance. |
michael@0 | 257 | * |
michael@0 | 258 | * @deprecated ICU 2.4. Renamed to U_IS_UNICODE_CHAR, see utf_old.h. |
michael@0 | 259 | */ |
michael@0 | 260 | #define UTF_IS_UNICODE_CHAR(c) \ |
michael@0 | 261 | ((uint32_t)(c)<0xd800 || \ |
michael@0 | 262 | ((uint32_t)(c)>0xdfff && \ |
michael@0 | 263 | (uint32_t)(c)<=0x10ffff && \ |
michael@0 | 264 | !UTF_IS_UNICODE_NONCHAR(c))) |
michael@0 | 265 | |
michael@0 | 266 | /* Formerly utf8.h ---------------------------------------------------------- */ |
michael@0 | 267 | |
michael@0 | 268 | /** |
michael@0 | 269 | * Count the trail bytes for a UTF-8 lead byte. |
michael@0 | 270 | * @deprecated ICU 2.4. Renamed to U8_COUNT_TRAIL_BYTES, see utf_old.h. |
michael@0 | 271 | */ |
michael@0 | 272 | #define UTF8_COUNT_TRAIL_BYTES(leadByte) (utf8_countTrailBytes[(uint8_t)leadByte]) |
michael@0 | 273 | |
michael@0 | 274 | /** |
michael@0 | 275 | * Mask a UTF-8 lead byte, leave only the lower bits that form part of the code point value. |
michael@0 | 276 | * @deprecated ICU 2.4. Renamed to U8_MASK_LEAD_BYTE, see utf_old.h. |
michael@0 | 277 | */ |
michael@0 | 278 | #define UTF8_MASK_LEAD_BYTE(leadByte, countTrailBytes) ((leadByte)&=(1<<(6-(countTrailBytes)))-1) |
michael@0 | 279 | |
michael@0 | 280 | /** Is this this code point a single code unit (byte)? @deprecated ICU 2.4. Renamed to U8_IS_SINGLE, see utf_old.h. */ |
michael@0 | 281 | #define UTF8_IS_SINGLE(uchar) (((uchar)&0x80)==0) |
michael@0 | 282 | /** Is this this code unit the lead code unit (byte) of a code point? @deprecated ICU 2.4. Renamed to U8_IS_LEAD, see utf_old.h. */ |
michael@0 | 283 | #define UTF8_IS_LEAD(uchar) ((uint8_t)((uchar)-0xc0)<0x3e) |
michael@0 | 284 | /** Is this this code unit a trailing code unit (byte) of a code point? @deprecated ICU 2.4. Renamed to U8_IS_TRAIL, see utf_old.h. */ |
michael@0 | 285 | #define UTF8_IS_TRAIL(uchar) (((uchar)&0xc0)==0x80) |
michael@0 | 286 | |
michael@0 | 287 | /** Does this scalar Unicode value need multiple code units for storage? @deprecated ICU 2.4. Use U8_LENGTH or test ((uint32_t)(c)>0x7f) instead, see utf_old.h. */ |
michael@0 | 288 | #define UTF8_NEED_MULTIPLE_UCHAR(c) ((uint32_t)(c)>0x7f) |
michael@0 | 289 | |
michael@0 | 290 | /** |
michael@0 | 291 | * Given the lead character, how many bytes are taken by this code point. |
michael@0 | 292 | * ICU does not deal with code points >0x10ffff |
michael@0 | 293 | * unless necessary for advancing in the byte stream. |
michael@0 | 294 | * |
michael@0 | 295 | * These length macros take into account that for values >0x10ffff |
michael@0 | 296 | * the UTF8_APPEND_CHAR_SAFE macros would write the error code point 0xffff |
michael@0 | 297 | * with 3 bytes. |
michael@0 | 298 | * Code point comparisons need to be in uint32_t because UChar32 |
michael@0 | 299 | * may be a signed type, and negative values must be recognized. |
michael@0 | 300 | * |
michael@0 | 301 | * @deprecated ICU 2.4. Use U8_LENGTH instead, see utf.h. |
michael@0 | 302 | */ |
michael@0 | 303 | #if 1 |
michael@0 | 304 | # define UTF8_CHAR_LENGTH(c) \ |
michael@0 | 305 | ((uint32_t)(c)<=0x7f ? 1 : \ |
michael@0 | 306 | ((uint32_t)(c)<=0x7ff ? 2 : \ |
michael@0 | 307 | ((uint32_t)((c)-0x10000)>0xfffff ? 3 : 4) \ |
michael@0 | 308 | ) \ |
michael@0 | 309 | ) |
michael@0 | 310 | #else |
michael@0 | 311 | # define UTF8_CHAR_LENGTH(c) \ |
michael@0 | 312 | ((uint32_t)(c)<=0x7f ? 1 : \ |
michael@0 | 313 | ((uint32_t)(c)<=0x7ff ? 2 : \ |
michael@0 | 314 | ((uint32_t)(c)<=0xffff ? 3 : \ |
michael@0 | 315 | ((uint32_t)(c)<=0x10ffff ? 4 : \ |
michael@0 | 316 | ((uint32_t)(c)<=0x3ffffff ? 5 : \ |
michael@0 | 317 | ((uint32_t)(c)<=0x7fffffff ? 6 : 3) \ |
michael@0 | 318 | ) \ |
michael@0 | 319 | ) \ |
michael@0 | 320 | ) \ |
michael@0 | 321 | ) \ |
michael@0 | 322 | ) |
michael@0 | 323 | #endif |
michael@0 | 324 | |
michael@0 | 325 | /** The maximum number of bytes per code point. @deprecated ICU 2.4. Renamed to U8_MAX_LENGTH, see utf_old.h. */ |
michael@0 | 326 | #define UTF8_MAX_CHAR_LENGTH 4 |
michael@0 | 327 | |
michael@0 | 328 | /** Average number of code units compared to UTF-16. @deprecated ICU 2.4. Obsolete, see utf_old.h. */ |
michael@0 | 329 | #define UTF8_ARRAY_SIZE(size) ((5*(size))/2) |
michael@0 | 330 | |
michael@0 | 331 | /** @deprecated ICU 2.4. Renamed to U8_GET_UNSAFE, see utf_old.h. */ |
michael@0 | 332 | #define UTF8_GET_CHAR_UNSAFE(s, i, c) { \ |
michael@0 | 333 | int32_t _utf8_get_char_unsafe_index=(int32_t)(i); \ |
michael@0 | 334 | UTF8_SET_CHAR_START_UNSAFE(s, _utf8_get_char_unsafe_index); \ |
michael@0 | 335 | UTF8_NEXT_CHAR_UNSAFE(s, _utf8_get_char_unsafe_index, c); \ |
michael@0 | 336 | } |
michael@0 | 337 | |
michael@0 | 338 | /** @deprecated ICU 2.4. Use U8_GET instead, see utf_old.h. */ |
michael@0 | 339 | #define UTF8_GET_CHAR_SAFE(s, start, i, length, c, strict) { \ |
michael@0 | 340 | int32_t _utf8_get_char_safe_index=(int32_t)(i); \ |
michael@0 | 341 | UTF8_SET_CHAR_START_SAFE(s, start, _utf8_get_char_safe_index); \ |
michael@0 | 342 | UTF8_NEXT_CHAR_SAFE(s, _utf8_get_char_safe_index, length, c, strict); \ |
michael@0 | 343 | } |
michael@0 | 344 | |
michael@0 | 345 | /** @deprecated ICU 2.4. Renamed to U8_NEXT_UNSAFE, see utf_old.h. */ |
michael@0 | 346 | #define UTF8_NEXT_CHAR_UNSAFE(s, i, c) { \ |
michael@0 | 347 | (c)=(s)[(i)++]; \ |
michael@0 | 348 | if((uint8_t)((c)-0xc0)<0x35) { \ |
michael@0 | 349 | uint8_t __count=UTF8_COUNT_TRAIL_BYTES(c); \ |
michael@0 | 350 | UTF8_MASK_LEAD_BYTE(c, __count); \ |
michael@0 | 351 | switch(__count) { \ |
michael@0 | 352 | /* each following branch falls through to the next one */ \ |
michael@0 | 353 | case 3: \ |
michael@0 | 354 | (c)=((c)<<6)|((s)[(i)++]&0x3f); \ |
michael@0 | 355 | case 2: \ |
michael@0 | 356 | (c)=((c)<<6)|((s)[(i)++]&0x3f); \ |
michael@0 | 357 | case 1: \ |
michael@0 | 358 | (c)=((c)<<6)|((s)[(i)++]&0x3f); \ |
michael@0 | 359 | /* no other branches to optimize switch() */ \ |
michael@0 | 360 | break; \ |
michael@0 | 361 | } \ |
michael@0 | 362 | } \ |
michael@0 | 363 | } |
michael@0 | 364 | |
michael@0 | 365 | /** @deprecated ICU 2.4. Renamed to U8_APPEND_UNSAFE, see utf_old.h. */ |
michael@0 | 366 | #define UTF8_APPEND_CHAR_UNSAFE(s, i, c) { \ |
michael@0 | 367 | if((uint32_t)(c)<=0x7f) { \ |
michael@0 | 368 | (s)[(i)++]=(uint8_t)(c); \ |
michael@0 | 369 | } else { \ |
michael@0 | 370 | if((uint32_t)(c)<=0x7ff) { \ |
michael@0 | 371 | (s)[(i)++]=(uint8_t)(((c)>>6)|0xc0); \ |
michael@0 | 372 | } else { \ |
michael@0 | 373 | if((uint32_t)(c)<=0xffff) { \ |
michael@0 | 374 | (s)[(i)++]=(uint8_t)(((c)>>12)|0xe0); \ |
michael@0 | 375 | } else { \ |
michael@0 | 376 | (s)[(i)++]=(uint8_t)(((c)>>18)|0xf0); \ |
michael@0 | 377 | (s)[(i)++]=(uint8_t)((((c)>>12)&0x3f)|0x80); \ |
michael@0 | 378 | } \ |
michael@0 | 379 | (s)[(i)++]=(uint8_t)((((c)>>6)&0x3f)|0x80); \ |
michael@0 | 380 | } \ |
michael@0 | 381 | (s)[(i)++]=(uint8_t)(((c)&0x3f)|0x80); \ |
michael@0 | 382 | } \ |
michael@0 | 383 | } |
michael@0 | 384 | |
michael@0 | 385 | /** @deprecated ICU 2.4. Renamed to U8_FWD_1_UNSAFE, see utf_old.h. */ |
michael@0 | 386 | #define UTF8_FWD_1_UNSAFE(s, i) { \ |
michael@0 | 387 | (i)+=1+UTF8_COUNT_TRAIL_BYTES((s)[i]); \ |
michael@0 | 388 | } |
michael@0 | 389 | |
michael@0 | 390 | /** @deprecated ICU 2.4. Renamed to U8_FWD_N_UNSAFE, see utf_old.h. */ |
michael@0 | 391 | #define UTF8_FWD_N_UNSAFE(s, i, n) { \ |
michael@0 | 392 | int32_t __N=(n); \ |
michael@0 | 393 | while(__N>0) { \ |
michael@0 | 394 | UTF8_FWD_1_UNSAFE(s, i); \ |
michael@0 | 395 | --__N; \ |
michael@0 | 396 | } \ |
michael@0 | 397 | } |
michael@0 | 398 | |
michael@0 | 399 | /** @deprecated ICU 2.4. Renamed to U8_SET_CP_START_UNSAFE, see utf_old.h. */ |
michael@0 | 400 | #define UTF8_SET_CHAR_START_UNSAFE(s, i) { \ |
michael@0 | 401 | while(UTF8_IS_TRAIL((s)[i])) { --(i); } \ |
michael@0 | 402 | } |
michael@0 | 403 | |
michael@0 | 404 | /** @deprecated ICU 2.4. Use U8_NEXT instead, see utf_old.h. */ |
michael@0 | 405 | #define UTF8_NEXT_CHAR_SAFE(s, i, length, c, strict) { \ |
michael@0 | 406 | (c)=(s)[(i)++]; \ |
michael@0 | 407 | if((c)>=0x80) { \ |
michael@0 | 408 | if(UTF8_IS_LEAD(c)) { \ |
michael@0 | 409 | (c)=utf8_nextCharSafeBody(s, &(i), (int32_t)(length), c, strict); \ |
michael@0 | 410 | } else { \ |
michael@0 | 411 | (c)=UTF8_ERROR_VALUE_1; \ |
michael@0 | 412 | } \ |
michael@0 | 413 | } \ |
michael@0 | 414 | } |
michael@0 | 415 | |
michael@0 | 416 | /** @deprecated ICU 2.4. Use U8_APPEND instead, see utf_old.h. */ |
michael@0 | 417 | #define UTF8_APPEND_CHAR_SAFE(s, i, length, c) { \ |
michael@0 | 418 | if((uint32_t)(c)<=0x7f) { \ |
michael@0 | 419 | (s)[(i)++]=(uint8_t)(c); \ |
michael@0 | 420 | } else { \ |
michael@0 | 421 | (i)=utf8_appendCharSafeBody(s, (int32_t)(i), (int32_t)(length), c, NULL); \ |
michael@0 | 422 | } \ |
michael@0 | 423 | } |
michael@0 | 424 | |
michael@0 | 425 | /** @deprecated ICU 2.4. Renamed to U8_FWD_1, see utf_old.h. */ |
michael@0 | 426 | #define UTF8_FWD_1_SAFE(s, i, length) U8_FWD_1(s, i, length) |
michael@0 | 427 | |
michael@0 | 428 | /** @deprecated ICU 2.4. Renamed to U8_FWD_N, see utf_old.h. */ |
michael@0 | 429 | #define UTF8_FWD_N_SAFE(s, i, length, n) U8_FWD_N(s, i, length, n) |
michael@0 | 430 | |
michael@0 | 431 | /** @deprecated ICU 2.4. Renamed to U8_SET_CP_START, see utf_old.h. */ |
michael@0 | 432 | #define UTF8_SET_CHAR_START_SAFE(s, start, i) U8_SET_CP_START(s, start, i) |
michael@0 | 433 | |
michael@0 | 434 | /** @deprecated ICU 2.4. Renamed to U8_PREV_UNSAFE, see utf_old.h. */ |
michael@0 | 435 | #define UTF8_PREV_CHAR_UNSAFE(s, i, c) { \ |
michael@0 | 436 | (c)=(s)[--(i)]; \ |
michael@0 | 437 | if(UTF8_IS_TRAIL(c)) { \ |
michael@0 | 438 | uint8_t __b, __count=1, __shift=6; \ |
michael@0 | 439 | \ |
michael@0 | 440 | /* c is a trail byte */ \ |
michael@0 | 441 | (c)&=0x3f; \ |
michael@0 | 442 | for(;;) { \ |
michael@0 | 443 | __b=(s)[--(i)]; \ |
michael@0 | 444 | if(__b>=0xc0) { \ |
michael@0 | 445 | UTF8_MASK_LEAD_BYTE(__b, __count); \ |
michael@0 | 446 | (c)|=(UChar32)__b<<__shift; \ |
michael@0 | 447 | break; \ |
michael@0 | 448 | } else { \ |
michael@0 | 449 | (c)|=(UChar32)(__b&0x3f)<<__shift; \ |
michael@0 | 450 | ++__count; \ |
michael@0 | 451 | __shift+=6; \ |
michael@0 | 452 | } \ |
michael@0 | 453 | } \ |
michael@0 | 454 | } \ |
michael@0 | 455 | } |
michael@0 | 456 | |
michael@0 | 457 | /** @deprecated ICU 2.4. Renamed to U8_BACK_1_UNSAFE, see utf_old.h. */ |
michael@0 | 458 | #define UTF8_BACK_1_UNSAFE(s, i) { \ |
michael@0 | 459 | while(UTF8_IS_TRAIL((s)[--(i)])) {} \ |
michael@0 | 460 | } |
michael@0 | 461 | |
michael@0 | 462 | /** @deprecated ICU 2.4. Renamed to U8_BACK_N_UNSAFE, see utf_old.h. */ |
michael@0 | 463 | #define UTF8_BACK_N_UNSAFE(s, i, n) { \ |
michael@0 | 464 | int32_t __N=(n); \ |
michael@0 | 465 | while(__N>0) { \ |
michael@0 | 466 | UTF8_BACK_1_UNSAFE(s, i); \ |
michael@0 | 467 | --__N; \ |
michael@0 | 468 | } \ |
michael@0 | 469 | } |
michael@0 | 470 | |
michael@0 | 471 | /** @deprecated ICU 2.4. Renamed to U8_SET_CP_LIMIT_UNSAFE, see utf_old.h. */ |
michael@0 | 472 | #define UTF8_SET_CHAR_LIMIT_UNSAFE(s, i) { \ |
michael@0 | 473 | UTF8_BACK_1_UNSAFE(s, i); \ |
michael@0 | 474 | UTF8_FWD_1_UNSAFE(s, i); \ |
michael@0 | 475 | } |
michael@0 | 476 | |
michael@0 | 477 | /** @deprecated ICU 2.4. Use U8_PREV instead, see utf_old.h. */ |
michael@0 | 478 | #define UTF8_PREV_CHAR_SAFE(s, start, i, c, strict) { \ |
michael@0 | 479 | (c)=(s)[--(i)]; \ |
michael@0 | 480 | if((c)>=0x80) { \ |
michael@0 | 481 | if((c)<=0xbf) { \ |
michael@0 | 482 | (c)=utf8_prevCharSafeBody(s, start, &(i), c, strict); \ |
michael@0 | 483 | } else { \ |
michael@0 | 484 | (c)=UTF8_ERROR_VALUE_1; \ |
michael@0 | 485 | } \ |
michael@0 | 486 | } \ |
michael@0 | 487 | } |
michael@0 | 488 | |
michael@0 | 489 | /** @deprecated ICU 2.4. Renamed to U8_BACK_1, see utf_old.h. */ |
michael@0 | 490 | #define UTF8_BACK_1_SAFE(s, start, i) U8_BACK_1(s, start, i) |
michael@0 | 491 | |
michael@0 | 492 | /** @deprecated ICU 2.4. Renamed to U8_BACK_N, see utf_old.h. */ |
michael@0 | 493 | #define UTF8_BACK_N_SAFE(s, start, i, n) U8_BACK_N(s, start, i, n) |
michael@0 | 494 | |
michael@0 | 495 | /** @deprecated ICU 2.4. Renamed to U8_SET_CP_LIMIT, see utf_old.h. */ |
michael@0 | 496 | #define UTF8_SET_CHAR_LIMIT_SAFE(s, start, i, length) U8_SET_CP_LIMIT(s, start, i, length) |
michael@0 | 497 | |
michael@0 | 498 | /* Formerly utf16.h --------------------------------------------------------- */ |
michael@0 | 499 | |
michael@0 | 500 | /** Is uchar a first/lead surrogate? @deprecated ICU 2.4. Renamed to U_IS_LEAD and U16_IS_LEAD, see utf_old.h. */ |
michael@0 | 501 | #define UTF_IS_FIRST_SURROGATE(uchar) (((uchar)&0xfffffc00)==0xd800) |
michael@0 | 502 | |
michael@0 | 503 | /** Is uchar a second/trail surrogate? @deprecated ICU 2.4. Renamed to U_IS_TRAIL and U16_IS_TRAIL, see utf_old.h. */ |
michael@0 | 504 | #define UTF_IS_SECOND_SURROGATE(uchar) (((uchar)&0xfffffc00)==0xdc00) |
michael@0 | 505 | |
michael@0 | 506 | /** Assuming c is a surrogate, is it a first/lead surrogate? @deprecated ICU 2.4. Renamed to U_IS_SURROGATE_LEAD and U16_IS_SURROGATE_LEAD, see utf_old.h. */ |
michael@0 | 507 | #define UTF_IS_SURROGATE_FIRST(c) (((c)&0x400)==0) |
michael@0 | 508 | |
michael@0 | 509 | /** Helper constant for UTF16_GET_PAIR_VALUE. @deprecated ICU 2.4. Renamed to U16_SURROGATE_OFFSET, see utf_old.h. */ |
michael@0 | 510 | #define UTF_SURROGATE_OFFSET ((0xd800<<10UL)+0xdc00-0x10000) |
michael@0 | 511 | |
michael@0 | 512 | /** Get the UTF-32 value from the surrogate code units. @deprecated ICU 2.4. Renamed to U16_GET_SUPPLEMENTARY, see utf_old.h. */ |
michael@0 | 513 | #define UTF16_GET_PAIR_VALUE(first, second) \ |
michael@0 | 514 | (((first)<<10UL)+(second)-UTF_SURROGATE_OFFSET) |
michael@0 | 515 | |
michael@0 | 516 | /** @deprecated ICU 2.4. Renamed to U16_LEAD, see utf_old.h. */ |
michael@0 | 517 | #define UTF_FIRST_SURROGATE(supplementary) (UChar)(((supplementary)>>10)+0xd7c0) |
michael@0 | 518 | |
michael@0 | 519 | /** @deprecated ICU 2.4. Renamed to U16_TRAIL, see utf_old.h. */ |
michael@0 | 520 | #define UTF_SECOND_SURROGATE(supplementary) (UChar)(((supplementary)&0x3ff)|0xdc00) |
michael@0 | 521 | |
michael@0 | 522 | /** @deprecated ICU 2.4. Renamed to U16_LEAD, see utf_old.h. */ |
michael@0 | 523 | #define UTF16_LEAD(supplementary) UTF_FIRST_SURROGATE(supplementary) |
michael@0 | 524 | |
michael@0 | 525 | /** @deprecated ICU 2.4. Renamed to U16_TRAIL, see utf_old.h. */ |
michael@0 | 526 | #define UTF16_TRAIL(supplementary) UTF_SECOND_SURROGATE(supplementary) |
michael@0 | 527 | |
michael@0 | 528 | /** @deprecated ICU 2.4. Renamed to U16_IS_SINGLE, see utf_old.h. */ |
michael@0 | 529 | #define UTF16_IS_SINGLE(uchar) !UTF_IS_SURROGATE(uchar) |
michael@0 | 530 | |
michael@0 | 531 | /** @deprecated ICU 2.4. Renamed to U16_IS_LEAD, see utf_old.h. */ |
michael@0 | 532 | #define UTF16_IS_LEAD(uchar) UTF_IS_FIRST_SURROGATE(uchar) |
michael@0 | 533 | |
michael@0 | 534 | /** @deprecated ICU 2.4. Renamed to U16_IS_TRAIL, see utf_old.h. */ |
michael@0 | 535 | #define UTF16_IS_TRAIL(uchar) UTF_IS_SECOND_SURROGATE(uchar) |
michael@0 | 536 | |
michael@0 | 537 | /** Does this scalar Unicode value need multiple code units for storage? @deprecated ICU 2.4. Use U16_LENGTH or test ((uint32_t)(c)>0xffff) instead, see utf_old.h. */ |
michael@0 | 538 | #define UTF16_NEED_MULTIPLE_UCHAR(c) ((uint32_t)(c)>0xffff) |
michael@0 | 539 | |
michael@0 | 540 | /** @deprecated ICU 2.4. Renamed to U16_LENGTH, see utf_old.h. */ |
michael@0 | 541 | #define UTF16_CHAR_LENGTH(c) ((uint32_t)(c)<=0xffff ? 1 : 2) |
michael@0 | 542 | |
michael@0 | 543 | /** @deprecated ICU 2.4. Renamed to U16_MAX_LENGTH, see utf_old.h. */ |
michael@0 | 544 | #define UTF16_MAX_CHAR_LENGTH 2 |
michael@0 | 545 | |
michael@0 | 546 | /** Average number of code units compared to UTF-16. @deprecated ICU 2.4. Obsolete, see utf_old.h. */ |
michael@0 | 547 | #define UTF16_ARRAY_SIZE(size) (size) |
michael@0 | 548 | |
michael@0 | 549 | /** |
michael@0 | 550 | * Get a single code point from an offset that points to any |
michael@0 | 551 | * of the code units that belong to that code point. |
michael@0 | 552 | * Assume 0<=i<length. |
michael@0 | 553 | * |
michael@0 | 554 | * This could be used for iteration together with |
michael@0 | 555 | * UTF16_CHAR_LENGTH() and UTF_IS_ERROR(), |
michael@0 | 556 | * but the use of UTF16_NEXT_CHAR[_UNSAFE]() and |
michael@0 | 557 | * UTF16_PREV_CHAR[_UNSAFE]() is more efficient for that. |
michael@0 | 558 | * @deprecated ICU 2.4. Renamed to U16_GET_UNSAFE, see utf_old.h. |
michael@0 | 559 | */ |
michael@0 | 560 | #define UTF16_GET_CHAR_UNSAFE(s, i, c) { \ |
michael@0 | 561 | (c)=(s)[i]; \ |
michael@0 | 562 | if(UTF_IS_SURROGATE(c)) { \ |
michael@0 | 563 | if(UTF_IS_SURROGATE_FIRST(c)) { \ |
michael@0 | 564 | (c)=UTF16_GET_PAIR_VALUE((c), (s)[(i)+1]); \ |
michael@0 | 565 | } else { \ |
michael@0 | 566 | (c)=UTF16_GET_PAIR_VALUE((s)[(i)-1], (c)); \ |
michael@0 | 567 | } \ |
michael@0 | 568 | } \ |
michael@0 | 569 | } |
michael@0 | 570 | |
michael@0 | 571 | /** @deprecated ICU 2.4. Use U16_GET instead, see utf_old.h. */ |
michael@0 | 572 | #define UTF16_GET_CHAR_SAFE(s, start, i, length, c, strict) { \ |
michael@0 | 573 | (c)=(s)[i]; \ |
michael@0 | 574 | if(UTF_IS_SURROGATE(c)) { \ |
michael@0 | 575 | uint16_t __c2; \ |
michael@0 | 576 | if(UTF_IS_SURROGATE_FIRST(c)) { \ |
michael@0 | 577 | if((i)+1<(length) && UTF_IS_SECOND_SURROGATE(__c2=(s)[(i)+1])) { \ |
michael@0 | 578 | (c)=UTF16_GET_PAIR_VALUE((c), __c2); \ |
michael@0 | 579 | /* strict: ((c)&0xfffe)==0xfffe is caught by UTF_IS_ERROR() and UTF_IS_UNICODE_CHAR() */ \ |
michael@0 | 580 | } else if(strict) {\ |
michael@0 | 581 | /* unmatched first surrogate */ \ |
michael@0 | 582 | (c)=UTF_ERROR_VALUE; \ |
michael@0 | 583 | } \ |
michael@0 | 584 | } else { \ |
michael@0 | 585 | if((i)-1>=(start) && UTF_IS_FIRST_SURROGATE(__c2=(s)[(i)-1])) { \ |
michael@0 | 586 | (c)=UTF16_GET_PAIR_VALUE(__c2, (c)); \ |
michael@0 | 587 | /* strict: ((c)&0xfffe)==0xfffe is caught by UTF_IS_ERROR() and UTF_IS_UNICODE_CHAR() */ \ |
michael@0 | 588 | } else if(strict) {\ |
michael@0 | 589 | /* unmatched second surrogate */ \ |
michael@0 | 590 | (c)=UTF_ERROR_VALUE; \ |
michael@0 | 591 | } \ |
michael@0 | 592 | } \ |
michael@0 | 593 | } else if((strict) && !UTF_IS_UNICODE_CHAR(c)) { \ |
michael@0 | 594 | (c)=UTF_ERROR_VALUE; \ |
michael@0 | 595 | } \ |
michael@0 | 596 | } |
michael@0 | 597 | |
michael@0 | 598 | /** @deprecated ICU 2.4. Renamed to U16_NEXT_UNSAFE, see utf_old.h. */ |
michael@0 | 599 | #define UTF16_NEXT_CHAR_UNSAFE(s, i, c) { \ |
michael@0 | 600 | (c)=(s)[(i)++]; \ |
michael@0 | 601 | if(UTF_IS_FIRST_SURROGATE(c)) { \ |
michael@0 | 602 | (c)=UTF16_GET_PAIR_VALUE((c), (s)[(i)++]); \ |
michael@0 | 603 | } \ |
michael@0 | 604 | } |
michael@0 | 605 | |
michael@0 | 606 | /** @deprecated ICU 2.4. Renamed to U16_APPEND_UNSAFE, see utf_old.h. */ |
michael@0 | 607 | #define UTF16_APPEND_CHAR_UNSAFE(s, i, c) { \ |
michael@0 | 608 | if((uint32_t)(c)<=0xffff) { \ |
michael@0 | 609 | (s)[(i)++]=(uint16_t)(c); \ |
michael@0 | 610 | } else { \ |
michael@0 | 611 | (s)[(i)++]=(uint16_t)(((c)>>10)+0xd7c0); \ |
michael@0 | 612 | (s)[(i)++]=(uint16_t)(((c)&0x3ff)|0xdc00); \ |
michael@0 | 613 | } \ |
michael@0 | 614 | } |
michael@0 | 615 | |
michael@0 | 616 | /** @deprecated ICU 2.4. Renamed to U16_FWD_1_UNSAFE, see utf_old.h. */ |
michael@0 | 617 | #define UTF16_FWD_1_UNSAFE(s, i) { \ |
michael@0 | 618 | if(UTF_IS_FIRST_SURROGATE((s)[(i)++])) { \ |
michael@0 | 619 | ++(i); \ |
michael@0 | 620 | } \ |
michael@0 | 621 | } |
michael@0 | 622 | |
michael@0 | 623 | /** @deprecated ICU 2.4. Renamed to U16_FWD_N_UNSAFE, see utf_old.h. */ |
michael@0 | 624 | #define UTF16_FWD_N_UNSAFE(s, i, n) { \ |
michael@0 | 625 | int32_t __N=(n); \ |
michael@0 | 626 | while(__N>0) { \ |
michael@0 | 627 | UTF16_FWD_1_UNSAFE(s, i); \ |
michael@0 | 628 | --__N; \ |
michael@0 | 629 | } \ |
michael@0 | 630 | } |
michael@0 | 631 | |
michael@0 | 632 | /** @deprecated ICU 2.4. Renamed to U16_SET_CP_START_UNSAFE, see utf_old.h. */ |
michael@0 | 633 | #define UTF16_SET_CHAR_START_UNSAFE(s, i) { \ |
michael@0 | 634 | if(UTF_IS_SECOND_SURROGATE((s)[i])) { \ |
michael@0 | 635 | --(i); \ |
michael@0 | 636 | } \ |
michael@0 | 637 | } |
michael@0 | 638 | |
michael@0 | 639 | /** @deprecated ICU 2.4. Use U16_NEXT instead, see utf_old.h. */ |
michael@0 | 640 | #define UTF16_NEXT_CHAR_SAFE(s, i, length, c, strict) { \ |
michael@0 | 641 | (c)=(s)[(i)++]; \ |
michael@0 | 642 | if(UTF_IS_FIRST_SURROGATE(c)) { \ |
michael@0 | 643 | uint16_t __c2; \ |
michael@0 | 644 | if((i)<(length) && UTF_IS_SECOND_SURROGATE(__c2=(s)[(i)])) { \ |
michael@0 | 645 | ++(i); \ |
michael@0 | 646 | (c)=UTF16_GET_PAIR_VALUE((c), __c2); \ |
michael@0 | 647 | /* strict: ((c)&0xfffe)==0xfffe is caught by UTF_IS_ERROR() and UTF_IS_UNICODE_CHAR() */ \ |
michael@0 | 648 | } else if(strict) {\ |
michael@0 | 649 | /* unmatched first surrogate */ \ |
michael@0 | 650 | (c)=UTF_ERROR_VALUE; \ |
michael@0 | 651 | } \ |
michael@0 | 652 | } else if((strict) && !UTF_IS_UNICODE_CHAR(c)) { \ |
michael@0 | 653 | /* unmatched second surrogate or other non-character */ \ |
michael@0 | 654 | (c)=UTF_ERROR_VALUE; \ |
michael@0 | 655 | } \ |
michael@0 | 656 | } |
michael@0 | 657 | |
michael@0 | 658 | /** @deprecated ICU 2.4. Use U16_APPEND instead, see utf_old.h. */ |
michael@0 | 659 | #define UTF16_APPEND_CHAR_SAFE(s, i, length, c) { \ |
michael@0 | 660 | if((uint32_t)(c)<=0xffff) { \ |
michael@0 | 661 | (s)[(i)++]=(uint16_t)(c); \ |
michael@0 | 662 | } else if((uint32_t)(c)<=0x10ffff) { \ |
michael@0 | 663 | if((i)+1<(length)) { \ |
michael@0 | 664 | (s)[(i)++]=(uint16_t)(((c)>>10)+0xd7c0); \ |
michael@0 | 665 | (s)[(i)++]=(uint16_t)(((c)&0x3ff)|0xdc00); \ |
michael@0 | 666 | } else /* not enough space */ { \ |
michael@0 | 667 | (s)[(i)++]=UTF_ERROR_VALUE; \ |
michael@0 | 668 | } \ |
michael@0 | 669 | } else /* c>0x10ffff, write error value */ { \ |
michael@0 | 670 | (s)[(i)++]=UTF_ERROR_VALUE; \ |
michael@0 | 671 | } \ |
michael@0 | 672 | } |
michael@0 | 673 | |
michael@0 | 674 | /** @deprecated ICU 2.4. Renamed to U16_FWD_1, see utf_old.h. */ |
michael@0 | 675 | #define UTF16_FWD_1_SAFE(s, i, length) U16_FWD_1(s, i, length) |
michael@0 | 676 | |
michael@0 | 677 | /** @deprecated ICU 2.4. Renamed to U16_FWD_N, see utf_old.h. */ |
michael@0 | 678 | #define UTF16_FWD_N_SAFE(s, i, length, n) U16_FWD_N(s, i, length, n) |
michael@0 | 679 | |
michael@0 | 680 | /** @deprecated ICU 2.4. Renamed to U16_SET_CP_START, see utf_old.h. */ |
michael@0 | 681 | #define UTF16_SET_CHAR_START_SAFE(s, start, i) U16_SET_CP_START(s, start, i) |
michael@0 | 682 | |
michael@0 | 683 | /** @deprecated ICU 2.4. Renamed to U16_PREV_UNSAFE, see utf_old.h. */ |
michael@0 | 684 | #define UTF16_PREV_CHAR_UNSAFE(s, i, c) { \ |
michael@0 | 685 | (c)=(s)[--(i)]; \ |
michael@0 | 686 | if(UTF_IS_SECOND_SURROGATE(c)) { \ |
michael@0 | 687 | (c)=UTF16_GET_PAIR_VALUE((s)[--(i)], (c)); \ |
michael@0 | 688 | } \ |
michael@0 | 689 | } |
michael@0 | 690 | |
michael@0 | 691 | /** @deprecated ICU 2.4. Renamed to U16_BACK_1_UNSAFE, see utf_old.h. */ |
michael@0 | 692 | #define UTF16_BACK_1_UNSAFE(s, i) { \ |
michael@0 | 693 | if(UTF_IS_SECOND_SURROGATE((s)[--(i)])) { \ |
michael@0 | 694 | --(i); \ |
michael@0 | 695 | } \ |
michael@0 | 696 | } |
michael@0 | 697 | |
michael@0 | 698 | /** @deprecated ICU 2.4. Renamed to U16_BACK_N_UNSAFE, see utf_old.h. */ |
michael@0 | 699 | #define UTF16_BACK_N_UNSAFE(s, i, n) { \ |
michael@0 | 700 | int32_t __N=(n); \ |
michael@0 | 701 | while(__N>0) { \ |
michael@0 | 702 | UTF16_BACK_1_UNSAFE(s, i); \ |
michael@0 | 703 | --__N; \ |
michael@0 | 704 | } \ |
michael@0 | 705 | } |
michael@0 | 706 | |
michael@0 | 707 | /** @deprecated ICU 2.4. Renamed to U16_SET_CP_LIMIT_UNSAFE, see utf_old.h. */ |
michael@0 | 708 | #define UTF16_SET_CHAR_LIMIT_UNSAFE(s, i) { \ |
michael@0 | 709 | if(UTF_IS_FIRST_SURROGATE((s)[(i)-1])) { \ |
michael@0 | 710 | ++(i); \ |
michael@0 | 711 | } \ |
michael@0 | 712 | } |
michael@0 | 713 | |
michael@0 | 714 | /** @deprecated ICU 2.4. Use U16_PREV instead, see utf_old.h. */ |
michael@0 | 715 | #define UTF16_PREV_CHAR_SAFE(s, start, i, c, strict) { \ |
michael@0 | 716 | (c)=(s)[--(i)]; \ |
michael@0 | 717 | if(UTF_IS_SECOND_SURROGATE(c)) { \ |
michael@0 | 718 | uint16_t __c2; \ |
michael@0 | 719 | if((i)>(start) && UTF_IS_FIRST_SURROGATE(__c2=(s)[(i)-1])) { \ |
michael@0 | 720 | --(i); \ |
michael@0 | 721 | (c)=UTF16_GET_PAIR_VALUE(__c2, (c)); \ |
michael@0 | 722 | /* strict: ((c)&0xfffe)==0xfffe is caught by UTF_IS_ERROR() and UTF_IS_UNICODE_CHAR() */ \ |
michael@0 | 723 | } else if(strict) {\ |
michael@0 | 724 | /* unmatched second surrogate */ \ |
michael@0 | 725 | (c)=UTF_ERROR_VALUE; \ |
michael@0 | 726 | } \ |
michael@0 | 727 | } else if((strict) && !UTF_IS_UNICODE_CHAR(c)) { \ |
michael@0 | 728 | /* unmatched first surrogate or other non-character */ \ |
michael@0 | 729 | (c)=UTF_ERROR_VALUE; \ |
michael@0 | 730 | } \ |
michael@0 | 731 | } |
michael@0 | 732 | |
michael@0 | 733 | /** @deprecated ICU 2.4. Renamed to U16_BACK_1, see utf_old.h. */ |
michael@0 | 734 | #define UTF16_BACK_1_SAFE(s, start, i) U16_BACK_1(s, start, i) |
michael@0 | 735 | |
michael@0 | 736 | /** @deprecated ICU 2.4. Renamed to U16_BACK_N, see utf_old.h. */ |
michael@0 | 737 | #define UTF16_BACK_N_SAFE(s, start, i, n) U16_BACK_N(s, start, i, n) |
michael@0 | 738 | |
michael@0 | 739 | /** @deprecated ICU 2.4. Renamed to U16_SET_CP_LIMIT, see utf_old.h. */ |
michael@0 | 740 | #define UTF16_SET_CHAR_LIMIT_SAFE(s, start, i, length) U16_SET_CP_LIMIT(s, start, i, length) |
michael@0 | 741 | |
michael@0 | 742 | /* Formerly utf32.h --------------------------------------------------------- */ |
michael@0 | 743 | |
michael@0 | 744 | /* |
michael@0 | 745 | * Old documentation: |
michael@0 | 746 | * |
michael@0 | 747 | * This file defines macros to deal with UTF-32 code units and code points. |
michael@0 | 748 | * Signatures and semantics are the same as for the similarly named macros |
michael@0 | 749 | * in utf16.h. |
michael@0 | 750 | * utf32.h is included by utf.h after unicode/umachine.h</p> |
michael@0 | 751 | * and some common definitions. |
michael@0 | 752 | * <p><b>Usage:</b> ICU coding guidelines for if() statements should be followed when using these macros. |
michael@0 | 753 | * Compound statements (curly braces {}) must be used for if-else-while... |
michael@0 | 754 | * bodies and all macro statements should be terminated with semicolon.</p> |
michael@0 | 755 | */ |
michael@0 | 756 | |
michael@0 | 757 | /* internal definitions ----------------------------------------------------- */ |
michael@0 | 758 | |
michael@0 | 759 | /** @deprecated ICU 2.4. Obsolete, see utf_old.h. */ |
michael@0 | 760 | #define UTF32_IS_SAFE(c, strict) \ |
michael@0 | 761 | (!(strict) ? \ |
michael@0 | 762 | (uint32_t)(c)<=0x10ffff : \ |
michael@0 | 763 | UTF_IS_UNICODE_CHAR(c)) |
michael@0 | 764 | |
michael@0 | 765 | /* |
michael@0 | 766 | * For the semantics of all of these macros, see utf16.h. |
michael@0 | 767 | * The UTF-32 versions are trivial because any code point is |
michael@0 | 768 | * encoded using exactly one code unit. |
michael@0 | 769 | */ |
michael@0 | 770 | |
michael@0 | 771 | /* single-code point definitions -------------------------------------------- */ |
michael@0 | 772 | |
michael@0 | 773 | /* classes of code unit values */ |
michael@0 | 774 | |
michael@0 | 775 | /** @deprecated ICU 2.4. Obsolete, see utf_old.h. */ |
michael@0 | 776 | #define UTF32_IS_SINGLE(uchar) 1 |
michael@0 | 777 | /** @deprecated ICU 2.4. Obsolete, see utf_old.h. */ |
michael@0 | 778 | #define UTF32_IS_LEAD(uchar) 0 |
michael@0 | 779 | /** @deprecated ICU 2.4. Obsolete, see utf_old.h. */ |
michael@0 | 780 | #define UTF32_IS_TRAIL(uchar) 0 |
michael@0 | 781 | |
michael@0 | 782 | /* number of code units per code point */ |
michael@0 | 783 | |
michael@0 | 784 | /** @deprecated ICU 2.4. Obsolete, see utf_old.h. */ |
michael@0 | 785 | #define UTF32_NEED_MULTIPLE_UCHAR(c) 0 |
michael@0 | 786 | /** @deprecated ICU 2.4. Obsolete, see utf_old.h. */ |
michael@0 | 787 | #define UTF32_CHAR_LENGTH(c) 1 |
michael@0 | 788 | /** @deprecated ICU 2.4. Obsolete, see utf_old.h. */ |
michael@0 | 789 | #define UTF32_MAX_CHAR_LENGTH 1 |
michael@0 | 790 | |
michael@0 | 791 | /* average number of code units compared to UTF-16 */ |
michael@0 | 792 | |
michael@0 | 793 | /** @deprecated ICU 2.4. Obsolete, see utf_old.h. */ |
michael@0 | 794 | #define UTF32_ARRAY_SIZE(size) (size) |
michael@0 | 795 | |
michael@0 | 796 | /** @deprecated ICU 2.4. Obsolete, see utf_old.h. */ |
michael@0 | 797 | #define UTF32_GET_CHAR_UNSAFE(s, i, c) { \ |
michael@0 | 798 | (c)=(s)[i]; \ |
michael@0 | 799 | } |
michael@0 | 800 | |
michael@0 | 801 | /** @deprecated ICU 2.4. Obsolete, see utf_old.h. */ |
michael@0 | 802 | #define UTF32_GET_CHAR_SAFE(s, start, i, length, c, strict) { \ |
michael@0 | 803 | (c)=(s)[i]; \ |
michael@0 | 804 | if(!UTF32_IS_SAFE(c, strict)) { \ |
michael@0 | 805 | (c)=UTF_ERROR_VALUE; \ |
michael@0 | 806 | } \ |
michael@0 | 807 | } |
michael@0 | 808 | |
michael@0 | 809 | /* definitions with forward iteration --------------------------------------- */ |
michael@0 | 810 | |
michael@0 | 811 | /** @deprecated ICU 2.4. Obsolete, see utf_old.h. */ |
michael@0 | 812 | #define UTF32_NEXT_CHAR_UNSAFE(s, i, c) { \ |
michael@0 | 813 | (c)=(s)[(i)++]; \ |
michael@0 | 814 | } |
michael@0 | 815 | |
michael@0 | 816 | /** @deprecated ICU 2.4. Obsolete, see utf_old.h. */ |
michael@0 | 817 | #define UTF32_APPEND_CHAR_UNSAFE(s, i, c) { \ |
michael@0 | 818 | (s)[(i)++]=(c); \ |
michael@0 | 819 | } |
michael@0 | 820 | |
michael@0 | 821 | /** @deprecated ICU 2.4. Obsolete, see utf_old.h. */ |
michael@0 | 822 | #define UTF32_FWD_1_UNSAFE(s, i) { \ |
michael@0 | 823 | ++(i); \ |
michael@0 | 824 | } |
michael@0 | 825 | |
michael@0 | 826 | /** @deprecated ICU 2.4. Obsolete, see utf_old.h. */ |
michael@0 | 827 | #define UTF32_FWD_N_UNSAFE(s, i, n) { \ |
michael@0 | 828 | (i)+=(n); \ |
michael@0 | 829 | } |
michael@0 | 830 | |
michael@0 | 831 | /** @deprecated ICU 2.4. Obsolete, see utf_old.h. */ |
michael@0 | 832 | #define UTF32_SET_CHAR_START_UNSAFE(s, i) { \ |
michael@0 | 833 | } |
michael@0 | 834 | |
michael@0 | 835 | /** @deprecated ICU 2.4. Obsolete, see utf_old.h. */ |
michael@0 | 836 | #define UTF32_NEXT_CHAR_SAFE(s, i, length, c, strict) { \ |
michael@0 | 837 | (c)=(s)[(i)++]; \ |
michael@0 | 838 | if(!UTF32_IS_SAFE(c, strict)) { \ |
michael@0 | 839 | (c)=UTF_ERROR_VALUE; \ |
michael@0 | 840 | } \ |
michael@0 | 841 | } |
michael@0 | 842 | |
michael@0 | 843 | /** @deprecated ICU 2.4. Obsolete, see utf_old.h. */ |
michael@0 | 844 | #define UTF32_APPEND_CHAR_SAFE(s, i, length, c) { \ |
michael@0 | 845 | if((uint32_t)(c)<=0x10ffff) { \ |
michael@0 | 846 | (s)[(i)++]=(c); \ |
michael@0 | 847 | } else /* c>0x10ffff, write 0xfffd */ { \ |
michael@0 | 848 | (s)[(i)++]=0xfffd; \ |
michael@0 | 849 | } \ |
michael@0 | 850 | } |
michael@0 | 851 | |
michael@0 | 852 | /** @deprecated ICU 2.4. Obsolete, see utf_old.h. */ |
michael@0 | 853 | #define UTF32_FWD_1_SAFE(s, i, length) { \ |
michael@0 | 854 | ++(i); \ |
michael@0 | 855 | } |
michael@0 | 856 | |
michael@0 | 857 | /** @deprecated ICU 2.4. Obsolete, see utf_old.h. */ |
michael@0 | 858 | #define UTF32_FWD_N_SAFE(s, i, length, n) { \ |
michael@0 | 859 | if(((i)+=(n))>(length)) { \ |
michael@0 | 860 | (i)=(length); \ |
michael@0 | 861 | } \ |
michael@0 | 862 | } |
michael@0 | 863 | |
michael@0 | 864 | /** @deprecated ICU 2.4. Obsolete, see utf_old.h. */ |
michael@0 | 865 | #define UTF32_SET_CHAR_START_SAFE(s, start, i) { \ |
michael@0 | 866 | } |
michael@0 | 867 | |
michael@0 | 868 | /* definitions with backward iteration -------------------------------------- */ |
michael@0 | 869 | |
michael@0 | 870 | /** @deprecated ICU 2.4. Obsolete, see utf_old.h. */ |
michael@0 | 871 | #define UTF32_PREV_CHAR_UNSAFE(s, i, c) { \ |
michael@0 | 872 | (c)=(s)[--(i)]; \ |
michael@0 | 873 | } |
michael@0 | 874 | |
michael@0 | 875 | /** @deprecated ICU 2.4. Obsolete, see utf_old.h. */ |
michael@0 | 876 | #define UTF32_BACK_1_UNSAFE(s, i) { \ |
michael@0 | 877 | --(i); \ |
michael@0 | 878 | } |
michael@0 | 879 | |
michael@0 | 880 | /** @deprecated ICU 2.4. Obsolete, see utf_old.h. */ |
michael@0 | 881 | #define UTF32_BACK_N_UNSAFE(s, i, n) { \ |
michael@0 | 882 | (i)-=(n); \ |
michael@0 | 883 | } |
michael@0 | 884 | |
michael@0 | 885 | /** @deprecated ICU 2.4. Obsolete, see utf_old.h. */ |
michael@0 | 886 | #define UTF32_SET_CHAR_LIMIT_UNSAFE(s, i) { \ |
michael@0 | 887 | } |
michael@0 | 888 | |
michael@0 | 889 | /** @deprecated ICU 2.4. Obsolete, see utf_old.h. */ |
michael@0 | 890 | #define UTF32_PREV_CHAR_SAFE(s, start, i, c, strict) { \ |
michael@0 | 891 | (c)=(s)[--(i)]; \ |
michael@0 | 892 | if(!UTF32_IS_SAFE(c, strict)) { \ |
michael@0 | 893 | (c)=UTF_ERROR_VALUE; \ |
michael@0 | 894 | } \ |
michael@0 | 895 | } |
michael@0 | 896 | |
michael@0 | 897 | /** @deprecated ICU 2.4. Obsolete, see utf_old.h. */ |
michael@0 | 898 | #define UTF32_BACK_1_SAFE(s, start, i) { \ |
michael@0 | 899 | --(i); \ |
michael@0 | 900 | } |
michael@0 | 901 | |
michael@0 | 902 | /** @deprecated ICU 2.4. Obsolete, see utf_old.h. */ |
michael@0 | 903 | #define UTF32_BACK_N_SAFE(s, start, i, n) { \ |
michael@0 | 904 | (i)-=(n); \ |
michael@0 | 905 | if((i)<(start)) { \ |
michael@0 | 906 | (i)=(start); \ |
michael@0 | 907 | } \ |
michael@0 | 908 | } |
michael@0 | 909 | |
michael@0 | 910 | /** @deprecated ICU 2.4. Obsolete, see utf_old.h. */ |
michael@0 | 911 | #define UTF32_SET_CHAR_LIMIT_SAFE(s, i, length) { \ |
michael@0 | 912 | } |
michael@0 | 913 | |
michael@0 | 914 | /* Formerly utf.h, part 2 --------------------------------------------------- */ |
michael@0 | 915 | |
michael@0 | 916 | /** |
michael@0 | 917 | * Estimate the number of code units for a string based on the number of UTF-16 code units. |
michael@0 | 918 | * |
michael@0 | 919 | * @deprecated ICU 2.4. Obsolete, see utf_old.h. |
michael@0 | 920 | */ |
michael@0 | 921 | #define UTF_ARRAY_SIZE(size) UTF16_ARRAY_SIZE(size) |
michael@0 | 922 | |
michael@0 | 923 | /** @deprecated ICU 2.4. Renamed to U16_GET_UNSAFE, see utf_old.h. */ |
michael@0 | 924 | #define UTF_GET_CHAR_UNSAFE(s, i, c) UTF16_GET_CHAR_UNSAFE(s, i, c) |
michael@0 | 925 | |
michael@0 | 926 | /** @deprecated ICU 2.4. Use U16_GET instead, see utf_old.h. */ |
michael@0 | 927 | #define UTF_GET_CHAR_SAFE(s, start, i, length, c, strict) UTF16_GET_CHAR_SAFE(s, start, i, length, c, strict) |
michael@0 | 928 | |
michael@0 | 929 | |
michael@0 | 930 | /** @deprecated ICU 2.4. Renamed to U16_NEXT_UNSAFE, see utf_old.h. */ |
michael@0 | 931 | #define UTF_NEXT_CHAR_UNSAFE(s, i, c) UTF16_NEXT_CHAR_UNSAFE(s, i, c) |
michael@0 | 932 | |
michael@0 | 933 | /** @deprecated ICU 2.4. Use U16_NEXT instead, see utf_old.h. */ |
michael@0 | 934 | #define UTF_NEXT_CHAR_SAFE(s, i, length, c, strict) UTF16_NEXT_CHAR_SAFE(s, i, length, c, strict) |
michael@0 | 935 | |
michael@0 | 936 | |
michael@0 | 937 | /** @deprecated ICU 2.4. Renamed to U16_APPEND_UNSAFE, see utf_old.h. */ |
michael@0 | 938 | #define UTF_APPEND_CHAR_UNSAFE(s, i, c) UTF16_APPEND_CHAR_UNSAFE(s, i, c) |
michael@0 | 939 | |
michael@0 | 940 | /** @deprecated ICU 2.4. Use U16_APPEND instead, see utf_old.h. */ |
michael@0 | 941 | #define UTF_APPEND_CHAR_SAFE(s, i, length, c) UTF16_APPEND_CHAR_SAFE(s, i, length, c) |
michael@0 | 942 | |
michael@0 | 943 | |
michael@0 | 944 | /** @deprecated ICU 2.4. Renamed to U16_FWD_1_UNSAFE, see utf_old.h. */ |
michael@0 | 945 | #define UTF_FWD_1_UNSAFE(s, i) UTF16_FWD_1_UNSAFE(s, i) |
michael@0 | 946 | |
michael@0 | 947 | /** @deprecated ICU 2.4. Renamed to U16_FWD_1, see utf_old.h. */ |
michael@0 | 948 | #define UTF_FWD_1_SAFE(s, i, length) UTF16_FWD_1_SAFE(s, i, length) |
michael@0 | 949 | |
michael@0 | 950 | |
michael@0 | 951 | /** @deprecated ICU 2.4. Renamed to U16_FWD_N_UNSAFE, see utf_old.h. */ |
michael@0 | 952 | #define UTF_FWD_N_UNSAFE(s, i, n) UTF16_FWD_N_UNSAFE(s, i, n) |
michael@0 | 953 | |
michael@0 | 954 | /** @deprecated ICU 2.4. Renamed to U16_FWD_N, see utf_old.h. */ |
michael@0 | 955 | #define UTF_FWD_N_SAFE(s, i, length, n) UTF16_FWD_N_SAFE(s, i, length, n) |
michael@0 | 956 | |
michael@0 | 957 | |
michael@0 | 958 | /** @deprecated ICU 2.4. Renamed to U16_SET_CP_START_UNSAFE, see utf_old.h. */ |
michael@0 | 959 | #define UTF_SET_CHAR_START_UNSAFE(s, i) UTF16_SET_CHAR_START_UNSAFE(s, i) |
michael@0 | 960 | |
michael@0 | 961 | /** @deprecated ICU 2.4. Renamed to U16_SET_CP_START, see utf_old.h. */ |
michael@0 | 962 | #define UTF_SET_CHAR_START_SAFE(s, start, i) UTF16_SET_CHAR_START_SAFE(s, start, i) |
michael@0 | 963 | |
michael@0 | 964 | |
michael@0 | 965 | /** @deprecated ICU 2.4. Renamed to U16_PREV_UNSAFE, see utf_old.h. */ |
michael@0 | 966 | #define UTF_PREV_CHAR_UNSAFE(s, i, c) UTF16_PREV_CHAR_UNSAFE(s, i, c) |
michael@0 | 967 | |
michael@0 | 968 | /** @deprecated ICU 2.4. Use U16_PREV instead, see utf_old.h. */ |
michael@0 | 969 | #define UTF_PREV_CHAR_SAFE(s, start, i, c, strict) UTF16_PREV_CHAR_SAFE(s, start, i, c, strict) |
michael@0 | 970 | |
michael@0 | 971 | |
michael@0 | 972 | /** @deprecated ICU 2.4. Renamed to U16_BACK_1_UNSAFE, see utf_old.h. */ |
michael@0 | 973 | #define UTF_BACK_1_UNSAFE(s, i) UTF16_BACK_1_UNSAFE(s, i) |
michael@0 | 974 | |
michael@0 | 975 | /** @deprecated ICU 2.4. Renamed to U16_BACK_1, see utf_old.h. */ |
michael@0 | 976 | #define UTF_BACK_1_SAFE(s, start, i) UTF16_BACK_1_SAFE(s, start, i) |
michael@0 | 977 | |
michael@0 | 978 | |
michael@0 | 979 | /** @deprecated ICU 2.4. Renamed to U16_BACK_N_UNSAFE, see utf_old.h. */ |
michael@0 | 980 | #define UTF_BACK_N_UNSAFE(s, i, n) UTF16_BACK_N_UNSAFE(s, i, n) |
michael@0 | 981 | |
michael@0 | 982 | /** @deprecated ICU 2.4. Renamed to U16_BACK_N, see utf_old.h. */ |
michael@0 | 983 | #define UTF_BACK_N_SAFE(s, start, i, n) UTF16_BACK_N_SAFE(s, start, i, n) |
michael@0 | 984 | |
michael@0 | 985 | |
michael@0 | 986 | /** @deprecated ICU 2.4. Renamed to U16_SET_CP_LIMIT_UNSAFE, see utf_old.h. */ |
michael@0 | 987 | #define UTF_SET_CHAR_LIMIT_UNSAFE(s, i) UTF16_SET_CHAR_LIMIT_UNSAFE(s, i) |
michael@0 | 988 | |
michael@0 | 989 | /** @deprecated ICU 2.4. Renamed to U16_SET_CP_LIMIT, see utf_old.h. */ |
michael@0 | 990 | #define UTF_SET_CHAR_LIMIT_SAFE(s, start, i, length) UTF16_SET_CHAR_LIMIT_SAFE(s, start, i, length) |
michael@0 | 991 | |
michael@0 | 992 | /* Define default macros (UTF-16 "safe") ------------------------------------ */ |
michael@0 | 993 | |
michael@0 | 994 | /** |
michael@0 | 995 | * Does this code unit alone encode a code point (BMP, not a surrogate)? |
michael@0 | 996 | * Same as UTF16_IS_SINGLE. |
michael@0 | 997 | * @deprecated ICU 2.4. Renamed to U_IS_SINGLE and U16_IS_SINGLE, see utf_old.h. |
michael@0 | 998 | */ |
michael@0 | 999 | #define UTF_IS_SINGLE(uchar) U16_IS_SINGLE(uchar) |
michael@0 | 1000 | |
michael@0 | 1001 | /** |
michael@0 | 1002 | * Is this code unit the first one of several (a lead surrogate)? |
michael@0 | 1003 | * Same as UTF16_IS_LEAD. |
michael@0 | 1004 | * @deprecated ICU 2.4. Renamed to U_IS_LEAD and U16_IS_LEAD, see utf_old.h. |
michael@0 | 1005 | */ |
michael@0 | 1006 | #define UTF_IS_LEAD(uchar) U16_IS_LEAD(uchar) |
michael@0 | 1007 | |
michael@0 | 1008 | /** |
michael@0 | 1009 | * Is this code unit one of several but not the first one (a trail surrogate)? |
michael@0 | 1010 | * Same as UTF16_IS_TRAIL. |
michael@0 | 1011 | * @deprecated ICU 2.4. Renamed to U_IS_TRAIL and U16_IS_TRAIL, see utf_old.h. |
michael@0 | 1012 | */ |
michael@0 | 1013 | #define UTF_IS_TRAIL(uchar) U16_IS_TRAIL(uchar) |
michael@0 | 1014 | |
michael@0 | 1015 | /** |
michael@0 | 1016 | * Does this code point require multiple code units (is it a supplementary code point)? |
michael@0 | 1017 | * Same as UTF16_NEED_MULTIPLE_UCHAR. |
michael@0 | 1018 | * @deprecated ICU 2.4. Use U16_LENGTH or test ((uint32_t)(c)>0xffff) instead. |
michael@0 | 1019 | */ |
michael@0 | 1020 | #define UTF_NEED_MULTIPLE_UCHAR(c) UTF16_NEED_MULTIPLE_UCHAR(c) |
michael@0 | 1021 | |
michael@0 | 1022 | /** |
michael@0 | 1023 | * How many code units are used to encode this code point (1 or 2)? |
michael@0 | 1024 | * Same as UTF16_CHAR_LENGTH. |
michael@0 | 1025 | * @deprecated ICU 2.4. Renamed to U16_LENGTH, see utf_old.h. |
michael@0 | 1026 | */ |
michael@0 | 1027 | #define UTF_CHAR_LENGTH(c) U16_LENGTH(c) |
michael@0 | 1028 | |
michael@0 | 1029 | /** |
michael@0 | 1030 | * How many code units are used at most for any Unicode code point (2)? |
michael@0 | 1031 | * Same as UTF16_MAX_CHAR_LENGTH. |
michael@0 | 1032 | * @deprecated ICU 2.4. Renamed to U16_MAX_LENGTH, see utf_old.h. |
michael@0 | 1033 | */ |
michael@0 | 1034 | #define UTF_MAX_CHAR_LENGTH U16_MAX_LENGTH |
michael@0 | 1035 | |
michael@0 | 1036 | /** |
michael@0 | 1037 | * Set c to the code point that contains the code unit i. |
michael@0 | 1038 | * i could point to the lead or the trail surrogate for the code point. |
michael@0 | 1039 | * i is not modified. |
michael@0 | 1040 | * Same as UTF16_GET_CHAR. |
michael@0 | 1041 | * \pre 0<=i<length |
michael@0 | 1042 | * |
michael@0 | 1043 | * @deprecated ICU 2.4. Renamed to U16_GET, see utf_old.h. |
michael@0 | 1044 | */ |
michael@0 | 1045 | #define UTF_GET_CHAR(s, start, i, length, c) U16_GET(s, start, i, length, c) |
michael@0 | 1046 | |
michael@0 | 1047 | /** |
michael@0 | 1048 | * Set c to the code point that starts at code unit i |
michael@0 | 1049 | * and advance i to beyond the code units of this code point (post-increment). |
michael@0 | 1050 | * i must point to the first code unit of a code point. |
michael@0 | 1051 | * Otherwise c is set to the trail unit (surrogate) itself. |
michael@0 | 1052 | * Same as UTF16_NEXT_CHAR. |
michael@0 | 1053 | * \pre 0<=i<length |
michael@0 | 1054 | * \post 0<i<=length |
michael@0 | 1055 | * |
michael@0 | 1056 | * @deprecated ICU 2.4. Renamed to U16_NEXT, see utf_old.h. |
michael@0 | 1057 | */ |
michael@0 | 1058 | #define UTF_NEXT_CHAR(s, i, length, c) U16_NEXT(s, i, length, c) |
michael@0 | 1059 | |
michael@0 | 1060 | /** |
michael@0 | 1061 | * Append the code units of code point c to the string at index i |
michael@0 | 1062 | * and advance i to beyond the new code units (post-increment). |
michael@0 | 1063 | * The code units beginning at index i will be overwritten. |
michael@0 | 1064 | * Same as UTF16_APPEND_CHAR. |
michael@0 | 1065 | * \pre 0<=c<=0x10ffff |
michael@0 | 1066 | * \pre 0<=i<length |
michael@0 | 1067 | * \post 0<i<=length |
michael@0 | 1068 | * |
michael@0 | 1069 | * @deprecated ICU 2.4. Use U16_APPEND instead, see utf_old.h. |
michael@0 | 1070 | */ |
michael@0 | 1071 | #define UTF_APPEND_CHAR(s, i, length, c) UTF16_APPEND_CHAR_SAFE(s, i, length, c) |
michael@0 | 1072 | |
michael@0 | 1073 | /** |
michael@0 | 1074 | * Advance i to beyond the code units of the code point that begins at i. |
michael@0 | 1075 | * I.e., advance i by one code point. |
michael@0 | 1076 | * Same as UTF16_FWD_1. |
michael@0 | 1077 | * \pre 0<=i<length |
michael@0 | 1078 | * \post 0<i<=length |
michael@0 | 1079 | * |
michael@0 | 1080 | * @deprecated ICU 2.4. Renamed to U16_FWD_1, see utf_old.h. |
michael@0 | 1081 | */ |
michael@0 | 1082 | #define UTF_FWD_1(s, i, length) U16_FWD_1(s, i, length) |
michael@0 | 1083 | |
michael@0 | 1084 | /** |
michael@0 | 1085 | * Advance i to beyond the code units of the n code points where the first one begins at i. |
michael@0 | 1086 | * I.e., advance i by n code points. |
michael@0 | 1087 | * Same as UT16_FWD_N. |
michael@0 | 1088 | * \pre 0<=i<length |
michael@0 | 1089 | * \post 0<i<=length |
michael@0 | 1090 | * |
michael@0 | 1091 | * @deprecated ICU 2.4. Renamed to U16_FWD_N, see utf_old.h. |
michael@0 | 1092 | */ |
michael@0 | 1093 | #define UTF_FWD_N(s, i, length, n) U16_FWD_N(s, i, length, n) |
michael@0 | 1094 | |
michael@0 | 1095 | /** |
michael@0 | 1096 | * Take the random-access index i and adjust it so that it points to the beginning |
michael@0 | 1097 | * of a code point. |
michael@0 | 1098 | * The input index points to any code unit of a code point and is moved to point to |
michael@0 | 1099 | * the first code unit of the same code point. i is never incremented. |
michael@0 | 1100 | * In other words, if i points to a trail surrogate that is preceded by a matching |
michael@0 | 1101 | * lead surrogate, then i is decremented. Otherwise it is not modified. |
michael@0 | 1102 | * This can be used to start an iteration with UTF_NEXT_CHAR() from a random index. |
michael@0 | 1103 | * Same as UTF16_SET_CHAR_START. |
michael@0 | 1104 | * \pre start<=i<length |
michael@0 | 1105 | * \post start<=i<length |
michael@0 | 1106 | * |
michael@0 | 1107 | * @deprecated ICU 2.4. Renamed to U16_SET_CP_START, see utf_old.h. |
michael@0 | 1108 | */ |
michael@0 | 1109 | #define UTF_SET_CHAR_START(s, start, i) U16_SET_CP_START(s, start, i) |
michael@0 | 1110 | |
michael@0 | 1111 | /** |
michael@0 | 1112 | * Set c to the code point that has code units before i |
michael@0 | 1113 | * and move i backward (towards the beginning of the string) |
michael@0 | 1114 | * to the first code unit of this code point (pre-increment). |
michael@0 | 1115 | * i must point to the first code unit after the last unit of a code point (i==length is allowed). |
michael@0 | 1116 | * Same as UTF16_PREV_CHAR. |
michael@0 | 1117 | * \pre start<i<=length |
michael@0 | 1118 | * \post start<=i<length |
michael@0 | 1119 | * |
michael@0 | 1120 | * @deprecated ICU 2.4. Renamed to U16_PREV, see utf_old.h. |
michael@0 | 1121 | */ |
michael@0 | 1122 | #define UTF_PREV_CHAR(s, start, i, c) U16_PREV(s, start, i, c) |
michael@0 | 1123 | |
michael@0 | 1124 | /** |
michael@0 | 1125 | * Move i backward (towards the beginning of the string) |
michael@0 | 1126 | * to the first code unit of the code point that has code units before i. |
michael@0 | 1127 | * I.e., move i backward by one code point. |
michael@0 | 1128 | * i must point to the first code unit after the last unit of a code point (i==length is allowed). |
michael@0 | 1129 | * Same as UTF16_BACK_1. |
michael@0 | 1130 | * \pre start<i<=length |
michael@0 | 1131 | * \post start<=i<length |
michael@0 | 1132 | * |
michael@0 | 1133 | * @deprecated ICU 2.4. Renamed to U16_BACK_1, see utf_old.h. |
michael@0 | 1134 | */ |
michael@0 | 1135 | #define UTF_BACK_1(s, start, i) U16_BACK_1(s, start, i) |
michael@0 | 1136 | |
michael@0 | 1137 | /** |
michael@0 | 1138 | * Move i backward (towards the beginning of the string) |
michael@0 | 1139 | * to the first code unit of the n code points that have code units before i. |
michael@0 | 1140 | * I.e., move i backward by n code points. |
michael@0 | 1141 | * i must point to the first code unit after the last unit of a code point (i==length is allowed). |
michael@0 | 1142 | * Same as UTF16_BACK_N. |
michael@0 | 1143 | * \pre start<i<=length |
michael@0 | 1144 | * \post start<=i<length |
michael@0 | 1145 | * |
michael@0 | 1146 | * @deprecated ICU 2.4. Renamed to U16_BACK_N, see utf_old.h. |
michael@0 | 1147 | */ |
michael@0 | 1148 | #define UTF_BACK_N(s, start, i, n) U16_BACK_N(s, start, i, n) |
michael@0 | 1149 | |
michael@0 | 1150 | /** |
michael@0 | 1151 | * Take the random-access index i and adjust it so that it points beyond |
michael@0 | 1152 | * a code point. The input index points beyond any code unit |
michael@0 | 1153 | * of a code point and is moved to point beyond the last code unit of the same |
michael@0 | 1154 | * code point. i is never decremented. |
michael@0 | 1155 | * In other words, if i points to a trail surrogate that is preceded by a matching |
michael@0 | 1156 | * lead surrogate, then i is incremented. Otherwise it is not modified. |
michael@0 | 1157 | * This can be used to start an iteration with UTF_PREV_CHAR() from a random index. |
michael@0 | 1158 | * Same as UTF16_SET_CHAR_LIMIT. |
michael@0 | 1159 | * \pre start<i<=length |
michael@0 | 1160 | * \post start<i<=length |
michael@0 | 1161 | * |
michael@0 | 1162 | * @deprecated ICU 2.4. Renamed to U16_SET_CP_LIMIT, see utf_old.h. |
michael@0 | 1163 | */ |
michael@0 | 1164 | #define UTF_SET_CHAR_LIMIT(s, start, i, length) U16_SET_CP_LIMIT(s, start, i, length) |
michael@0 | 1165 | |
michael@0 | 1166 | #endif /* U_HIDE_DEPRECATED_API */ |
michael@0 | 1167 | |
michael@0 | 1168 | #endif |
michael@0 | 1169 |