utf_old.h 43 KB

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