utf_old.h 42 KB

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