1 // © 2016 and later: Unicode, Inc. and others. 2 // License & terms of use: http://www.unicode.org/copyright.html 3 /* 4 ********************************************************************** 5 * Copyright (C) 1998-2014, International Business Machines 6 * Corporation and others. All Rights Reserved. 7 ********************************************************************** 8 * 9 * File ustring.h 10 * 11 * Modification History: 12 * 13 * Date Name Description 14 * 12/07/98 bertrand Creation. 15 ****************************************************************************** 16 */ 17 18 #ifndef USTRING_H 19 #define USTRING_H 20 21 #include "unicode/utypes.h" 22 #include "unicode/putil.h" 23 24 /** 25 * \def UBRK_TYPEDEF_UBREAK_ITERATOR 26 * \xrefitem internal "Internal" "Internal List" Do not use. This API is for internal use only. 27 */ 28 29 #ifndef UBRK_TYPEDEF_UBREAK_ITERATOR 30 # define UBRK_TYPEDEF_UBREAK_ITERATOR 31 /** Simple declaration for u_strToTitle() to avoid including unicode/ubrk.h. \xrefitem stable "Stable" "Stable List" ICU 2.1*/ 32 typedef struct UBreakIterator UBreakIterator; 33 #endif 34 35 /** 36 * @addtogroup icu4c ICU4C 37 * @{ 38 * \file 39 * \brief C API: Unicode string handling functions 40 * 41 * These C API functions provide general Unicode string handling. 42 * 43 * Some functions are equivalent in name, signature, and behavior to the ANSI C <string.h> 44 * functions. (For example, they do not check for bad arguments like NULL string pointers.) 45 * In some cases, only the thread-safe variant of such a function is implemented here 46 * (see u_strtok_r()). 47 * 48 * Other functions provide more Unicode-specific functionality like locale-specific 49 * upper/lower-casing and string comparison in code point order. 50 * 51 * ICU uses 16-bit Unicode (UTF-16) in the form of arrays of UChar code units. 52 * UTF-16 encodes each Unicode code point with either one or two UChar code units. 53 * (This is the default form of Unicode, and a forward-compatible extension of the original, 54 * fixed-width form that was known as UCS-2. UTF-16 superseded UCS-2 with Unicode 2.0 55 * in 1996.) 56 * 57 * Some APIs accept a 32-bit UChar32 value for a single code point. 58 * 59 * ICU also handles 16-bit Unicode text with unpaired surrogates. 60 * Such text is not well-formed UTF-16. 61 * Code-point-related functions treat unpaired surrogates as surrogate code points, 62 * i.e., as separate units. 63 * 64 * Although UTF-16 is a variable-width encoding form (like some legacy multi-byte encodings), 65 * it is much more efficient even for random access because the code unit values 66 * for single-unit characters vs. lead units vs. trail units are completely disjoint. 67 * This means that it is easy to determine character (code point) boundaries from 68 * random offsets in the string. 69 * 70 * Unicode (UTF-16) string processing is optimized for the single-unit case. 71 * Although it is important to support supplementary characters 72 * (which use pairs of lead/trail code units called "surrogates"), 73 * their occurrence is rare. Almost all characters in modern use require only 74 * a single UChar code unit (i.e., their code point values are <=0xffff). 75 * 76 * For more details see the User Guide Strings chapter (https://unicode-org.github.io/icu/userguide/strings/). 77 * For a discussion of the handling of unpaired surrogates see also 78 * Jitterbug 2145 and its icu mailing list proposal on 2002-sep-18. 79 */ 80 81 /** 82 * Determine the length of an array of UChar. 83 * 84 * @param s The array of UChars, NULL (U+0000) terminated. 85 * @return The number of UChars in <code>chars</code>, minus the terminator. 86 * \xrefitem stable "Stable" "Stable List" ICU 2.0 87 */ 88 U_CAPI int32_t U_EXPORT2 89 u_strlen(const UChar *s) __INTRODUCED_IN(31); 90 91 92 93 /** 94 * Count Unicode code points in the length UChar code units of the string. 95 * A code point may occupy either one or two UChar code units. 96 * Counting code points involves reading all code units. 97 * 98 * This functions is basically the inverse of the U16_FWD_N() macro (see utf.h). 99 * 100 * @param s The input string. 101 * @param length The number of UChar code units to be checked, or -1 to count all 102 * code points before the first NUL (U+0000). 103 * @return The number of code points in the specified code units. 104 * \xrefitem stable "Stable" "Stable List" ICU 2.0 105 */ 106 U_CAPI int32_t U_EXPORT2 107 u_countChar32(const UChar *s, int32_t length) __INTRODUCED_IN(31); 108 109 110 111 /** 112 * Check if the string contains more Unicode code points than a certain number. 113 * This is more efficient than counting all code points in the entire string 114 * and comparing that number with a threshold. 115 * This function may not need to scan the string at all if the length is known 116 * (not -1 for NUL-termination) and falls within a certain range, and 117 * never needs to count more than 'number+1' code points. 118 * Logically equivalent to (u_countChar32(s, length)>number). 119 * A Unicode code point may occupy either one or two UChar code units. 120 * 121 * @param s The input string. 122 * @param length The length of the string, or -1 if it is NUL-terminated. 123 * @param number The number of code points in the string is compared against 124 * the 'number' parameter. 125 * @return Boolean value for whether the string contains more Unicode code points 126 * than 'number'. Same as (u_countChar32(s, length)>number). 127 * \xrefitem stable "Stable" "Stable List" ICU 2.4 128 */ 129 U_CAPI UBool U_EXPORT2 130 u_strHasMoreChar32Than(const UChar *s, int32_t length, int32_t number) __INTRODUCED_IN(31); 131 132 133 134 /** 135 * Concatenate two ustrings. Appends a copy of <code>src</code>, 136 * including the null terminator, to <code>dst</code>. The initial copied 137 * character from <code>src</code> overwrites the null terminator in <code>dst</code>. 138 * 139 * @param dst The destination string. 140 * @param src The source string. 141 * @return A pointer to <code>dst</code>. 142 * \xrefitem stable "Stable" "Stable List" ICU 2.0 143 */ 144 U_CAPI UChar* U_EXPORT2 145 u_strcat(UChar *dst, 146 const UChar *src) __INTRODUCED_IN(31); 147 148 149 150 /** 151 * Concatenate two ustrings. 152 * Appends at most <code>n</code> characters from <code>src</code> to <code>dst</code>. 153 * Adds a terminating NUL. 154 * If src is too long, then only <code>n-1</code> characters will be copied 155 * before the terminating NUL. 156 * If <code>n<=0</code> then dst is not modified. 157 * 158 * @param dst The destination string. 159 * @param src The source string (can be NULL/invalid if n<=0). 160 * @param n The maximum number of characters to append; no-op if <=0. 161 * @return A pointer to <code>dst</code>. 162 * \xrefitem stable "Stable" "Stable List" ICU 2.0 163 */ 164 U_CAPI UChar* U_EXPORT2 165 u_strncat(UChar *dst, 166 const UChar *src, 167 int32_t n) __INTRODUCED_IN(31); 168 169 170 171 /** 172 * Find the first occurrence of a substring in a string. 173 * The substring is found at code point boundaries. 174 * That means that if the substring begins with 175 * a trail surrogate or ends with a lead surrogate, 176 * then it is found only if these surrogates stand alone in the text. 177 * Otherwise, the substring edge units would be matched against 178 * halves of surrogate pairs. 179 * 180 * @param s The string to search (NUL-terminated). 181 * @param substring The substring to find (NUL-terminated). 182 * @return A pointer to the first occurrence of <code>substring</code> in <code>s</code>, 183 * or <code>s</code> itself if the <code>substring</code> is empty, 184 * or <code>NULL</code> if <code>substring</code> is not in <code>s</code>. 185 * \xrefitem stable "Stable" "Stable List" ICU 2.0 186 * 187 * @see u_strrstr 188 * @see u_strFindFirst 189 * @see u_strFindLast 190 */ 191 U_CAPI UChar * U_EXPORT2 192 u_strstr(const UChar *s, const UChar *substring) __INTRODUCED_IN(31); 193 194 195 196 /** 197 * Find the first occurrence of a substring in a string. 198 * The substring is found at code point boundaries. 199 * That means that if the substring begins with 200 * a trail surrogate or ends with a lead surrogate, 201 * then it is found only if these surrogates stand alone in the text. 202 * Otherwise, the substring edge units would be matched against 203 * halves of surrogate pairs. 204 * 205 * @param s The string to search. 206 * @param length The length of s (number of UChars), or -1 if it is NUL-terminated. 207 * @param substring The substring to find (NUL-terminated). 208 * @param subLength The length of substring (number of UChars), or -1 if it is NUL-terminated. 209 * @return A pointer to the first occurrence of <code>substring</code> in <code>s</code>, 210 * or <code>s</code> itself if the <code>substring</code> is empty, 211 * or <code>NULL</code> if <code>substring</code> is not in <code>s</code>. 212 * \xrefitem stable "Stable" "Stable List" ICU 2.4 213 * 214 * @see u_strstr 215 * @see u_strFindLast 216 */ 217 U_CAPI UChar * U_EXPORT2 218 u_strFindFirst(const UChar *s, int32_t length, const UChar *substring, int32_t subLength) __INTRODUCED_IN(31); 219 220 221 222 /** 223 * Find the first occurrence of a BMP code point in a string. 224 * A surrogate code point is found only if its match in the text is not 225 * part of a surrogate pair. 226 * A NUL character is found at the string terminator. 227 * 228 * @param s The string to search (NUL-terminated). 229 * @param c The BMP code point to find. 230 * @return A pointer to the first occurrence of <code>c</code> in <code>s</code> 231 * or <code>NULL</code> if <code>c</code> is not in <code>s</code>. 232 * \xrefitem stable "Stable" "Stable List" ICU 2.0 233 * 234 * @see u_strchr32 235 * @see u_memchr 236 * @see u_strstr 237 * @see u_strFindFirst 238 */ 239 U_CAPI UChar * U_EXPORT2 240 u_strchr(const UChar *s, UChar c) __INTRODUCED_IN(31); 241 242 243 244 /** 245 * Find the first occurrence of a code point in a string. 246 * A surrogate code point is found only if its match in the text is not 247 * part of a surrogate pair. 248 * A NUL character is found at the string terminator. 249 * 250 * @param s The string to search (NUL-terminated). 251 * @param c The code point to find. 252 * @return A pointer to the first occurrence of <code>c</code> in <code>s</code> 253 * or <code>NULL</code> if <code>c</code> is not in <code>s</code>. 254 * \xrefitem stable "Stable" "Stable List" ICU 2.0 255 * 256 * @see u_strchr 257 * @see u_memchr32 258 * @see u_strstr 259 * @see u_strFindFirst 260 */ 261 U_CAPI UChar * U_EXPORT2 262 u_strchr32(const UChar *s, UChar32 c) __INTRODUCED_IN(31); 263 264 265 266 /** 267 * Find the last occurrence of a substring in a string. 268 * The substring is found at code point boundaries. 269 * That means that if the substring begins with 270 * a trail surrogate or ends with a lead surrogate, 271 * then it is found only if these surrogates stand alone in the text. 272 * Otherwise, the substring edge units would be matched against 273 * halves of surrogate pairs. 274 * 275 * @param s The string to search (NUL-terminated). 276 * @param substring The substring to find (NUL-terminated). 277 * @return A pointer to the last occurrence of <code>substring</code> in <code>s</code>, 278 * or <code>s</code> itself if the <code>substring</code> is empty, 279 * or <code>NULL</code> if <code>substring</code> is not in <code>s</code>. 280 * \xrefitem stable "Stable" "Stable List" ICU 2.4 281 * 282 * @see u_strstr 283 * @see u_strFindFirst 284 * @see u_strFindLast 285 */ 286 U_CAPI UChar * U_EXPORT2 287 u_strrstr(const UChar *s, const UChar *substring) __INTRODUCED_IN(31); 288 289 290 291 /** 292 * Find the last occurrence of a substring in a string. 293 * The substring is found at code point boundaries. 294 * That means that if the substring begins with 295 * a trail surrogate or ends with a lead surrogate, 296 * then it is found only if these surrogates stand alone in the text. 297 * Otherwise, the substring edge units would be matched against 298 * halves of surrogate pairs. 299 * 300 * @param s The string to search. 301 * @param length The length of s (number of UChars), or -1 if it is NUL-terminated. 302 * @param substring The substring to find (NUL-terminated). 303 * @param subLength The length of substring (number of UChars), or -1 if it is NUL-terminated. 304 * @return A pointer to the last occurrence of <code>substring</code> in <code>s</code>, 305 * or <code>s</code> itself if the <code>substring</code> is empty, 306 * or <code>NULL</code> if <code>substring</code> is not in <code>s</code>. 307 * \xrefitem stable "Stable" "Stable List" ICU 2.4 308 * 309 * @see u_strstr 310 * @see u_strFindLast 311 */ 312 U_CAPI UChar * U_EXPORT2 313 u_strFindLast(const UChar *s, int32_t length, const UChar *substring, int32_t subLength) __INTRODUCED_IN(31); 314 315 316 317 /** 318 * Find the last occurrence of a BMP code point in a string. 319 * A surrogate code point is found only if its match in the text is not 320 * part of a surrogate pair. 321 * A NUL character is found at the string terminator. 322 * 323 * @param s The string to search (NUL-terminated). 324 * @param c The BMP code point to find. 325 * @return A pointer to the last occurrence of <code>c</code> in <code>s</code> 326 * or <code>NULL</code> if <code>c</code> is not in <code>s</code>. 327 * \xrefitem stable "Stable" "Stable List" ICU 2.4 328 * 329 * @see u_strrchr32 330 * @see u_memrchr 331 * @see u_strrstr 332 * @see u_strFindLast 333 */ 334 U_CAPI UChar * U_EXPORT2 335 u_strrchr(const UChar *s, UChar c) __INTRODUCED_IN(31); 336 337 338 339 /** 340 * Find the last occurrence of a code point in a string. 341 * A surrogate code point is found only if its match in the text is not 342 * part of a surrogate pair. 343 * A NUL character is found at the string terminator. 344 * 345 * @param s The string to search (NUL-terminated). 346 * @param c The code point to find. 347 * @return A pointer to the last occurrence of <code>c</code> in <code>s</code> 348 * or <code>NULL</code> if <code>c</code> is not in <code>s</code>. 349 * \xrefitem stable "Stable" "Stable List" ICU 2.4 350 * 351 * @see u_strrchr 352 * @see u_memchr32 353 * @see u_strrstr 354 * @see u_strFindLast 355 */ 356 U_CAPI UChar * U_EXPORT2 357 u_strrchr32(const UChar *s, UChar32 c) __INTRODUCED_IN(31); 358 359 360 361 /** 362 * Locates the first occurrence in the string <code>string</code> of any of the characters 363 * in the string <code>matchSet</code>. 364 * Works just like C's strpbrk but with Unicode. 365 * 366 * @param string The string in which to search, NUL-terminated. 367 * @param matchSet A NUL-terminated string defining a set of code points 368 * for which to search in the text string. 369 * @return A pointer to the character in <code>string</code> that matches one of the 370 * characters in <code>matchSet</code>, or NULL if no such character is found. 371 * \xrefitem stable "Stable" "Stable List" ICU 2.0 372 */ 373 U_CAPI UChar * U_EXPORT2 374 u_strpbrk(const UChar *string, const UChar *matchSet) __INTRODUCED_IN(31); 375 376 377 378 /** 379 * Returns the number of consecutive characters in <code>string</code>, 380 * beginning with the first, that do not occur somewhere in <code>matchSet</code>. 381 * Works just like C's strcspn but with Unicode. 382 * 383 * @param string The string in which to search, NUL-terminated. 384 * @param matchSet A NUL-terminated string defining a set of code points 385 * for which to search in the text string. 386 * @return The number of initial characters in <code>string</code> that do not 387 * occur in <code>matchSet</code>. 388 * @see u_strspn 389 * \xrefitem stable "Stable" "Stable List" ICU 2.0 390 */ 391 U_CAPI int32_t U_EXPORT2 392 u_strcspn(const UChar *string, const UChar *matchSet) __INTRODUCED_IN(31); 393 394 395 396 /** 397 * Returns the number of consecutive characters in <code>string</code>, 398 * beginning with the first, that occur somewhere in <code>matchSet</code>. 399 * Works just like C's strspn but with Unicode. 400 * 401 * @param string The string in which to search, NUL-terminated. 402 * @param matchSet A NUL-terminated string defining a set of code points 403 * for which to search in the text string. 404 * @return The number of initial characters in <code>string</code> that do 405 * occur in <code>matchSet</code>. 406 * @see u_strcspn 407 * \xrefitem stable "Stable" "Stable List" ICU 2.0 408 */ 409 U_CAPI int32_t U_EXPORT2 410 u_strspn(const UChar *string, const UChar *matchSet) __INTRODUCED_IN(31); 411 412 413 414 /** 415 * The string tokenizer API allows an application to break a string into 416 * tokens. Unlike strtok(), the saveState (the current pointer within the 417 * original string) is maintained in saveState. In the first call, the 418 * argument src is a pointer to the string. In subsequent calls to 419 * return successive tokens of that string, src must be specified as 420 * NULL. The value saveState is set by this function to maintain the 421 * function's position within the string, and on each subsequent call 422 * you must give this argument the same variable. This function does 423 * handle surrogate pairs. This function is similar to the strtok_r() 424 * the POSIX Threads Extension (1003.1c-1995) version. 425 * 426 * @param src String containing token(s). This string will be modified. 427 * After the first call to u_strtok_r(), this argument must 428 * be NULL to get to the next token. 429 * @param delim Set of delimiter characters (Unicode code points). 430 * @param saveState The current pointer within the original string, 431 * which is set by this function. The saveState 432 * parameter should the address of a local variable of type 433 * UChar *. (i.e. defined "UChar *myLocalSaveState" and use 434 * &myLocalSaveState for this parameter). 435 * @return A pointer to the next token found in src, or NULL 436 * when there are no more tokens. 437 * \xrefitem stable "Stable" "Stable List" ICU 2.0 438 */ 439 U_CAPI UChar * U_EXPORT2 440 u_strtok_r(UChar *src, 441 const UChar *delim, 442 UChar **saveState) __INTRODUCED_IN(31); 443 444 445 446 /** 447 * Compare two Unicode strings for bitwise equality (code unit order). 448 * 449 * @param s1 A string to compare. 450 * @param s2 A string to compare. 451 * @return 0 if <code>s1</code> and <code>s2</code> are bitwise equal; a negative 452 * value if <code>s1</code> is bitwise less than <code>s2,</code>; a positive 453 * value if <code>s1</code> is bitwise greater than <code>s2</code>. 454 * \xrefitem stable "Stable" "Stable List" ICU 2.0 455 */ 456 U_CAPI int32_t U_EXPORT2 457 u_strcmp(const UChar *s1, 458 const UChar *s2) __INTRODUCED_IN(31); 459 460 461 462 /** 463 * Compare two Unicode strings in code point order. 464 * See u_strCompare for details. 465 * 466 * @param s1 A string to compare. 467 * @param s2 A string to compare. 468 * @return a negative/zero/positive integer corresponding to whether 469 * the first string is less than/equal to/greater than the second one 470 * in code point order 471 * \xrefitem stable "Stable" "Stable List" ICU 2.0 472 */ 473 U_CAPI int32_t U_EXPORT2 474 u_strcmpCodePointOrder(const UChar *s1, const UChar *s2) __INTRODUCED_IN(31); 475 476 477 478 /** 479 * Compare two Unicode strings (binary order). 480 * 481 * The comparison can be done in code unit order or in code point order. 482 * They differ only in UTF-16 when 483 * comparing supplementary code points (U+10000..U+10ffff) 484 * to BMP code points near the end of the BMP (i.e., U+e000..U+ffff). 485 * In code unit order, high BMP code points sort after supplementary code points 486 * because they are stored as pairs of surrogates which are at U+d800..U+dfff. 487 * 488 * This functions works with strings of different explicitly specified lengths 489 * unlike the ANSI C-like u_strcmp() and u_memcmp() etc. 490 * NUL-terminated strings are possible with length arguments of -1. 491 * 492 * @param s1 First source string. 493 * @param length1 Length of first source string, or -1 if NUL-terminated. 494 * 495 * @param s2 Second source string. 496 * @param length2 Length of second source string, or -1 if NUL-terminated. 497 * 498 * @param codePointOrder Choose between code unit order (false) 499 * and code point order (true). 500 * 501 * @return <0 or 0 or >0 as usual for string comparisons 502 * 503 * \xrefitem stable "Stable" "Stable List" ICU 2.2 504 */ 505 U_CAPI int32_t U_EXPORT2 506 u_strCompare(const UChar *s1, int32_t length1, 507 const UChar *s2, int32_t length2, 508 UBool codePointOrder) __INTRODUCED_IN(31); 509 510 511 512 513 514 /** 515 * Compare two strings case-insensitively using full case folding. 516 * This is equivalent to 517 * u_strCompare(u_strFoldCase(s1, options), 518 * u_strFoldCase(s2, options), 519 * (options&U_COMPARE_CODE_POINT_ORDER)!=0). 520 * 521 * The comparison can be done in UTF-16 code unit order or in code point order. 522 * They differ only when comparing supplementary code points (U+10000..U+10ffff) 523 * to BMP code points near the end of the BMP (i.e., U+e000..U+ffff). 524 * In code unit order, high BMP code points sort after supplementary code points 525 * because they are stored as pairs of surrogates which are at U+d800..U+dfff. 526 * 527 * This functions works with strings of different explicitly specified lengths 528 * unlike the ANSI C-like u_strcmp() and u_memcmp() etc. 529 * NUL-terminated strings are possible with length arguments of -1. 530 * 531 * @param s1 First source string. 532 * @param length1 Length of first source string, or -1 if NUL-terminated. 533 * 534 * @param s2 Second source string. 535 * @param length2 Length of second source string, or -1 if NUL-terminated. 536 * 537 * @param options A bit set of options: 538 * - U_FOLD_CASE_DEFAULT or 0 is used for default options: 539 * Comparison in code unit order with default case folding. 540 * 541 * - U_COMPARE_CODE_POINT_ORDER 542 * Set to choose code point order instead of code unit order 543 * (see u_strCompare for details). 544 * 545 * - U_FOLD_CASE_EXCLUDE_SPECIAL_I 546 * 547 * @param pErrorCode Must be a valid pointer to an error code value, 548 * which must not indicate a failure before the function call. 549 * 550 * @return <0 or 0 or >0 as usual for string comparisons 551 * 552 * \xrefitem stable "Stable" "Stable List" ICU 2.2 553 */ 554 U_CAPI int32_t U_EXPORT2 555 u_strCaseCompare(const UChar *s1, int32_t length1, 556 const UChar *s2, int32_t length2, 557 uint32_t options, 558 UErrorCode *pErrorCode) __INTRODUCED_IN(31); 559 560 561 562 /** 563 * Compare two ustrings for bitwise equality. 564 * Compares at most <code>n</code> characters. 565 * 566 * @param ucs1 A string to compare (can be NULL/invalid if n<=0). 567 * @param ucs2 A string to compare (can be NULL/invalid if n<=0). 568 * @param n The maximum number of characters to compare; always returns 0 if n<=0. 569 * @return 0 if <code>s1</code> and <code>s2</code> are bitwise equal; a negative 570 * value if <code>s1</code> is bitwise less than <code>s2</code>; a positive 571 * value if <code>s1</code> is bitwise greater than <code>s2</code>. 572 * \xrefitem stable "Stable" "Stable List" ICU 2.0 573 */ 574 U_CAPI int32_t U_EXPORT2 575 u_strncmp(const UChar *ucs1, 576 const UChar *ucs2, 577 int32_t n) __INTRODUCED_IN(31); 578 579 580 581 /** 582 * Compare two Unicode strings in code point order. 583 * This is different in UTF-16 from u_strncmp() if supplementary characters are present. 584 * For details, see u_strCompare(). 585 * 586 * @param s1 A string to compare. 587 * @param s2 A string to compare. 588 * @param n The maximum number of characters to compare. 589 * @return a negative/zero/positive integer corresponding to whether 590 * the first string is less than/equal to/greater than the second one 591 * in code point order 592 * \xrefitem stable "Stable" "Stable List" ICU 2.0 593 */ 594 U_CAPI int32_t U_EXPORT2 595 u_strncmpCodePointOrder(const UChar *s1, const UChar *s2, int32_t n) __INTRODUCED_IN(31); 596 597 598 599 /** 600 * Compare two strings case-insensitively using full case folding. 601 * This is equivalent to u_strcmp(u_strFoldCase(s1, options), u_strFoldCase(s2, options)). 602 * 603 * @param s1 A string to compare. 604 * @param s2 A string to compare. 605 * @param options A bit set of options: 606 * - U_FOLD_CASE_DEFAULT or 0 is used for default options: 607 * Comparison in code unit order with default case folding. 608 * 609 * - U_COMPARE_CODE_POINT_ORDER 610 * Set to choose code point order instead of code unit order 611 * (see u_strCompare for details). 612 * 613 * - U_FOLD_CASE_EXCLUDE_SPECIAL_I 614 * 615 * @return A negative, zero, or positive integer indicating the comparison result. 616 * \xrefitem stable "Stable" "Stable List" ICU 2.0 617 */ 618 U_CAPI int32_t U_EXPORT2 619 u_strcasecmp(const UChar *s1, const UChar *s2, uint32_t options) __INTRODUCED_IN(31); 620 621 622 623 /** 624 * Compare two strings case-insensitively using full case folding. 625 * This is equivalent to u_strcmp(u_strFoldCase(s1, at most n, options), 626 * u_strFoldCase(s2, at most n, options)). 627 * 628 * @param s1 A string to compare. 629 * @param s2 A string to compare. 630 * @param n The maximum number of characters each string to case-fold and then compare. 631 * @param options A bit set of options: 632 * - U_FOLD_CASE_DEFAULT or 0 is used for default options: 633 * Comparison in code unit order with default case folding. 634 * 635 * - U_COMPARE_CODE_POINT_ORDER 636 * Set to choose code point order instead of code unit order 637 * (see u_strCompare for details). 638 * 639 * - U_FOLD_CASE_EXCLUDE_SPECIAL_I 640 * 641 * @return A negative, zero, or positive integer indicating the comparison result. 642 * \xrefitem stable "Stable" "Stable List" ICU 2.0 643 */ 644 U_CAPI int32_t U_EXPORT2 645 u_strncasecmp(const UChar *s1, const UChar *s2, int32_t n, uint32_t options) __INTRODUCED_IN(31); 646 647 648 649 /** 650 * Compare two strings case-insensitively using full case folding. 651 * This is equivalent to u_strcmp(u_strFoldCase(s1, n, options), 652 * u_strFoldCase(s2, n, options)). 653 * 654 * @param s1 A string to compare. 655 * @param s2 A string to compare. 656 * @param length The number of characters in each string to case-fold and then compare. 657 * @param options A bit set of options: 658 * - U_FOLD_CASE_DEFAULT or 0 is used for default options: 659 * Comparison in code unit order with default case folding. 660 * 661 * - U_COMPARE_CODE_POINT_ORDER 662 * Set to choose code point order instead of code unit order 663 * (see u_strCompare for details). 664 * 665 * - U_FOLD_CASE_EXCLUDE_SPECIAL_I 666 * 667 * @return A negative, zero, or positive integer indicating the comparison result. 668 * \xrefitem stable "Stable" "Stable List" ICU 2.0 669 */ 670 U_CAPI int32_t U_EXPORT2 671 u_memcasecmp(const UChar *s1, const UChar *s2, int32_t length, uint32_t options) __INTRODUCED_IN(31); 672 673 674 675 /** 676 * Copy a ustring. Adds a null terminator. 677 * 678 * @param dst The destination string. 679 * @param src The source string. 680 * @return A pointer to <code>dst</code>. 681 * \xrefitem stable "Stable" "Stable List" ICU 2.0 682 */ 683 U_CAPI UChar* U_EXPORT2 684 u_strcpy(UChar *dst, 685 const UChar *src) __INTRODUCED_IN(31); 686 687 688 689 /** 690 * Copy a ustring. 691 * Copies at most <code>n</code> characters. The result will be null terminated 692 * if the length of <code>src</code> is less than <code>n</code>. 693 * 694 * @param dst The destination string. 695 * @param src The source string (can be NULL/invalid if n<=0). 696 * @param n The maximum number of characters to copy; no-op if <=0. 697 * @return A pointer to <code>dst</code>. 698 * \xrefitem stable "Stable" "Stable List" ICU 2.0 699 */ 700 U_CAPI UChar* U_EXPORT2 701 u_strncpy(UChar *dst, 702 const UChar *src, 703 int32_t n) __INTRODUCED_IN(31); 704 705 706 707 #if !UCONFIG_NO_CONVERSION 708 709 710 711 712 713 714 715 716 717 #endif 718 719 /** 720 * Synonym for memcpy(), but with UChars only. 721 * @param dest The destination string 722 * @param src The source string (can be NULL/invalid if count<=0) 723 * @param count The number of characters to copy; no-op if <=0 724 * @return A pointer to <code>dest</code> 725 * \xrefitem stable "Stable" "Stable List" ICU 2.0 726 */ 727 U_CAPI UChar* U_EXPORT2 728 u_memcpy(UChar *dest, const UChar *src, int32_t count) __INTRODUCED_IN(31); 729 730 731 732 /** 733 * Synonym for memmove(), but with UChars only. 734 * @param dest The destination string 735 * @param src The source string (can be NULL/invalid if count<=0) 736 * @param count The number of characters to move; no-op if <=0 737 * @return A pointer to <code>dest</code> 738 * \xrefitem stable "Stable" "Stable List" ICU 2.0 739 */ 740 U_CAPI UChar* U_EXPORT2 741 u_memmove(UChar *dest, const UChar *src, int32_t count) __INTRODUCED_IN(31); 742 743 744 745 /** 746 * Initialize <code>count</code> characters of <code>dest</code> to <code>c</code>. 747 * 748 * @param dest The destination string. 749 * @param c The character to initialize the string. 750 * @param count The maximum number of characters to set. 751 * @return A pointer to <code>dest</code>. 752 * \xrefitem stable "Stable" "Stable List" ICU 2.0 753 */ 754 U_CAPI UChar* U_EXPORT2 755 u_memset(UChar *dest, UChar c, int32_t count) __INTRODUCED_IN(31); 756 757 758 759 /** 760 * Compare the first <code>count</code> UChars of each buffer. 761 * 762 * @param buf1 The first string to compare. 763 * @param buf2 The second string to compare. 764 * @param count The maximum number of UChars to compare. 765 * @return When buf1 < buf2, a negative number is returned. 766 * When buf1 == buf2, 0 is returned. 767 * When buf1 > buf2, a positive number is returned. 768 * \xrefitem stable "Stable" "Stable List" ICU 2.0 769 */ 770 U_CAPI int32_t U_EXPORT2 771 u_memcmp(const UChar *buf1, const UChar *buf2, int32_t count) __INTRODUCED_IN(31); 772 773 774 775 /** 776 * Compare two Unicode strings in code point order. 777 * This is different in UTF-16 from u_memcmp() if supplementary characters are present. 778 * For details, see u_strCompare(). 779 * 780 * @param s1 A string to compare. 781 * @param s2 A string to compare. 782 * @param count The maximum number of characters to compare. 783 * @return a negative/zero/positive integer corresponding to whether 784 * the first string is less than/equal to/greater than the second one 785 * in code point order 786 * \xrefitem stable "Stable" "Stable List" ICU 2.0 787 */ 788 U_CAPI int32_t U_EXPORT2 789 u_memcmpCodePointOrder(const UChar *s1, const UChar *s2, int32_t count) __INTRODUCED_IN(31); 790 791 792 793 /** 794 * Find the first occurrence of a BMP code point in a string. 795 * A surrogate code point is found only if its match in the text is not 796 * part of a surrogate pair. 797 * A NUL character is found at the string terminator. 798 * 799 * @param s The string to search (contains <code>count</code> UChars). 800 * @param c The BMP code point to find. 801 * @param count The length of the string. 802 * @return A pointer to the first occurrence of <code>c</code> in <code>s</code> 803 * or <code>NULL</code> if <code>c</code> is not in <code>s</code>. 804 * \xrefitem stable "Stable" "Stable List" ICU 2.0 805 * 806 * @see u_strchr 807 * @see u_memchr32 808 * @see u_strFindFirst 809 */ 810 U_CAPI UChar* U_EXPORT2 811 u_memchr(const UChar *s, UChar c, int32_t count) __INTRODUCED_IN(31); 812 813 814 815 /** 816 * Find the first occurrence of a code point in a string. 817 * A surrogate code point is found only if its match in the text is not 818 * part of a surrogate pair. 819 * A NUL character is found at the string terminator. 820 * 821 * @param s The string to search (contains <code>count</code> UChars). 822 * @param c The code point to find. 823 * @param count The length of the string. 824 * @return A pointer to the first occurrence of <code>c</code> in <code>s</code> 825 * or <code>NULL</code> if <code>c</code> is not in <code>s</code>. 826 * \xrefitem stable "Stable" "Stable List" ICU 2.0 827 * 828 * @see u_strchr32 829 * @see u_memchr 830 * @see u_strFindFirst 831 */ 832 U_CAPI UChar* U_EXPORT2 833 u_memchr32(const UChar *s, UChar32 c, int32_t count) __INTRODUCED_IN(31); 834 835 836 837 /** 838 * Find the last occurrence of a BMP code point in a string. 839 * A surrogate code point is found only if its match in the text is not 840 * part of a surrogate pair. 841 * A NUL character is found at the string terminator. 842 * 843 * @param s The string to search (contains <code>count</code> UChars). 844 * @param c The BMP code point to find. 845 * @param count The length of the string. 846 * @return A pointer to the last occurrence of <code>c</code> in <code>s</code> 847 * or <code>NULL</code> if <code>c</code> is not in <code>s</code>. 848 * \xrefitem stable "Stable" "Stable List" ICU 2.4 849 * 850 * @see u_strrchr 851 * @see u_memrchr32 852 * @see u_strFindLast 853 */ 854 U_CAPI UChar* U_EXPORT2 855 u_memrchr(const UChar *s, UChar c, int32_t count) __INTRODUCED_IN(31); 856 857 858 859 /** 860 * Find the last occurrence of a code point in a string. 861 * A surrogate code point is found only if its match in the text is not 862 * part of a surrogate pair. 863 * A NUL character is found at the string terminator. 864 * 865 * @param s The string to search (contains <code>count</code> UChars). 866 * @param c The code point to find. 867 * @param count The length of the string. 868 * @return A pointer to the last occurrence of <code>c</code> in <code>s</code> 869 * or <code>NULL</code> if <code>c</code> is not in <code>s</code>. 870 * \xrefitem stable "Stable" "Stable List" ICU 2.4 871 * 872 * @see u_strrchr32 873 * @see u_memrchr 874 * @see u_strFindLast 875 */ 876 U_CAPI UChar* U_EXPORT2 877 u_memrchr32(const UChar *s, UChar32 c, int32_t count) __INTRODUCED_IN(31); 878 879 880 881 /** 882 * Unicode String literals in C. 883 * We need one macro to declare a variable for the string 884 * and to statically preinitialize it if possible, 885 * and a second macro to dynamically initialize such a string variable if necessary. 886 * 887 * The macros are defined for maximum performance. 888 * They work only for strings that contain "invariant characters", i.e., 889 * only latin letters, digits, and some punctuation. 890 * See utypes.h for details. 891 * 892 * A pair of macros for a single string must be used with the same 893 * parameters. 894 * The string parameter must be a C string literal. 895 * The length of the string, not including the terminating 896 * `NUL`, must be specified as a constant. 897 * The U_STRING_DECL macro should be invoked exactly once for one 898 * such string variable before it is used. 899 * 900 * Usage: 901 * 902 * U_STRING_DECL(ustringVar1, "Quick-Fox 2", 11); 903 * U_STRING_DECL(ustringVar2, "jumps 5%", 8); 904 * static UBool didInit=false; 905 * 906 * int32_t function() { 907 * if(!didInit) { 908 * U_STRING_INIT(ustringVar1, "Quick-Fox 2", 11); 909 * U_STRING_INIT(ustringVar2, "jumps 5%", 8); 910 * didInit=true; 911 * } 912 * return u_strcmp(ustringVar1, ustringVar2); 913 * } 914 * 915 * Note that the macros will NOT consistently work if their argument is another #`define`. 916 * The following will not work on all platforms, don't use it. 917 * 918 * #define GLUCK "Mr. Gluck" 919 * U_STRING_DECL(var, GLUCK, 9) 920 * U_STRING_INIT(var, GLUCK, 9) 921 * 922 * Instead, use the string literal "Mr. Gluck" as the argument to both macro 923 * calls. 924 * 925 * 926 * \xrefitem stable "Stable" "Stable List" ICU 2.0 927 */ 928 #if defined(U_DECLARE_UTF16) 929 # define U_STRING_DECL(var, cs, length) static const UChar *var=(const UChar *)U_DECLARE_UTF16(cs) 930 /**\xrefitem stable "Stable" "Stable List" ICU 2.0 */ 931 # define U_STRING_INIT(var, cs, length) 932 #elif U_SIZEOF_WCHAR_T==U_SIZEOF_UCHAR && (U_CHARSET_FAMILY==U_ASCII_FAMILY || defined(U_WCHAR_IS_UTF16)) 933 # define U_STRING_DECL(var, cs, length) static const UChar var[(length)+1]=L ## cs 934 /**\xrefitem stable "Stable" "Stable List" ICU 2.0 */ 935 # define U_STRING_INIT(var, cs, length) 936 #else 937 # define U_STRING_DECL(var, cs, length) static UChar var[(length)+1] 938 /**\xrefitem stable "Stable" "Stable List" ICU 2.0 */ 939 # define U_STRING_INIT(var, cs, length) u_charsToUChars(cs, var, length+1) 940 #endif 941 942 943 944 U_CDECL_BEGIN 945 /** 946 * Callback function for u_unescapeAt() that returns a character of 947 * the source text given an offset and a context pointer. The context 948 * pointer will be whatever is passed into u_unescapeAt(). 949 * 950 * @param offset pointer to the offset that will be passed to u_unescapeAt(). 951 * @param context an opaque pointer passed directly into u_unescapeAt() 952 * @return the character represented by the escape sequence at 953 * offset 954 * @see u_unescapeAt 955 * \xrefitem stable "Stable" "Stable List" ICU 2.0 956 */ 957 typedef UChar (U_CALLCONV *UNESCAPE_CHAR_AT)(int32_t offset, void *context); 958 U_CDECL_END 959 960 961 962 /** 963 * Uppercase the characters in a string. 964 * Casing is locale-dependent and context-sensitive. 965 * The result may be longer or shorter than the original. 966 * The source string and the destination buffer are allowed to overlap. 967 * 968 * @param dest A buffer for the result string. The result will be zero-terminated if 969 * the buffer is large enough. 970 * @param destCapacity The size of the buffer (number of UChars). If it is 0, then 971 * dest may be NULL and the function will only return the length of the result 972 * without writing any of the result string. 973 * @param src The original string 974 * @param srcLength The length of the original string. If -1, then src must be zero-terminated. 975 * @param locale The locale to consider, or "" for the root locale or NULL for the default locale. 976 * @param pErrorCode Must be a valid pointer to an error code value, 977 * which must not indicate a failure before the function call. 978 * @return The length of the result string. It may be greater than destCapacity. In that case, 979 * only some of the result was written to the destination buffer. 980 * \xrefitem stable "Stable" "Stable List" ICU 2.0 981 */ 982 U_CAPI int32_t U_EXPORT2 983 u_strToUpper(UChar *dest, int32_t destCapacity, 984 const UChar *src, int32_t srcLength, 985 const char *locale, 986 UErrorCode *pErrorCode) __INTRODUCED_IN(31); 987 988 989 990 /** 991 * Lowercase the characters in a string. 992 * Casing is locale-dependent and context-sensitive. 993 * The result may be longer or shorter than the original. 994 * The source string and the destination buffer are allowed to overlap. 995 * 996 * @param dest A buffer for the result string. The result will be zero-terminated if 997 * the buffer is large enough. 998 * @param destCapacity The size of the buffer (number of UChars). If it is 0, then 999 * dest may be NULL and the function will only return the length of the result 1000 * without writing any of the result string. 1001 * @param src The original string 1002 * @param srcLength The length of the original string. If -1, then src must be zero-terminated. 1003 * @param locale The locale to consider, or "" for the root locale or NULL for the default locale. 1004 * @param pErrorCode Must be a valid pointer to an error code value, 1005 * which must not indicate a failure before the function call. 1006 * @return The length of the result string. It may be greater than destCapacity. In that case, 1007 * only some of the result was written to the destination buffer. 1008 * \xrefitem stable "Stable" "Stable List" ICU 2.0 1009 */ 1010 U_CAPI int32_t U_EXPORT2 1011 u_strToLower(UChar *dest, int32_t destCapacity, 1012 const UChar *src, int32_t srcLength, 1013 const char *locale, 1014 UErrorCode *pErrorCode) __INTRODUCED_IN(31); 1015 1016 1017 1018 #if !UCONFIG_NO_BREAK_ITERATION 1019 1020 /** 1021 * Titlecase a string. 1022 * Casing is locale-dependent and context-sensitive. 1023 * Titlecasing uses a break iterator to find the first characters of words 1024 * that are to be titlecased. It titlecases those characters and lowercases 1025 * all others. 1026 * 1027 * The titlecase break iterator can be provided to customize for arbitrary 1028 * styles, using rules and dictionaries beyond the standard iterators. 1029 * It may be more efficient to always provide an iterator to avoid 1030 * opening and closing one for each string. 1031 * The standard titlecase iterator for the root locale implements the 1032 * algorithm of Unicode TR 21. 1033 * 1034 * This function uses only the setText(), first() and next() methods of the 1035 * provided break iterator. 1036 * 1037 * The result may be longer or shorter than the original. 1038 * The source string and the destination buffer are allowed to overlap. 1039 * 1040 * @param dest A buffer for the result string. The result will be zero-terminated if 1041 * the buffer is large enough. 1042 * @param destCapacity The size of the buffer (number of UChars). If it is 0, then 1043 * dest may be NULL and the function will only return the length of the result 1044 * without writing any of the result string. 1045 * @param src The original string 1046 * @param srcLength The length of the original string. If -1, then src must be zero-terminated. 1047 * @param titleIter A break iterator to find the first characters of words 1048 * that are to be titlecased. 1049 * If none is provided (NULL), then a standard titlecase 1050 * break iterator is opened. 1051 * @param locale The locale to consider, or "" for the root locale or NULL for the default locale. 1052 * @param pErrorCode Must be a valid pointer to an error code value, 1053 * which must not indicate a failure before the function call. 1054 * @return The length of the result string. It may be greater than destCapacity. In that case, 1055 * only some of the result was written to the destination buffer. 1056 * \xrefitem stable "Stable" "Stable List" ICU 2.1 1057 */ 1058 U_CAPI int32_t U_EXPORT2 1059 u_strToTitle(UChar *dest, int32_t destCapacity, 1060 const UChar *src, int32_t srcLength, 1061 UBreakIterator *titleIter, 1062 const char *locale, 1063 UErrorCode *pErrorCode) __INTRODUCED_IN(31); 1064 1065 1066 1067 #endif 1068 1069 /** 1070 * Case-folds the characters in a string. 1071 * 1072 * Case-folding is locale-independent and not context-sensitive, 1073 * but there is an option for whether to include or exclude mappings for dotted I 1074 * and dotless i that are marked with 'T' in CaseFolding.txt. 1075 * 1076 * The result may be longer or shorter than the original. 1077 * The source string and the destination buffer are allowed to overlap. 1078 * 1079 * @param dest A buffer for the result string. The result will be zero-terminated if 1080 * the buffer is large enough. 1081 * @param destCapacity The size of the buffer (number of UChars). If it is 0, then 1082 * dest may be NULL and the function will only return the length of the result 1083 * without writing any of the result string. 1084 * @param src The original string 1085 * @param srcLength The length of the original string. If -1, then src must be zero-terminated. 1086 * @param options Either U_FOLD_CASE_DEFAULT or U_FOLD_CASE_EXCLUDE_SPECIAL_I 1087 * @param pErrorCode Must be a valid pointer to an error code value, 1088 * which must not indicate a failure before the function call. 1089 * @return The length of the result string. It may be greater than destCapacity. In that case, 1090 * only some of the result was written to the destination buffer. 1091 * \xrefitem stable "Stable" "Stable List" ICU 2.0 1092 */ 1093 U_CAPI int32_t U_EXPORT2 1094 u_strFoldCase(UChar *dest, int32_t destCapacity, 1095 const UChar *src, int32_t srcLength, 1096 uint32_t options, 1097 UErrorCode *pErrorCode) __INTRODUCED_IN(31); 1098 1099 1100 1101 #if defined(U_WCHAR_IS_UTF16) || defined(U_WCHAR_IS_UTF32) || !UCONFIG_NO_CONVERSION 1102 1103 1104 #endif /* defined(U_WCHAR_IS_UTF16) || defined(U_WCHAR_IS_UTF32) || !UCONFIG_NO_CONVERSION */ 1105 1106 /** 1107 * Convert a UTF-16 string to UTF-8. 1108 * If the input string is not well-formed, then the U_INVALID_CHAR_FOUND error code is set. 1109 * 1110 * @param dest A buffer for the result string. The result will be zero-terminated if 1111 * the buffer is large enough. 1112 * @param destCapacity The size of the buffer (number of chars). If it is 0, then 1113 * dest may be NULL and the function will only return the length of the 1114 * result without writing any of the result string (pre-flighting). 1115 * @param pDestLength A pointer to receive the number of units written to the destination. If 1116 * pDestLength!=NULL then *pDestLength is always set to the 1117 * number of output units corresponding to the transformation of 1118 * all the input units, even in case of a buffer overflow. 1119 * @param src The original source string 1120 * @param srcLength The length of the original string. If -1, then src must be zero-terminated. 1121 * @param pErrorCode Must be a valid pointer to an error code value, 1122 * which must not indicate a failure before the function call. 1123 * @return The pointer to destination buffer. 1124 * \xrefitem stable "Stable" "Stable List" ICU 2.0 1125 * @see u_strToUTF8WithSub 1126 * @see u_strFromUTF8 1127 */ 1128 U_CAPI char* U_EXPORT2 1129 u_strToUTF8(char *dest, 1130 int32_t destCapacity, 1131 int32_t *pDestLength, 1132 const UChar *src, 1133 int32_t srcLength, 1134 UErrorCode *pErrorCode) __INTRODUCED_IN(31); 1135 1136 1137 1138 /** 1139 * Convert a UTF-8 string to UTF-16. 1140 * If the input string is not well-formed, then the U_INVALID_CHAR_FOUND error code is set. 1141 * 1142 * @param dest A buffer for the result string. The result will be zero-terminated if 1143 * the buffer is large enough. 1144 * @param destCapacity The size of the buffer (number of UChars). If it is 0, then 1145 * dest may be NULL and the function will only return the length of the 1146 * result without writing any of the result string (pre-flighting). 1147 * @param pDestLength A pointer to receive the number of units written to the destination. If 1148 * pDestLength!=NULL then *pDestLength is always set to the 1149 * number of output units corresponding to the transformation of 1150 * all the input units, even in case of a buffer overflow. 1151 * @param src The original source string 1152 * @param srcLength The length of the original string. If -1, then src must be zero-terminated. 1153 * @param pErrorCode Must be a valid pointer to an error code value, 1154 * which must not indicate a failure before the function call. 1155 * @return The pointer to destination buffer. 1156 * \xrefitem stable "Stable" "Stable List" ICU 2.0 1157 * @see u_strFromUTF8WithSub 1158 * @see u_strFromUTF8Lenient 1159 */ 1160 U_CAPI UChar* U_EXPORT2 1161 u_strFromUTF8(UChar *dest, 1162 int32_t destCapacity, 1163 int32_t *pDestLength, 1164 const char *src, 1165 int32_t srcLength, 1166 UErrorCode *pErrorCode) __INTRODUCED_IN(31); 1167 1168 1169 1170 /** 1171 * Convert a UTF-16 string to UTF-8. 1172 * 1173 * Same as u_strToUTF8() except for the additional subchar which is output for 1174 * illegal input sequences, instead of stopping with the U_INVALID_CHAR_FOUND error code. 1175 * With subchar==U_SENTINEL, this function behaves exactly like u_strToUTF8(). 1176 * 1177 * @param dest A buffer for the result string. The result will be zero-terminated if 1178 * the buffer is large enough. 1179 * @param destCapacity The size of the buffer (number of chars). If it is 0, then 1180 * dest may be NULL and the function will only return the length of the 1181 * result without writing any of the result string (pre-flighting). 1182 * @param pDestLength A pointer to receive the number of units written to the destination. If 1183 * pDestLength!=NULL then *pDestLength is always set to the 1184 * number of output units corresponding to the transformation of 1185 * all the input units, even in case of a buffer overflow. 1186 * @param src The original source string 1187 * @param srcLength The length of the original string. If -1, then src must be zero-terminated. 1188 * @param subchar The substitution character to use in place of an illegal input sequence, 1189 * or U_SENTINEL if the function is to return with U_INVALID_CHAR_FOUND instead. 1190 * A substitution character can be any valid Unicode code point (up to U+10FFFF) 1191 * except for surrogate code points (U+D800..U+DFFF). 1192 * The recommended value is U+FFFD "REPLACEMENT CHARACTER". 1193 * @param pNumSubstitutions Output parameter receiving the number of substitutions if subchar>=0. 1194 * Set to 0 if no substitutions occur or subchar<0. 1195 * pNumSubstitutions can be NULL. 1196 * @param pErrorCode Pointer to a standard ICU error code. Its input value must 1197 * pass the U_SUCCESS() test, or else the function returns 1198 * immediately. Check for U_FAILURE() on output or use with 1199 * function chaining. (See User Guide for details.) 1200 * @return The pointer to destination buffer. 1201 * @see u_strToUTF8 1202 * @see u_strFromUTF8WithSub 1203 * \xrefitem stable "Stable" "Stable List" ICU 3.6 1204 */ 1205 U_CAPI char* U_EXPORT2 1206 u_strToUTF8WithSub(char *dest, 1207 int32_t destCapacity, 1208 int32_t *pDestLength, 1209 const UChar *src, 1210 int32_t srcLength, 1211 UChar32 subchar, int32_t *pNumSubstitutions, 1212 UErrorCode *pErrorCode) __INTRODUCED_IN(31); 1213 1214 1215 1216 /** 1217 * Convert a UTF-8 string to UTF-16. 1218 * 1219 * Same as u_strFromUTF8() except for the additional subchar which is output for 1220 * illegal input sequences, instead of stopping with the U_INVALID_CHAR_FOUND error code. 1221 * With subchar==U_SENTINEL, this function behaves exactly like u_strFromUTF8(). 1222 * 1223 * @param dest A buffer for the result string. The result will be zero-terminated if 1224 * the buffer is large enough. 1225 * @param destCapacity The size of the buffer (number of UChars). If it is 0, then 1226 * dest may be NULL and the function will only return the length of the 1227 * result without writing any of the result string (pre-flighting). 1228 * @param pDestLength A pointer to receive the number of units written to the destination. If 1229 * pDestLength!=NULL then *pDestLength is always set to the 1230 * number of output units corresponding to the transformation of 1231 * all the input units, even in case of a buffer overflow. 1232 * @param src The original source string 1233 * @param srcLength The length of the original string. If -1, then src must be zero-terminated. 1234 * @param subchar The substitution character to use in place of an illegal input sequence, 1235 * or U_SENTINEL if the function is to return with U_INVALID_CHAR_FOUND instead. 1236 * A substitution character can be any valid Unicode code point (up to U+10FFFF) 1237 * except for surrogate code points (U+D800..U+DFFF). 1238 * The recommended value is U+FFFD "REPLACEMENT CHARACTER". 1239 * @param pNumSubstitutions Output parameter receiving the number of substitutions if subchar>=0. 1240 * Set to 0 if no substitutions occur or subchar<0. 1241 * pNumSubstitutions can be NULL. 1242 * @param pErrorCode Pointer to a standard ICU error code. Its input value must 1243 * pass the U_SUCCESS() test, or else the function returns 1244 * immediately. Check for U_FAILURE() on output or use with 1245 * function chaining. (See User Guide for details.) 1246 * @return The pointer to destination buffer. 1247 * @see u_strFromUTF8 1248 * @see u_strFromUTF8Lenient 1249 * @see u_strToUTF8WithSub 1250 * \xrefitem stable "Stable" "Stable List" ICU 3.6 1251 */ 1252 U_CAPI UChar* U_EXPORT2 1253 u_strFromUTF8WithSub(UChar *dest, 1254 int32_t destCapacity, 1255 int32_t *pDestLength, 1256 const char *src, 1257 int32_t srcLength, 1258 UChar32 subchar, int32_t *pNumSubstitutions, 1259 UErrorCode *pErrorCode) __INTRODUCED_IN(31); 1260 1261 1262 1263 /** 1264 * Convert a UTF-8 string to UTF-16. 1265 * 1266 * Same as u_strFromUTF8() except that this function is designed to be very fast, 1267 * which it achieves by being lenient about malformed UTF-8 sequences. 1268 * This function is intended for use in environments where UTF-8 text is 1269 * expected to be well-formed. 1270 * 1271 * Its semantics are: 1272 * - Well-formed UTF-8 text is correctly converted to well-formed UTF-16 text. 1273 * - The function will not read beyond the input string, nor write beyond 1274 * the destCapacity. 1275 * - Malformed UTF-8 results in "garbage" 16-bit Unicode strings which may not 1276 * be well-formed UTF-16. 1277 * The function will resynchronize to valid code point boundaries 1278 * within a small number of code points after an illegal sequence. 1279 * - Non-shortest forms are not detected and will result in "spoofing" output. 1280 * 1281 * For further performance improvement, if srcLength is given (>=0), 1282 * then it must be destCapacity>=srcLength. 1283 * 1284 * There is no inverse u_strToUTF8Lenient() function because there is practically 1285 * no performance gain from not checking that a UTF-16 string is well-formed. 1286 * 1287 * @param dest A buffer for the result string. The result will be zero-terminated if 1288 * the buffer is large enough. 1289 * @param destCapacity The size of the buffer (number of UChars). If it is 0, then 1290 * dest may be NULL and the function will only return the length of the 1291 * result without writing any of the result string (pre-flighting). 1292 * Unlike for other ICU functions, if srcLength>=0 then it 1293 * must be destCapacity>=srcLength. 1294 * @param pDestLength A pointer to receive the number of units written to the destination. If 1295 * pDestLength!=NULL then *pDestLength is always set to the 1296 * number of output units corresponding to the transformation of 1297 * all the input units, even in case of a buffer overflow. 1298 * Unlike for other ICU functions, if srcLength>=0 but 1299 * destCapacity<srcLength, then *pDestLength will be set to srcLength 1300 * (and U_BUFFER_OVERFLOW_ERROR will be set) 1301 * regardless of the actual result length. 1302 * @param src The original source string 1303 * @param srcLength The length of the original string. If -1, then src must be zero-terminated. 1304 * @param pErrorCode Pointer to a standard ICU error code. Its input value must 1305 * pass the U_SUCCESS() test, or else the function returns 1306 * immediately. Check for U_FAILURE() on output or use with 1307 * function chaining. (See User Guide for details.) 1308 * @return The pointer to destination buffer. 1309 * @see u_strFromUTF8 1310 * @see u_strFromUTF8WithSub 1311 * @see u_strToUTF8WithSub 1312 * \xrefitem stable "Stable" "Stable List" ICU 3.6 1313 */ 1314 U_CAPI UChar * U_EXPORT2 1315 u_strFromUTF8Lenient(UChar *dest, 1316 int32_t destCapacity, 1317 int32_t *pDestLength, 1318 const char *src, 1319 int32_t srcLength, 1320 UErrorCode *pErrorCode) __INTRODUCED_IN(31); 1321 1322 1323 1324 /** 1325 * Convert a UTF-16 string to UTF-32. 1326 * If the input string is not well-formed, then the U_INVALID_CHAR_FOUND error code is set. 1327 * 1328 * @param dest A buffer for the result string. The result will be zero-terminated if 1329 * the buffer is large enough. 1330 * @param destCapacity The size of the buffer (number of UChar32s). If it is 0, then 1331 * dest may be NULL and the function will only return the length of the 1332 * result without writing any of the result string (pre-flighting). 1333 * @param pDestLength A pointer to receive the number of units written to the destination. If 1334 * pDestLength!=NULL then *pDestLength is always set to the 1335 * number of output units corresponding to the transformation of 1336 * all the input units, even in case of a buffer overflow. 1337 * @param src The original source string 1338 * @param srcLength The length of the original string. If -1, then src must be zero-terminated. 1339 * @param pErrorCode Must be a valid pointer to an error code value, 1340 * which must not indicate a failure before the function call. 1341 * @return The pointer to destination buffer. 1342 * @see u_strToUTF32WithSub 1343 * @see u_strFromUTF32 1344 * \xrefitem stable "Stable" "Stable List" ICU 2.0 1345 */ 1346 U_CAPI UChar32* U_EXPORT2 1347 u_strToUTF32(UChar32 *dest, 1348 int32_t destCapacity, 1349 int32_t *pDestLength, 1350 const UChar *src, 1351 int32_t srcLength, 1352 UErrorCode *pErrorCode) __INTRODUCED_IN(31); 1353 1354 1355 1356 /** 1357 * Convert a UTF-32 string to UTF-16. 1358 * If the input string is not well-formed, then the U_INVALID_CHAR_FOUND error code is set. 1359 * 1360 * @param dest A buffer for the result string. The result will be zero-terminated if 1361 * the buffer is large enough. 1362 * @param destCapacity The size of the buffer (number of UChars). If it is 0, then 1363 * dest may be NULL and the function will only return the length of the 1364 * result without writing any of the result string (pre-flighting). 1365 * @param pDestLength A pointer to receive the number of units written to the destination. If 1366 * pDestLength!=NULL then *pDestLength is always set to the 1367 * number of output units corresponding to the transformation of 1368 * all the input units, even in case of a buffer overflow. 1369 * @param src The original source string 1370 * @param srcLength The length of the original string. If -1, then src must be zero-terminated. 1371 * @param pErrorCode Must be a valid pointer to an error code value, 1372 * which must not indicate a failure before the function call. 1373 * @return The pointer to destination buffer. 1374 * @see u_strFromUTF32WithSub 1375 * @see u_strToUTF32 1376 * \xrefitem stable "Stable" "Stable List" ICU 2.0 1377 */ 1378 U_CAPI UChar* U_EXPORT2 1379 u_strFromUTF32(UChar *dest, 1380 int32_t destCapacity, 1381 int32_t *pDestLength, 1382 const UChar32 *src, 1383 int32_t srcLength, 1384 UErrorCode *pErrorCode) __INTRODUCED_IN(31); 1385 1386 1387 1388 /** 1389 * Convert a UTF-16 string to UTF-32. 1390 * 1391 * Same as u_strToUTF32() except for the additional subchar which is output for 1392 * illegal input sequences, instead of stopping with the U_INVALID_CHAR_FOUND error code. 1393 * With subchar==U_SENTINEL, this function behaves exactly like u_strToUTF32(). 1394 * 1395 * @param dest A buffer for the result string. The result will be zero-terminated if 1396 * the buffer is large enough. 1397 * @param destCapacity The size of the buffer (number of UChar32s). If it is 0, then 1398 * dest may be NULL and the function will only return the length of the 1399 * result without writing any of the result string (pre-flighting). 1400 * @param pDestLength A pointer to receive the number of units written to the destination. If 1401 * pDestLength!=NULL then *pDestLength is always set to the 1402 * number of output units corresponding to the transformation of 1403 * all the input units, even in case of a buffer overflow. 1404 * @param src The original source string 1405 * @param srcLength The length of the original string. If -1, then src must be zero-terminated. 1406 * @param subchar The substitution character to use in place of an illegal input sequence, 1407 * or U_SENTINEL if the function is to return with U_INVALID_CHAR_FOUND instead. 1408 * A substitution character can be any valid Unicode code point (up to U+10FFFF) 1409 * except for surrogate code points (U+D800..U+DFFF). 1410 * The recommended value is U+FFFD "REPLACEMENT CHARACTER". 1411 * @param pNumSubstitutions Output parameter receiving the number of substitutions if subchar>=0. 1412 * Set to 0 if no substitutions occur or subchar<0. 1413 * pNumSubstitutions can be NULL. 1414 * @param pErrorCode Pointer to a standard ICU error code. Its input value must 1415 * pass the U_SUCCESS() test, or else the function returns 1416 * immediately. Check for U_FAILURE() on output or use with 1417 * function chaining. (See User Guide for details.) 1418 * @return The pointer to destination buffer. 1419 * @see u_strToUTF32 1420 * @see u_strFromUTF32WithSub 1421 * \xrefitem stable "Stable" "Stable List" ICU 4.2 1422 */ 1423 U_CAPI UChar32* U_EXPORT2 1424 u_strToUTF32WithSub(UChar32 *dest, 1425 int32_t destCapacity, 1426 int32_t *pDestLength, 1427 const UChar *src, 1428 int32_t srcLength, 1429 UChar32 subchar, int32_t *pNumSubstitutions, 1430 UErrorCode *pErrorCode) __INTRODUCED_IN(31); 1431 1432 1433 1434 /** 1435 * Convert a UTF-32 string to UTF-16. 1436 * 1437 * Same as u_strFromUTF32() except for the additional subchar which is output for 1438 * illegal input sequences, instead of stopping with the U_INVALID_CHAR_FOUND error code. 1439 * With subchar==U_SENTINEL, this function behaves exactly like u_strFromUTF32(). 1440 * 1441 * @param dest A buffer for the result string. The result will be zero-terminated if 1442 * the buffer is large enough. 1443 * @param destCapacity The size of the buffer (number of UChars). If it is 0, then 1444 * dest may be NULL and the function will only return the length of the 1445 * result without writing any of the result string (pre-flighting). 1446 * @param pDestLength A pointer to receive the number of units written to the destination. If 1447 * pDestLength!=NULL then *pDestLength is always set to the 1448 * number of output units corresponding to the transformation of 1449 * all the input units, even in case of a buffer overflow. 1450 * @param src The original source string 1451 * @param srcLength The length of the original string. If -1, then src must be zero-terminated. 1452 * @param subchar The substitution character to use in place of an illegal input sequence, 1453 * or U_SENTINEL if the function is to return with U_INVALID_CHAR_FOUND instead. 1454 * A substitution character can be any valid Unicode code point (up to U+10FFFF) 1455 * except for surrogate code points (U+D800..U+DFFF). 1456 * The recommended value is U+FFFD "REPLACEMENT CHARACTER". 1457 * @param pNumSubstitutions Output parameter receiving the number of substitutions if subchar>=0. 1458 * Set to 0 if no substitutions occur or subchar<0. 1459 * pNumSubstitutions can be NULL. 1460 * @param pErrorCode Pointer to a standard ICU error code. Its input value must 1461 * pass the U_SUCCESS() test, or else the function returns 1462 * immediately. Check for U_FAILURE() on output or use with 1463 * function chaining. (See User Guide for details.) 1464 * @return The pointer to destination buffer. 1465 * @see u_strFromUTF32 1466 * @see u_strToUTF32WithSub 1467 * \xrefitem stable "Stable" "Stable List" ICU 4.2 1468 */ 1469 U_CAPI UChar* U_EXPORT2 1470 u_strFromUTF32WithSub(UChar *dest, 1471 int32_t destCapacity, 1472 int32_t *pDestLength, 1473 const UChar32 *src, 1474 int32_t srcLength, 1475 UChar32 subchar, int32_t *pNumSubstitutions, 1476 UErrorCode *pErrorCode) __INTRODUCED_IN(31); 1477 1478 1479 1480 1481 1482 1483 1484 #endif 1485 1486 /** @} */ // addtogroup 1487