1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/textandloc/fontservices/textshaperplugin/IcuSource/common/unicode/utf16.h Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,605 @@
1.4 +/*
1.5 +*******************************************************************************
1.6 +*
1.7 +* Copyright (C) 1999-2005, International Business Machines
1.8 +* Corporation and others. All Rights Reserved.
1.9 +*
1.10 +*******************************************************************************
1.11 +* file name: utf16.h
1.12 +* encoding: US-ASCII
1.13 +* tab size: 8 (not used)
1.14 +* indentation:4
1.15 +*
1.16 +* created on: 1999sep09
1.17 +* created by: Markus W. Scherer
1.18 +*/
1.19 +
1.20 +/**
1.21 + * \file
1.22 + * \brief C API: 16-bit Unicode handling macros
1.23 + *
1.24 + * This file defines macros to deal with 16-bit Unicode (UTF-16) code units and strings.
1.25 + * utf16.h is included by utf.h after unicode/umachine.h
1.26 + * and some common definitions.
1.27 + *
1.28 + * For more information see utf.h and the ICU User Guide Strings chapter
1.29 + * (http://icu.sourceforge.net/userguide/strings.html).
1.30 + *
1.31 + * <em>Usage:</em>
1.32 + * ICU coding guidelines for if() statements should be followed when using these macros.
1.33 + * Compound statements (curly braces {}) must be used for if-else-while...
1.34 + * bodies and all macro statements should be terminated with semicolon.
1.35 + */
1.36 +
1.37 +#ifndef __UTF16_H__
1.38 +#define __UTF16_H__
1.39 +
1.40 +/* utf.h must be included first. */
1.41 +#ifndef __UTF_H__
1.42 +# include "unicode/utf.h"
1.43 +#endif
1.44 +
1.45 +/* single-code point definitions -------------------------------------------- */
1.46 +
1.47 +/**
1.48 + * Does this code unit alone encode a code point (BMP, not a surrogate)?
1.49 + * @param c 16-bit code unit
1.50 + * @return TRUE or FALSE
1.51 + * @stable ICU 2.4
1.52 + */
1.53 +#define U16_IS_SINGLE(c) !U_IS_SURROGATE(c)
1.54 +
1.55 +/**
1.56 + * Is this code unit a lead surrogate (U+d800..U+dbff)?
1.57 + * @param c 16-bit code unit
1.58 + * @return TRUE or FALSE
1.59 + * @stable ICU 2.4
1.60 + */
1.61 +#define U16_IS_LEAD(c) (((c)&0xfffffc00)==0xd800)
1.62 +
1.63 +/**
1.64 + * Is this code unit a trail surrogate (U+dc00..U+dfff)?
1.65 + * @param c 16-bit code unit
1.66 + * @return TRUE or FALSE
1.67 + * @stable ICU 2.4
1.68 + */
1.69 +#define U16_IS_TRAIL(c) (((c)&0xfffffc00)==0xdc00)
1.70 +
1.71 +/**
1.72 + * Is this code unit a surrogate (U+d800..U+dfff)?
1.73 + * @param c 16-bit code unit
1.74 + * @return TRUE or FALSE
1.75 + * @stable ICU 2.4
1.76 + */
1.77 +#define U16_IS_SURROGATE(c) U_IS_SURROGATE(c)
1.78 +
1.79 +/**
1.80 + * Assuming c is a surrogate code point (U16_IS_SURROGATE(c)),
1.81 + * is it a lead surrogate?
1.82 + * @param c 16-bit code unit
1.83 + * @return TRUE or FALSE
1.84 + * @stable ICU 2.4
1.85 + */
1.86 +#define U16_IS_SURROGATE_LEAD(c) (((c)&0x400)==0)
1.87 +
1.88 +/**
1.89 + * Helper constant for U16_GET_SUPPLEMENTARY.
1.90 + * @internal
1.91 + */
1.92 +#define U16_SURROGATE_OFFSET ((0xd800<<10UL)+0xdc00-0x10000)
1.93 +
1.94 +/**
1.95 + * Get a supplementary code point value (U+10000..U+10ffff)
1.96 + * from its lead and trail surrogates.
1.97 + * The result is undefined if the input values are not
1.98 + * lead and trail surrogates.
1.99 + *
1.100 + * @param lead lead surrogate (U+d800..U+dbff)
1.101 + * @param trail trail surrogate (U+dc00..U+dfff)
1.102 + * @return supplementary code point (U+10000..U+10ffff)
1.103 + * @stable ICU 2.4
1.104 + */
1.105 +#define U16_GET_SUPPLEMENTARY(lead, trail) \
1.106 + (((UChar32)(lead)<<10UL)+(UChar32)(trail)-U16_SURROGATE_OFFSET)
1.107 +
1.108 +
1.109 +/**
1.110 + * Get the lead surrogate (0xd800..0xdbff) for a
1.111 + * supplementary code point (0x10000..0x10ffff).
1.112 + * @param supplementary 32-bit code point (U+10000..U+10ffff)
1.113 + * @return lead surrogate (U+d800..U+dbff) for supplementary
1.114 + * @stable ICU 2.4
1.115 + */
1.116 +#define U16_LEAD(supplementary) (UChar)(((supplementary)>>10)+0xd7c0)
1.117 +
1.118 +/**
1.119 + * Get the trail surrogate (0xdc00..0xdfff) for a
1.120 + * supplementary code point (0x10000..0x10ffff).
1.121 + * @param supplementary 32-bit code point (U+10000..U+10ffff)
1.122 + * @return trail surrogate (U+dc00..U+dfff) for supplementary
1.123 + * @stable ICU 2.4
1.124 + */
1.125 +#define U16_TRAIL(supplementary) (UChar)(((supplementary)&0x3ff)|0xdc00)
1.126 +
1.127 +/**
1.128 + * How many 16-bit code units are used to encode this Unicode code point? (1 or 2)
1.129 + * The result is not defined if c is not a Unicode code point (U+0000..U+10ffff).
1.130 + * @param c 32-bit code point
1.131 + * @return 1 or 2
1.132 + * @stable ICU 2.4
1.133 + */
1.134 +#define U16_LENGTH(c) ((uint32_t)(c)<=0xffff ? 1 : 2)
1.135 +
1.136 +/**
1.137 + * The maximum number of 16-bit code units per Unicode code point (U+0000..U+10ffff).
1.138 + * @return 2
1.139 + * @stable ICU 2.4
1.140 + */
1.141 +#define U16_MAX_LENGTH 2
1.142 +
1.143 +/**
1.144 + * Get a code point from a string at a random-access offset,
1.145 + * without changing the offset.
1.146 + * "Unsafe" macro, assumes well-formed UTF-16.
1.147 + *
1.148 + * The offset may point to either the lead or trail surrogate unit
1.149 + * for a supplementary code point, in which case the macro will read
1.150 + * the adjacent matching surrogate as well.
1.151 + * The result is undefined if the offset points to a single, unpaired surrogate.
1.152 + * Iteration through a string is more efficient with U16_NEXT_UNSAFE or U16_NEXT.
1.153 + *
1.154 + * @param s const UChar * string
1.155 + * @param i string offset
1.156 + * @param c output UChar32 variable
1.157 + * @see U16_GET
1.158 + * @stable ICU 2.4
1.159 + */
1.160 +#define U16_GET_UNSAFE(s, i, c) { \
1.161 + (c)=(s)[i]; \
1.162 + if(U16_IS_SURROGATE(c)) { \
1.163 + if(U16_IS_SURROGATE_LEAD(c)) { \
1.164 + (c)=U16_GET_SUPPLEMENTARY((c), (s)[(i)+1]); \
1.165 + } else { \
1.166 + (c)=U16_GET_SUPPLEMENTARY((s)[(i)-1], (c)); \
1.167 + } \
1.168 + } \
1.169 +}
1.170 +
1.171 +/**
1.172 + * Get a code point from a string at a random-access offset,
1.173 + * without changing the offset.
1.174 + * "Safe" macro, handles unpaired surrogates and checks for string boundaries.
1.175 + *
1.176 + * The offset may point to either the lead or trail surrogate unit
1.177 + * for a supplementary code point, in which case the macro will read
1.178 + * the adjacent matching surrogate as well.
1.179 + * If the offset points to a single, unpaired surrogate, then that itself
1.180 + * will be returned as the code point.
1.181 + * Iteration through a string is more efficient with U16_NEXT_UNSAFE or U16_NEXT.
1.182 + *
1.183 + * @param s const UChar * string
1.184 + * @param start starting string offset (usually 0)
1.185 + * @param i string offset, start<=i<length
1.186 + * @param length string length
1.187 + * @param c output UChar32 variable
1.188 + * @see U16_GET_UNSAFE
1.189 + * @stable ICU 2.4
1.190 + */
1.191 +#define U16_GET(s, start, i, length, c) { \
1.192 + (c)=(s)[i]; \
1.193 + if(U16_IS_SURROGATE(c)) { \
1.194 + uint16_t __c2; \
1.195 + if(U16_IS_SURROGATE_LEAD(c)) { \
1.196 + if((i)+1<(length) && U16_IS_TRAIL(__c2=(s)[(i)+1])) { \
1.197 + (c)=U16_GET_SUPPLEMENTARY((c), __c2); \
1.198 + } \
1.199 + } else { \
1.200 + if((i)-1>=(start) && U16_IS_LEAD(__c2=(s)[(i)-1])) { \
1.201 + (c)=U16_GET_SUPPLEMENTARY(__c2, (c)); \
1.202 + } \
1.203 + } \
1.204 + } \
1.205 +}
1.206 +
1.207 +/* definitions with forward iteration --------------------------------------- */
1.208 +
1.209 +/**
1.210 + * Get a code point from a string at a code point boundary offset,
1.211 + * and advance the offset to the next code point boundary.
1.212 + * (Post-incrementing forward iteration.)
1.213 + * "Unsafe" macro, assumes well-formed UTF-16.
1.214 + *
1.215 + * The offset may point to the lead surrogate unit
1.216 + * for a supplementary code point, in which case the macro will read
1.217 + * the following trail surrogate as well.
1.218 + * If the offset points to a trail surrogate, then that itself
1.219 + * will be returned as the code point.
1.220 + * The result is undefined if the offset points to a single, unpaired lead surrogate.
1.221 + *
1.222 + * @param s const UChar * string
1.223 + * @param i string offset
1.224 + * @param c output UChar32 variable
1.225 + * @see U16_NEXT
1.226 + * @stable ICU 2.4
1.227 + */
1.228 +#define U16_NEXT_UNSAFE(s, i, c) { \
1.229 + (c)=(s)[(i)++]; \
1.230 + if(U16_IS_LEAD(c)) { \
1.231 + (c)=U16_GET_SUPPLEMENTARY((c), (s)[(i)++]); \
1.232 + } \
1.233 +}
1.234 +
1.235 +/**
1.236 + * Get a code point from a string at a code point boundary offset,
1.237 + * and advance the offset to the next code point boundary.
1.238 + * (Post-incrementing forward iteration.)
1.239 + * "Safe" macro, handles unpaired surrogates and checks for string boundaries.
1.240 + *
1.241 + * The offset may point to the lead surrogate unit
1.242 + * for a supplementary code point, in which case the macro will read
1.243 + * the following trail surrogate as well.
1.244 + * If the offset points to a trail surrogate or
1.245 + * to a single, unpaired lead surrogate, then that itself
1.246 + * will be returned as the code point.
1.247 + *
1.248 + * @param s const UChar * string
1.249 + * @param i string offset, i<length
1.250 + * @param length string length
1.251 + * @param c output UChar32 variable
1.252 + * @see U16_NEXT_UNSAFE
1.253 + * @stable ICU 2.4
1.254 + */
1.255 +#define U16_NEXT(s, i, length, c) { \
1.256 + (c)=(s)[(i)++]; \
1.257 + if(U16_IS_LEAD(c)) { \
1.258 + uint16_t __c2; \
1.259 + if((i)<(length) && U16_IS_TRAIL(__c2=(s)[(i)])) { \
1.260 + ++(i); \
1.261 + (c)=U16_GET_SUPPLEMENTARY((c), __c2); \
1.262 + } \
1.263 + } \
1.264 +}
1.265 +
1.266 +/**
1.267 + * Append a code point to a string, overwriting 1 or 2 code units.
1.268 + * The offset points to the current end of the string contents
1.269 + * and is advanced (post-increment).
1.270 + * "Unsafe" macro, assumes a valid code point and sufficient space in the string.
1.271 + * Otherwise, the result is undefined.
1.272 + *
1.273 + * @param s const UChar * string buffer
1.274 + * @param i string offset
1.275 + * @param c code point to append
1.276 + * @see U16_APPEND
1.277 + * @stable ICU 2.4
1.278 + */
1.279 +#define U16_APPEND_UNSAFE(s, i, c) { \
1.280 + if((uint32_t)(c)<=0xffff) { \
1.281 + (s)[(i)++]=(uint16_t)(c); \
1.282 + } else { \
1.283 + (s)[(i)++]=(uint16_t)(((c)>>10)+0xd7c0); \
1.284 + (s)[(i)++]=(uint16_t)(((c)&0x3ff)|0xdc00); \
1.285 + } \
1.286 +}
1.287 +
1.288 +/**
1.289 + * Append a code point to a string, overwriting 1 or 2 code units.
1.290 + * The offset points to the current end of the string contents
1.291 + * and is advanced (post-increment).
1.292 + * "Safe" macro, checks for a valid code point.
1.293 + * If a surrogate pair is written, checks for sufficient space in the string.
1.294 + * If the code point is not valid or a trail surrogate does not fit,
1.295 + * then isError is set to TRUE.
1.296 + *
1.297 + * @param s const UChar * string buffer
1.298 + * @param i string offset, i<length
1.299 + * @param capacity size of the string buffer
1.300 + * @param c code point to append
1.301 + * @param isError output UBool set to TRUE if an error occurs, otherwise not modified
1.302 + * @see U16_APPEND_UNSAFE
1.303 + * @stable ICU 2.4
1.304 + */
1.305 +#define U16_APPEND(s, i, capacity, c, isError) { \
1.306 + if((uint32_t)(c)<=0xffff) { \
1.307 + (s)[(i)++]=(uint16_t)(c); \
1.308 + } else if((uint32_t)(c)<=0x10ffff && (i)+1<(capacity)) { \
1.309 + (s)[(i)++]=(uint16_t)(((c)>>10)+0xd7c0); \
1.310 + (s)[(i)++]=(uint16_t)(((c)&0x3ff)|0xdc00); \
1.311 + } else /* c>0x10ffff or not enough space */ { \
1.312 + (isError)=TRUE; \
1.313 + } \
1.314 +}
1.315 +
1.316 +/**
1.317 + * Advance the string offset from one code point boundary to the next.
1.318 + * (Post-incrementing iteration.)
1.319 + * "Unsafe" macro, assumes well-formed UTF-16.
1.320 + *
1.321 + * @param s const UChar * string
1.322 + * @param i string offset
1.323 + * @see U16_FWD_1
1.324 + * @stable ICU 2.4
1.325 + */
1.326 +#define U16_FWD_1_UNSAFE(s, i) { \
1.327 + if(U16_IS_LEAD((s)[(i)++])) { \
1.328 + ++(i); \
1.329 + } \
1.330 +}
1.331 +
1.332 +/**
1.333 + * Advance the string offset from one code point boundary to the next.
1.334 + * (Post-incrementing iteration.)
1.335 + * "Safe" macro, handles unpaired surrogates and checks for string boundaries.
1.336 + *
1.337 + * @param s const UChar * string
1.338 + * @param i string offset, i<length
1.339 + * @param length string length
1.340 + * @see U16_FWD_1_UNSAFE
1.341 + * @stable ICU 2.4
1.342 + */
1.343 +#define U16_FWD_1(s, i, length) { \
1.344 + if(U16_IS_LEAD((s)[(i)++]) && (i)<(length) && U16_IS_TRAIL((s)[i])) { \
1.345 + ++(i); \
1.346 + } \
1.347 +}
1.348 +
1.349 +/**
1.350 + * Advance the string offset from one code point boundary to the n-th next one,
1.351 + * i.e., move forward by n code points.
1.352 + * (Post-incrementing iteration.)
1.353 + * "Unsafe" macro, assumes well-formed UTF-16.
1.354 + *
1.355 + * @param s const UChar * string
1.356 + * @param i string offset
1.357 + * @param n number of code points to skip
1.358 + * @see U16_FWD_N
1.359 + * @stable ICU 2.4
1.360 + */
1.361 +#define U16_FWD_N_UNSAFE(s, i, n) { \
1.362 + int32_t __N=(n); \
1.363 + while(__N>0) { \
1.364 + U16_FWD_1_UNSAFE(s, i); \
1.365 + --__N; \
1.366 + } \
1.367 +}
1.368 +
1.369 +/**
1.370 + * Advance the string offset from one code point boundary to the n-th next one,
1.371 + * i.e., move forward by n code points.
1.372 + * (Post-incrementing iteration.)
1.373 + * "Safe" macro, handles unpaired surrogates and checks for string boundaries.
1.374 + *
1.375 + * @param s const UChar * string
1.376 + * @param i string offset, i<length
1.377 + * @param length string length
1.378 + * @param n number of code points to skip
1.379 + * @see U16_FWD_N_UNSAFE
1.380 + * @stable ICU 2.4
1.381 + */
1.382 +#define U16_FWD_N(s, i, length, n) { \
1.383 + int32_t __N=(n); \
1.384 + while(__N>0 && (i)<(length)) { \
1.385 + U16_FWD_1(s, i, length); \
1.386 + --__N; \
1.387 + } \
1.388 +}
1.389 +
1.390 +/**
1.391 + * Adjust a random-access offset to a code point boundary
1.392 + * at the start of a code point.
1.393 + * If the offset points to the trail surrogate of a surrogate pair,
1.394 + * then the offset is decremented.
1.395 + * Otherwise, it is not modified.
1.396 + * "Unsafe" macro, assumes well-formed UTF-16.
1.397 + *
1.398 + * @param s const UChar * string
1.399 + * @param i string offset
1.400 + * @see U16_SET_CP_START
1.401 + * @stable ICU 2.4
1.402 + */
1.403 +#define U16_SET_CP_START_UNSAFE(s, i) { \
1.404 + if(U16_IS_TRAIL((s)[i])) { \
1.405 + --(i); \
1.406 + } \
1.407 +}
1.408 +
1.409 +/**
1.410 + * Adjust a random-access offset to a code point boundary
1.411 + * at the start of a code point.
1.412 + * If the offset points to the trail surrogate of a surrogate pair,
1.413 + * then the offset is decremented.
1.414 + * Otherwise, it is not modified.
1.415 + * "Safe" macro, handles unpaired surrogates and checks for string boundaries.
1.416 + *
1.417 + * @param s const UChar * string
1.418 + * @param start starting string offset (usually 0)
1.419 + * @param i string offset, start<=i
1.420 + * @see U16_SET_CP_START_UNSAFE
1.421 + * @stable ICU 2.4
1.422 + */
1.423 +#define U16_SET_CP_START(s, start, i) { \
1.424 + if(U16_IS_TRAIL((s)[i]) && (i)>(start) && U16_IS_LEAD((s)[(i)-1])) { \
1.425 + --(i); \
1.426 + } \
1.427 +}
1.428 +
1.429 +/* definitions with backward iteration -------------------------------------- */
1.430 +
1.431 +/**
1.432 + * Move the string offset from one code point boundary to the previous one
1.433 + * and get the code point between them.
1.434 + * (Pre-decrementing backward iteration.)
1.435 + * "Unsafe" macro, assumes well-formed UTF-16.
1.436 + *
1.437 + * The input offset may be the same as the string length.
1.438 + * If the offset is behind a trail surrogate unit
1.439 + * for a supplementary code point, then the macro will read
1.440 + * the preceding lead surrogate as well.
1.441 + * If the offset is behind a lead surrogate, then that itself
1.442 + * will be returned as the code point.
1.443 + * The result is undefined if the offset is behind a single, unpaired trail surrogate.
1.444 + *
1.445 + * @param s const UChar * string
1.446 + * @param i string offset
1.447 + * @param c output UChar32 variable
1.448 + * @see U16_PREV
1.449 + * @stable ICU 2.4
1.450 + */
1.451 +#define U16_PREV_UNSAFE(s, i, c) { \
1.452 + (c)=(s)[--(i)]; \
1.453 + if(U16_IS_TRAIL(c)) { \
1.454 + (c)=U16_GET_SUPPLEMENTARY((s)[--(i)], (c)); \
1.455 + } \
1.456 +}
1.457 +
1.458 +/**
1.459 + * Move the string offset from one code point boundary to the previous one
1.460 + * and get the code point between them.
1.461 + * (Pre-decrementing backward iteration.)
1.462 + * "Safe" macro, handles unpaired surrogates and checks for string boundaries.
1.463 + *
1.464 + * The input offset may be the same as the string length.
1.465 + * If the offset is behind a trail surrogate unit
1.466 + * for a supplementary code point, then the macro will read
1.467 + * the preceding lead surrogate as well.
1.468 + * If the offset is behind a lead surrogate or behind a single, unpaired
1.469 + * trail surrogate, then that itself
1.470 + * will be returned as the code point.
1.471 + *
1.472 + * @param s const UChar * string
1.473 + * @param start starting string offset (usually 0)
1.474 + * @param i string offset, start<=i
1.475 + * @param c output UChar32 variable
1.476 + * @see U16_PREV_UNSAFE
1.477 + * @stable ICU 2.4
1.478 + */
1.479 +#define U16_PREV(s, start, i, c) { \
1.480 + (c)=(s)[--(i)]; \
1.481 + if(U16_IS_TRAIL(c)) { \
1.482 + uint16_t __c2; \
1.483 + if((i)>(start) && U16_IS_LEAD(__c2=(s)[(i)-1])) { \
1.484 + --(i); \
1.485 + (c)=U16_GET_SUPPLEMENTARY(__c2, (c)); \
1.486 + } \
1.487 + } \
1.488 +}
1.489 +
1.490 +/**
1.491 + * Move the string offset from one code point boundary to the previous one.
1.492 + * (Pre-decrementing backward iteration.)
1.493 + * The input offset may be the same as the string length.
1.494 + * "Unsafe" macro, assumes well-formed UTF-16.
1.495 + *
1.496 + * @param s const UChar * string
1.497 + * @param i string offset
1.498 + * @see U16_BACK_1
1.499 + * @stable ICU 2.4
1.500 + */
1.501 +#define U16_BACK_1_UNSAFE(s, i) { \
1.502 + if(U16_IS_TRAIL((s)[--(i)])) { \
1.503 + --(i); \
1.504 + } \
1.505 +}
1.506 +
1.507 +/**
1.508 + * Move the string offset from one code point boundary to the previous one.
1.509 + * (Pre-decrementing backward iteration.)
1.510 + * The input offset may be the same as the string length.
1.511 + * "Safe" macro, handles unpaired surrogates and checks for string boundaries.
1.512 + *
1.513 + * @param s const UChar * string
1.514 + * @param start starting string offset (usually 0)
1.515 + * @param i string offset, start<=i
1.516 + * @see U16_BACK_1_UNSAFE
1.517 + * @stable ICU 2.4
1.518 + */
1.519 +#define U16_BACK_1(s, start, i) { \
1.520 + if(U16_IS_TRAIL((s)[--(i)]) && (i)>(start) && U16_IS_LEAD((s)[(i)-1])) { \
1.521 + --(i); \
1.522 + } \
1.523 +}
1.524 +
1.525 +/**
1.526 + * Move the string offset from one code point boundary to the n-th one before it,
1.527 + * i.e., move backward by n code points.
1.528 + * (Pre-decrementing backward iteration.)
1.529 + * The input offset may be the same as the string length.
1.530 + * "Unsafe" macro, assumes well-formed UTF-16.
1.531 + *
1.532 + * @param s const UChar * string
1.533 + * @param i string offset
1.534 + * @param n number of code points to skip
1.535 + * @see U16_BACK_N
1.536 + * @stable ICU 2.4
1.537 + */
1.538 +#define U16_BACK_N_UNSAFE(s, i, n) { \
1.539 + int32_t __N=(n); \
1.540 + while(__N>0) { \
1.541 + U16_BACK_1_UNSAFE(s, i); \
1.542 + --__N; \
1.543 + } \
1.544 +}
1.545 +
1.546 +/**
1.547 + * Move the string offset from one code point boundary to the n-th one before it,
1.548 + * i.e., move backward by n code points.
1.549 + * (Pre-decrementing backward iteration.)
1.550 + * The input offset may be the same as the string length.
1.551 + * "Safe" macro, handles unpaired surrogates and checks for string boundaries.
1.552 + *
1.553 + * @param s const UChar * string
1.554 + * @param start start of string
1.555 + * @param i string offset, i<length
1.556 + * @param n number of code points to skip
1.557 + * @see U16_BACK_N_UNSAFE
1.558 + * @stable ICU 2.4
1.559 + */
1.560 +#define U16_BACK_N(s, start, i, n) { \
1.561 + int32_t __N=(n); \
1.562 + while(__N>0 && (i)>(start)) { \
1.563 + U16_BACK_1(s, start, i); \
1.564 + --__N; \
1.565 + } \
1.566 +}
1.567 +
1.568 +/**
1.569 + * Adjust a random-access offset to a code point boundary after a code point.
1.570 + * If the offset is behind the lead surrogate of a surrogate pair,
1.571 + * then the offset is incremented.
1.572 + * Otherwise, it is not modified.
1.573 + * The input offset may be the same as the string length.
1.574 + * "Unsafe" macro, assumes well-formed UTF-16.
1.575 + *
1.576 + * @param s const UChar * string
1.577 + * @param i string offset
1.578 + * @see U16_SET_CP_LIMIT
1.579 + * @stable ICU 2.4
1.580 + */
1.581 +#define U16_SET_CP_LIMIT_UNSAFE(s, i) { \
1.582 + if(U16_IS_LEAD((s)[(i)-1])) { \
1.583 + ++(i); \
1.584 + } \
1.585 +}
1.586 +
1.587 +/**
1.588 + * Adjust a random-access offset to a code point boundary after a code point.
1.589 + * If the offset is behind the lead surrogate of a surrogate pair,
1.590 + * then the offset is incremented.
1.591 + * Otherwise, it is not modified.
1.592 + * The input offset may be the same as the string length.
1.593 + * "Safe" macro, handles unpaired surrogates and checks for string boundaries.
1.594 + *
1.595 + * @param s const UChar * string
1.596 + * @param start starting string offset (usually 0)
1.597 + * @param i string offset, start<=i<=length
1.598 + * @param length string length
1.599 + * @see U16_SET_CP_LIMIT_UNSAFE
1.600 + * @stable ICU 2.4
1.601 + */
1.602 +#define U16_SET_CP_LIMIT(s, start, i, length) { \
1.603 + if((start)<(i) && (i)<(length) && U16_IS_LEAD((s)[(i)-1]) && U16_IS_TRAIL((s)[i])) { \
1.604 + ++(i); \
1.605 + } \
1.606 +}
1.607 +
1.608 +#endif