utf16.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  1. /*
  2. *******************************************************************************
  3. *
  4. * Copyright (C) 1999-2010, International Business Machines
  5. * Corporation and others. All Rights Reserved.
  6. *
  7. *******************************************************************************
  8. * file name: utf16.h
  9. * encoding: US-ASCII
  10. * tab size: 8 (not used)
  11. * indentation:4
  12. *
  13. * created on: 1999sep09
  14. * created by: Markus W. Scherer
  15. */
  16. /**
  17. * \file
  18. * \brief C API: 16-bit Unicode handling macros
  19. *
  20. * This file defines macros to deal with 16-bit Unicode (UTF-16) code units and strings.
  21. * utf16.h is included by utf.h after unicode/umachine.h
  22. * and some common definitions.
  23. *
  24. * For more information see utf.h and the ICU User Guide Strings chapter
  25. * (http://icu-project.org/userguide/strings.html).
  26. *
  27. * <em>Usage:</em>
  28. * ICU coding guidelines for if() statements should be followed when using these macros.
  29. * Compound statements (curly braces {}) must be used for if-else-while...
  30. * bodies and all macro statements should be terminated with semicolon.
  31. */
  32. #ifndef __UTF16_H__
  33. #define __UTF16_H__
  34. /* utf.h must be included first. */
  35. #ifndef __UTF_H__
  36. # include "unicode/utf.h"
  37. #endif
  38. /* single-code point definitions -------------------------------------------- */
  39. /**
  40. * Does this code unit alone encode a code point (BMP, not a surrogate)?
  41. * @param c 16-bit code unit
  42. * @return TRUE or FALSE
  43. * @stable ICU 2.4
  44. */
  45. #define U16_IS_SINGLE(c) !U_IS_SURROGATE(c)
  46. /**
  47. * Is this code unit a lead surrogate (U+d800..U+dbff)?
  48. * @param c 16-bit code unit
  49. * @return TRUE or FALSE
  50. * @stable ICU 2.4
  51. */
  52. #define U16_IS_LEAD(c) (((c)&0xfffffc00)==0xd800)
  53. /**
  54. * Is this code unit a trail surrogate (U+dc00..U+dfff)?
  55. * @param c 16-bit code unit
  56. * @return TRUE or FALSE
  57. * @stable ICU 2.4
  58. */
  59. #define U16_IS_TRAIL(c) (((c)&0xfffffc00)==0xdc00)
  60. /**
  61. * Is this code unit a surrogate (U+d800..U+dfff)?
  62. * @param c 16-bit code unit
  63. * @return TRUE or FALSE
  64. * @stable ICU 2.4
  65. */
  66. #define U16_IS_SURROGATE(c) U_IS_SURROGATE(c)
  67. /**
  68. * Assuming c is a surrogate code point (U16_IS_SURROGATE(c)),
  69. * is it a lead surrogate?
  70. * @param c 16-bit code unit
  71. * @return TRUE or FALSE
  72. * @stable ICU 2.4
  73. */
  74. #define U16_IS_SURROGATE_LEAD(c) (((c)&0x400)==0)
  75. /**
  76. * Assuming c is a surrogate code point (U16_IS_SURROGATE(c)),
  77. * is it a trail surrogate?
  78. * @param c 16-bit code unit
  79. * @return TRUE or FALSE
  80. * @stable ICU 4.2
  81. */
  82. #define U16_IS_SURROGATE_TRAIL(c) (((c)&0x400)!=0)
  83. /**
  84. * Helper constant for U16_GET_SUPPLEMENTARY.
  85. * @internal
  86. */
  87. #define U16_SURROGATE_OFFSET ((0xd800<<10UL)+0xdc00-0x10000)
  88. /**
  89. * Get a supplementary code point value (U+10000..U+10ffff)
  90. * from its lead and trail surrogates.
  91. * The result is undefined if the input values are not
  92. * lead and trail surrogates.
  93. *
  94. * @param lead lead surrogate (U+d800..U+dbff)
  95. * @param trail trail surrogate (U+dc00..U+dfff)
  96. * @return supplementary code point (U+10000..U+10ffff)
  97. * @stable ICU 2.4
  98. */
  99. #define U16_GET_SUPPLEMENTARY(lead, trail) \
  100. (((UChar32)(lead)<<10UL)+(UChar32)(trail)-U16_SURROGATE_OFFSET)
  101. /**
  102. * Get the lead surrogate (0xd800..0xdbff) for a
  103. * supplementary code point (0x10000..0x10ffff).
  104. * @param supplementary 32-bit code point (U+10000..U+10ffff)
  105. * @return lead surrogate (U+d800..U+dbff) for supplementary
  106. * @stable ICU 2.4
  107. */
  108. #define U16_LEAD(supplementary) (UChar)(((supplementary)>>10)+0xd7c0)
  109. /**
  110. * Get the trail surrogate (0xdc00..0xdfff) for a
  111. * supplementary code point (0x10000..0x10ffff).
  112. * @param supplementary 32-bit code point (U+10000..U+10ffff)
  113. * @return trail surrogate (U+dc00..U+dfff) for supplementary
  114. * @stable ICU 2.4
  115. */
  116. #define U16_TRAIL(supplementary) (UChar)(((supplementary)&0x3ff)|0xdc00)
  117. /**
  118. * How many 16-bit code units are used to encode this Unicode code point? (1 or 2)
  119. * The result is not defined if c is not a Unicode code point (U+0000..U+10ffff).
  120. * @param c 32-bit code point
  121. * @return 1 or 2
  122. * @stable ICU 2.4
  123. */
  124. #define U16_LENGTH(c) ((uint32_t)(c)<=0xffff ? 1 : 2)
  125. /**
  126. * The maximum number of 16-bit code units per Unicode code point (U+0000..U+10ffff).
  127. * @return 2
  128. * @stable ICU 2.4
  129. */
  130. #define U16_MAX_LENGTH 2
  131. /**
  132. * Get a code point from a string at a random-access offset,
  133. * without changing the offset.
  134. * "Unsafe" macro, assumes well-formed UTF-16.
  135. *
  136. * The offset may point to either the lead or trail surrogate unit
  137. * for a supplementary code point, in which case the macro will read
  138. * the adjacent matching surrogate as well.
  139. * The result is undefined if the offset points to a single, unpaired surrogate.
  140. * Iteration through a string is more efficient with U16_NEXT_UNSAFE or U16_NEXT.
  141. *
  142. * @param s const UChar * string
  143. * @param i string offset
  144. * @param c output UChar32 variable
  145. * @see U16_GET
  146. * @stable ICU 2.4
  147. */
  148. #define U16_GET_UNSAFE(s, i, c) { \
  149. (c)=(s)[i]; \
  150. if(U16_IS_SURROGATE(c)) { \
  151. if(U16_IS_SURROGATE_LEAD(c)) { \
  152. (c)=U16_GET_SUPPLEMENTARY((c), (s)[(i)+1]); \
  153. } else { \
  154. (c)=U16_GET_SUPPLEMENTARY((s)[(i)-1], (c)); \
  155. } \
  156. } \
  157. }
  158. /**
  159. * Get a code point from a string at a random-access offset,
  160. * without changing the offset.
  161. * "Safe" macro, handles unpaired surrogates and checks for string boundaries.
  162. *
  163. * The offset may point to either the lead or trail surrogate unit
  164. * for a supplementary code point, in which case the macro will read
  165. * the adjacent matching surrogate as well.
  166. * If the offset points to a single, unpaired surrogate, then that itself
  167. * will be returned as the code point.
  168. * Iteration through a string is more efficient with U16_NEXT_UNSAFE or U16_NEXT.
  169. *
  170. * @param s const UChar * string
  171. * @param start starting string offset (usually 0)
  172. * @param i string offset, must be start<=i<length
  173. * @param length string length
  174. * @param c output UChar32 variable
  175. * @see U16_GET_UNSAFE
  176. * @stable ICU 2.4
  177. */
  178. #define U16_GET(s, start, i, length, c) { \
  179. (c)=(s)[i]; \
  180. if(U16_IS_SURROGATE(c)) { \
  181. uint16_t __c2; \
  182. if(U16_IS_SURROGATE_LEAD(c)) { \
  183. if((i)+1<(length) && U16_IS_TRAIL(__c2=(s)[(i)+1])) { \
  184. (c)=U16_GET_SUPPLEMENTARY((c), __c2); \
  185. } \
  186. } else { \
  187. if((i)>(start) && U16_IS_LEAD(__c2=(s)[(i)-1])) { \
  188. (c)=U16_GET_SUPPLEMENTARY(__c2, (c)); \
  189. } \
  190. } \
  191. } \
  192. }
  193. /* definitions with forward iteration --------------------------------------- */
  194. /**
  195. * Get a code point from a string at a code point boundary offset,
  196. * and advance the offset to the next code point boundary.
  197. * (Post-incrementing forward iteration.)
  198. * "Unsafe" macro, assumes well-formed UTF-16.
  199. *
  200. * The offset may point to the lead surrogate unit
  201. * for a supplementary code point, in which case the macro will read
  202. * the following trail surrogate as well.
  203. * If the offset points to a trail surrogate, then that itself
  204. * will be returned as the code point.
  205. * The result is undefined if the offset points to a single, unpaired lead surrogate.
  206. *
  207. * @param s const UChar * string
  208. * @param i string offset
  209. * @param c output UChar32 variable
  210. * @see U16_NEXT
  211. * @stable ICU 2.4
  212. */
  213. #define U16_NEXT_UNSAFE(s, i, c) { \
  214. (c)=(s)[(i)++]; \
  215. if(U16_IS_LEAD(c)) { \
  216. (c)=U16_GET_SUPPLEMENTARY((c), (s)[(i)++]); \
  217. } \
  218. }
  219. /**
  220. * Get a code point from a string at a code point boundary offset,
  221. * and advance the offset to the next code point boundary.
  222. * (Post-incrementing forward iteration.)
  223. * "Safe" macro, handles unpaired surrogates and checks for string boundaries.
  224. *
  225. * The offset may point to the lead surrogate unit
  226. * for a supplementary code point, in which case the macro will read
  227. * the following trail surrogate as well.
  228. * If the offset points to a trail surrogate or
  229. * to a single, unpaired lead surrogate, then that itself
  230. * will be returned as the code point.
  231. *
  232. * @param s const UChar * string
  233. * @param i string offset, must be i<length
  234. * @param length string length
  235. * @param c output UChar32 variable
  236. * @see U16_NEXT_UNSAFE
  237. * @stable ICU 2.4
  238. */
  239. #define U16_NEXT(s, i, length, c) { \
  240. (c)=(s)[(i)++]; \
  241. if(U16_IS_LEAD(c)) { \
  242. uint16_t __c2; \
  243. if((i)<(length) && U16_IS_TRAIL(__c2=(s)[(i)])) { \
  244. ++(i); \
  245. (c)=U16_GET_SUPPLEMENTARY((c), __c2); \
  246. } \
  247. } \
  248. }
  249. /**
  250. * Append a code point to a string, overwriting 1 or 2 code units.
  251. * The offset points to the current end of the string contents
  252. * and is advanced (post-increment).
  253. * "Unsafe" macro, assumes a valid code point and sufficient space in the string.
  254. * Otherwise, the result is undefined.
  255. *
  256. * @param s const UChar * string buffer
  257. * @param i string offset
  258. * @param c code point to append
  259. * @see U16_APPEND
  260. * @stable ICU 2.4
  261. */
  262. #define U16_APPEND_UNSAFE(s, i, c) { \
  263. if((uint32_t)(c)<=0xffff) { \
  264. (s)[(i)++]=(uint16_t)(c); \
  265. } else { \
  266. (s)[(i)++]=(uint16_t)(((c)>>10)+0xd7c0); \
  267. (s)[(i)++]=(uint16_t)(((c)&0x3ff)|0xdc00); \
  268. } \
  269. }
  270. /**
  271. * Append a code point to a string, overwriting 1 or 2 code units.
  272. * The offset points to the current end of the string contents
  273. * and is advanced (post-increment).
  274. * "Safe" macro, checks for a valid code point.
  275. * If a surrogate pair is written, checks for sufficient space in the string.
  276. * If the code point is not valid or a trail surrogate does not fit,
  277. * then isError is set to TRUE.
  278. *
  279. * @param s const UChar * string buffer
  280. * @param i string offset, must be i<capacity
  281. * @param capacity size of the string buffer
  282. * @param c code point to append
  283. * @param isError output UBool set to TRUE if an error occurs, otherwise not modified
  284. * @see U16_APPEND_UNSAFE
  285. * @stable ICU 2.4
  286. */
  287. #define U16_APPEND(s, i, capacity, c, isError) { \
  288. if((uint32_t)(c)<=0xffff) { \
  289. (s)[(i)++]=(uint16_t)(c); \
  290. } else if((uint32_t)(c)<=0x10ffff && (i)+1<(capacity)) { \
  291. (s)[(i)++]=(uint16_t)(((c)>>10)+0xd7c0); \
  292. (s)[(i)++]=(uint16_t)(((c)&0x3ff)|0xdc00); \
  293. } else /* c>0x10ffff or not enough space */ { \
  294. (isError)=TRUE; \
  295. } \
  296. }
  297. /**
  298. * Advance the string offset from one code point boundary to the next.
  299. * (Post-incrementing iteration.)
  300. * "Unsafe" macro, assumes well-formed UTF-16.
  301. *
  302. * @param s const UChar * string
  303. * @param i string offset
  304. * @see U16_FWD_1
  305. * @stable ICU 2.4
  306. */
  307. #define U16_FWD_1_UNSAFE(s, i) { \
  308. if(U16_IS_LEAD((s)[(i)++])) { \
  309. ++(i); \
  310. } \
  311. }
  312. /**
  313. * Advance the string offset from one code point boundary to the next.
  314. * (Post-incrementing iteration.)
  315. * "Safe" macro, handles unpaired surrogates and checks for string boundaries.
  316. *
  317. * @param s const UChar * string
  318. * @param i string offset, must be i<length
  319. * @param length string length
  320. * @see U16_FWD_1_UNSAFE
  321. * @stable ICU 2.4
  322. */
  323. #define U16_FWD_1(s, i, length) { \
  324. if(U16_IS_LEAD((s)[(i)++]) && (i)<(length) && U16_IS_TRAIL((s)[i])) { \
  325. ++(i); \
  326. } \
  327. }
  328. /**
  329. * Advance the string offset from one code point boundary to the n-th next one,
  330. * i.e., move forward by n code points.
  331. * (Post-incrementing iteration.)
  332. * "Unsafe" macro, assumes well-formed UTF-16.
  333. *
  334. * @param s const UChar * string
  335. * @param i string offset
  336. * @param n number of code points to skip
  337. * @see U16_FWD_N
  338. * @stable ICU 2.4
  339. */
  340. #define U16_FWD_N_UNSAFE(s, i, n) { \
  341. int32_t __N=(n); \
  342. while(__N>0) { \
  343. U16_FWD_1_UNSAFE(s, i); \
  344. --__N; \
  345. } \
  346. }
  347. /**
  348. * Advance the string offset from one code point boundary to the n-th next one,
  349. * i.e., move forward by n code points.
  350. * (Post-incrementing iteration.)
  351. * "Safe" macro, handles unpaired surrogates and checks for string boundaries.
  352. *
  353. * @param s const UChar * string
  354. * @param i string offset, must be i<length
  355. * @param length string length
  356. * @param n number of code points to skip
  357. * @see U16_FWD_N_UNSAFE
  358. * @stable ICU 2.4
  359. */
  360. #define U16_FWD_N(s, i, length, n) { \
  361. int32_t __N=(n); \
  362. while(__N>0 && (i)<(length)) { \
  363. U16_FWD_1(s, i, length); \
  364. --__N; \
  365. } \
  366. }
  367. /**
  368. * Adjust a random-access offset to a code point boundary
  369. * at the start of a code point.
  370. * If the offset points to the trail surrogate of a surrogate pair,
  371. * then the offset is decremented.
  372. * Otherwise, it is not modified.
  373. * "Unsafe" macro, assumes well-formed UTF-16.
  374. *
  375. * @param s const UChar * string
  376. * @param i string offset
  377. * @see U16_SET_CP_START
  378. * @stable ICU 2.4
  379. */
  380. #define U16_SET_CP_START_UNSAFE(s, i) { \
  381. if(U16_IS_TRAIL((s)[i])) { \
  382. --(i); \
  383. } \
  384. }
  385. /**
  386. * Adjust a random-access offset to a code point boundary
  387. * at the start of a code point.
  388. * If the offset points to the trail surrogate of a surrogate pair,
  389. * then the offset is decremented.
  390. * Otherwise, it is not modified.
  391. * "Safe" macro, handles unpaired surrogates and checks for string boundaries.
  392. *
  393. * @param s const UChar * string
  394. * @param start starting string offset (usually 0)
  395. * @param i string offset, must be start<=i
  396. * @see U16_SET_CP_START_UNSAFE
  397. * @stable ICU 2.4
  398. */
  399. #define U16_SET_CP_START(s, start, i) { \
  400. if(U16_IS_TRAIL((s)[i]) && (i)>(start) && U16_IS_LEAD((s)[(i)-1])) { \
  401. --(i); \
  402. } \
  403. }
  404. /* definitions with backward iteration -------------------------------------- */
  405. /**
  406. * Move the string offset from one code point boundary to the previous one
  407. * and get the code point between them.
  408. * (Pre-decrementing backward iteration.)
  409. * "Unsafe" macro, assumes well-formed UTF-16.
  410. *
  411. * The input offset may be the same as the string length.
  412. * If the offset is behind a trail surrogate unit
  413. * for a supplementary code point, then the macro will read
  414. * the preceding lead surrogate as well.
  415. * If the offset is behind a lead surrogate, then that itself
  416. * will be returned as the code point.
  417. * The result is undefined if the offset is behind a single, unpaired trail surrogate.
  418. *
  419. * @param s const UChar * string
  420. * @param i string offset
  421. * @param c output UChar32 variable
  422. * @see U16_PREV
  423. * @stable ICU 2.4
  424. */
  425. #define U16_PREV_UNSAFE(s, i, c) { \
  426. (c)=(s)[--(i)]; \
  427. if(U16_IS_TRAIL(c)) { \
  428. (c)=U16_GET_SUPPLEMENTARY((s)[--(i)], (c)); \
  429. } \
  430. }
  431. /**
  432. * Move the string offset from one code point boundary to the previous one
  433. * and get the code point between them.
  434. * (Pre-decrementing backward iteration.)
  435. * "Safe" macro, handles unpaired surrogates and checks for string boundaries.
  436. *
  437. * The input offset may be the same as the string length.
  438. * If the offset is behind a trail surrogate unit
  439. * for a supplementary code point, then the macro will read
  440. * the preceding lead surrogate as well.
  441. * If the offset is behind a lead surrogate or behind a single, unpaired
  442. * trail surrogate, then that itself
  443. * will be returned as the code point.
  444. *
  445. * @param s const UChar * string
  446. * @param start starting string offset (usually 0)
  447. * @param i string offset, must be start<i
  448. * @param c output UChar32 variable
  449. * @see U16_PREV_UNSAFE
  450. * @stable ICU 2.4
  451. */
  452. #define U16_PREV(s, start, i, c) { \
  453. (c)=(s)[--(i)]; \
  454. if(U16_IS_TRAIL(c)) { \
  455. uint16_t __c2; \
  456. if((i)>(start) && U16_IS_LEAD(__c2=(s)[(i)-1])) { \
  457. --(i); \
  458. (c)=U16_GET_SUPPLEMENTARY(__c2, (c)); \
  459. } \
  460. } \
  461. }
  462. /**
  463. * Move the string offset from one code point boundary to the previous one.
  464. * (Pre-decrementing backward iteration.)
  465. * The input offset may be the same as the string length.
  466. * "Unsafe" macro, assumes well-formed UTF-16.
  467. *
  468. * @param s const UChar * string
  469. * @param i string offset
  470. * @see U16_BACK_1
  471. * @stable ICU 2.4
  472. */
  473. #define U16_BACK_1_UNSAFE(s, i) { \
  474. if(U16_IS_TRAIL((s)[--(i)])) { \
  475. --(i); \
  476. } \
  477. }
  478. /**
  479. * Move the string offset from one code point boundary to the previous one.
  480. * (Pre-decrementing backward iteration.)
  481. * The input offset may be the same as the string length.
  482. * "Safe" macro, handles unpaired surrogates and checks for string boundaries.
  483. *
  484. * @param s const UChar * string
  485. * @param start starting string offset (usually 0)
  486. * @param i string offset, must be start<i
  487. * @see U16_BACK_1_UNSAFE
  488. * @stable ICU 2.4
  489. */
  490. #define U16_BACK_1(s, start, i) { \
  491. if(U16_IS_TRAIL((s)[--(i)]) && (i)>(start) && U16_IS_LEAD((s)[(i)-1])) { \
  492. --(i); \
  493. } \
  494. }
  495. /**
  496. * Move the string offset from one code point boundary to the n-th one before it,
  497. * i.e., move backward by n code points.
  498. * (Pre-decrementing backward iteration.)
  499. * The input offset may be the same as the string length.
  500. * "Unsafe" macro, assumes well-formed UTF-16.
  501. *
  502. * @param s const UChar * string
  503. * @param i string offset
  504. * @param n number of code points to skip
  505. * @see U16_BACK_N
  506. * @stable ICU 2.4
  507. */
  508. #define U16_BACK_N_UNSAFE(s, i, n) { \
  509. int32_t __N=(n); \
  510. while(__N>0) { \
  511. U16_BACK_1_UNSAFE(s, i); \
  512. --__N; \
  513. } \
  514. }
  515. /**
  516. * Move the string offset from one code point boundary to the n-th one before it,
  517. * i.e., move backward by n code points.
  518. * (Pre-decrementing backward iteration.)
  519. * The input offset may be the same as the string length.
  520. * "Safe" macro, handles unpaired surrogates and checks for string boundaries.
  521. *
  522. * @param s const UChar * string
  523. * @param start start of string
  524. * @param i string offset, must be start<i
  525. * @param n number of code points to skip
  526. * @see U16_BACK_N_UNSAFE
  527. * @stable ICU 2.4
  528. */
  529. #define U16_BACK_N(s, start, i, n) { \
  530. int32_t __N=(n); \
  531. while(__N>0 && (i)>(start)) { \
  532. U16_BACK_1(s, start, i); \
  533. --__N; \
  534. } \
  535. }
  536. /**
  537. * Adjust a random-access offset to a code point boundary after a code point.
  538. * If the offset is behind the lead surrogate of a surrogate pair,
  539. * then the offset is incremented.
  540. * Otherwise, it is not modified.
  541. * The input offset may be the same as the string length.
  542. * "Unsafe" macro, assumes well-formed UTF-16.
  543. *
  544. * @param s const UChar * string
  545. * @param i string offset
  546. * @see U16_SET_CP_LIMIT
  547. * @stable ICU 2.4
  548. */
  549. #define U16_SET_CP_LIMIT_UNSAFE(s, i) { \
  550. if(U16_IS_LEAD((s)[(i)-1])) { \
  551. ++(i); \
  552. } \
  553. }
  554. /**
  555. * Adjust a random-access offset to a code point boundary after a code point.
  556. * If the offset is behind the lead surrogate of a surrogate pair,
  557. * then the offset is incremented.
  558. * Otherwise, it is not modified.
  559. * The input offset may be the same as the string length.
  560. * "Safe" macro, handles unpaired surrogates and checks for string boundaries.
  561. *
  562. * @param s const UChar * string
  563. * @param start starting string offset (usually 0)
  564. * @param i string offset, start<=i<=length
  565. * @param length string length
  566. * @see U16_SET_CP_LIMIT_UNSAFE
  567. * @stable ICU 2.4
  568. */
  569. #define U16_SET_CP_LIMIT(s, start, i, length) { \
  570. if((start)<(i) && (i)<(length) && U16_IS_LEAD((s)[(i)-1]) && U16_IS_TRAIL((s)[i])) { \
  571. ++(i); \
  572. } \
  573. }
  574. #endif