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