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