jpayne@69: // © 2016 and later: Unicode, Inc. and others. jpayne@69: // License & terms of use: http://www.unicode.org/copyright.html jpayne@69: /* jpayne@69: ********************************************************************** jpayne@69: * Copyright (C) 1998-2014, International Business Machines jpayne@69: * Corporation and others. All Rights Reserved. jpayne@69: ********************************************************************** jpayne@69: * jpayne@69: * File ustring.h jpayne@69: * jpayne@69: * Modification History: jpayne@69: * jpayne@69: * Date Name Description jpayne@69: * 12/07/98 bertrand Creation. jpayne@69: ****************************************************************************** jpayne@69: */ jpayne@69: jpayne@69: #ifndef USTRING_H jpayne@69: #define USTRING_H jpayne@69: jpayne@69: #include "unicode/utypes.h" jpayne@69: #include "unicode/putil.h" jpayne@69: #include "unicode/uiter.h" jpayne@69: jpayne@69: /** jpayne@69: * \def UBRK_TYPEDEF_UBREAK_ITERATOR jpayne@69: * @internal jpayne@69: */ jpayne@69: jpayne@69: #ifndef UBRK_TYPEDEF_UBREAK_ITERATOR jpayne@69: # define UBRK_TYPEDEF_UBREAK_ITERATOR jpayne@69: /** Simple declaration for u_strToTitle() to avoid including unicode/ubrk.h. @stable ICU 2.1*/ jpayne@69: typedef struct UBreakIterator UBreakIterator; jpayne@69: #endif jpayne@69: jpayne@69: /** jpayne@69: * \file jpayne@69: * \brief C API: Unicode string handling functions jpayne@69: * jpayne@69: * These C API functions provide general Unicode string handling. jpayne@69: * jpayne@69: * Some functions are equivalent in name, signature, and behavior to the ANSI C jpayne@69: * functions. (For example, they do not check for bad arguments like NULL string pointers.) jpayne@69: * In some cases, only the thread-safe variant of such a function is implemented here jpayne@69: * (see u_strtok_r()). jpayne@69: * jpayne@69: * Other functions provide more Unicode-specific functionality like locale-specific jpayne@69: * upper/lower-casing and string comparison in code point order. jpayne@69: * jpayne@69: * ICU uses 16-bit Unicode (UTF-16) in the form of arrays of UChar code units. jpayne@69: * UTF-16 encodes each Unicode code point with either one or two UChar code units. jpayne@69: * (This is the default form of Unicode, and a forward-compatible extension of the original, jpayne@69: * fixed-width form that was known as UCS-2. UTF-16 superseded UCS-2 with Unicode 2.0 jpayne@69: * in 1996.) jpayne@69: * jpayne@69: * Some APIs accept a 32-bit UChar32 value for a single code point. jpayne@69: * jpayne@69: * ICU also handles 16-bit Unicode text with unpaired surrogates. jpayne@69: * Such text is not well-formed UTF-16. jpayne@69: * Code-point-related functions treat unpaired surrogates as surrogate code points, jpayne@69: * i.e., as separate units. jpayne@69: * jpayne@69: * Although UTF-16 is a variable-width encoding form (like some legacy multi-byte encodings), jpayne@69: * it is much more efficient even for random access because the code unit values jpayne@69: * for single-unit characters vs. lead units vs. trail units are completely disjoint. jpayne@69: * This means that it is easy to determine character (code point) boundaries from jpayne@69: * random offsets in the string. jpayne@69: * jpayne@69: * Unicode (UTF-16) string processing is optimized for the single-unit case. jpayne@69: * Although it is important to support supplementary characters jpayne@69: * (which use pairs of lead/trail code units called "surrogates"), jpayne@69: * their occurrence is rare. Almost all characters in modern use require only jpayne@69: * a single UChar code unit (i.e., their code point values are <=0xffff). jpayne@69: * jpayne@69: * For more details see the User Guide Strings chapter (http://icu-project.org/userguide/strings.html). jpayne@69: * For a discussion of the handling of unpaired surrogates see also jpayne@69: * Jitterbug 2145 and its icu mailing list proposal on 2002-sep-18. jpayne@69: */ jpayne@69: jpayne@69: /** jpayne@69: * \defgroup ustring_ustrlen String Length jpayne@69: * \ingroup ustring_strlen jpayne@69: */ jpayne@69: /*@{*/ jpayne@69: /** jpayne@69: * Determine the length of an array of UChar. jpayne@69: * jpayne@69: * @param s The array of UChars, NULL (U+0000) terminated. jpayne@69: * @return The number of UChars in chars, minus the terminator. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE int32_t U_EXPORT2 jpayne@69: u_strlen(const UChar *s); jpayne@69: /*@}*/ jpayne@69: jpayne@69: /** jpayne@69: * Count Unicode code points in the length UChar code units of the string. jpayne@69: * A code point may occupy either one or two UChar code units. jpayne@69: * Counting code points involves reading all code units. jpayne@69: * jpayne@69: * This functions is basically the inverse of the U16_FWD_N() macro (see utf.h). jpayne@69: * jpayne@69: * @param s The input string. jpayne@69: * @param length The number of UChar code units to be checked, or -1 to count all jpayne@69: * code points before the first NUL (U+0000). jpayne@69: * @return The number of code points in the specified code units. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE int32_t U_EXPORT2 jpayne@69: u_countChar32(const UChar *s, int32_t length); jpayne@69: jpayne@69: /** jpayne@69: * Check if the string contains more Unicode code points than a certain number. jpayne@69: * This is more efficient than counting all code points in the entire string jpayne@69: * and comparing that number with a threshold. jpayne@69: * This function may not need to scan the string at all if the length is known jpayne@69: * (not -1 for NUL-termination) and falls within a certain range, and jpayne@69: * never needs to count more than 'number+1' code points. jpayne@69: * Logically equivalent to (u_countChar32(s, length)>number). jpayne@69: * A Unicode code point may occupy either one or two UChar code units. jpayne@69: * jpayne@69: * @param s The input string. jpayne@69: * @param length The length of the string, or -1 if it is NUL-terminated. jpayne@69: * @param number The number of code points in the string is compared against jpayne@69: * the 'number' parameter. jpayne@69: * @return Boolean value for whether the string contains more Unicode code points jpayne@69: * than 'number'. Same as (u_countChar32(s, length)>number). jpayne@69: * @stable ICU 2.4 jpayne@69: */ jpayne@69: U_STABLE UBool U_EXPORT2 jpayne@69: u_strHasMoreChar32Than(const UChar *s, int32_t length, int32_t number); jpayne@69: jpayne@69: /** jpayne@69: * Concatenate two ustrings. Appends a copy of src, jpayne@69: * including the null terminator, to dst. The initial copied jpayne@69: * character from src overwrites the null terminator in dst. jpayne@69: * jpayne@69: * @param dst The destination string. jpayne@69: * @param src The source string. jpayne@69: * @return A pointer to dst. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE UChar* U_EXPORT2 jpayne@69: u_strcat(UChar *dst, jpayne@69: const UChar *src); jpayne@69: jpayne@69: /** jpayne@69: * Concatenate two ustrings. jpayne@69: * Appends at most n characters from src to dst. jpayne@69: * Adds a terminating NUL. jpayne@69: * If src is too long, then only n-1 characters will be copied jpayne@69: * before the terminating NUL. jpayne@69: * If n<=0 then dst is not modified. jpayne@69: * jpayne@69: * @param dst The destination string. jpayne@69: * @param src The source string (can be NULL/invalid if n<=0). jpayne@69: * @param n The maximum number of characters to append; no-op if <=0. jpayne@69: * @return A pointer to dst. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE UChar* U_EXPORT2 jpayne@69: u_strncat(UChar *dst, jpayne@69: const UChar *src, jpayne@69: int32_t n); jpayne@69: jpayne@69: /** jpayne@69: * Find the first occurrence of a substring in a string. jpayne@69: * The substring is found at code point boundaries. jpayne@69: * That means that if the substring begins with jpayne@69: * a trail surrogate or ends with a lead surrogate, jpayne@69: * then it is found only if these surrogates stand alone in the text. jpayne@69: * Otherwise, the substring edge units would be matched against jpayne@69: * halves of surrogate pairs. jpayne@69: * jpayne@69: * @param s The string to search (NUL-terminated). jpayne@69: * @param substring The substring to find (NUL-terminated). jpayne@69: * @return A pointer to the first occurrence of substring in s, jpayne@69: * or s itself if the substring is empty, jpayne@69: * or NULL if substring is not in s. jpayne@69: * @stable ICU 2.0 jpayne@69: * jpayne@69: * @see u_strrstr jpayne@69: * @see u_strFindFirst jpayne@69: * @see u_strFindLast jpayne@69: */ jpayne@69: U_STABLE UChar * U_EXPORT2 jpayne@69: u_strstr(const UChar *s, const UChar *substring); jpayne@69: jpayne@69: /** jpayne@69: * Find the first occurrence of a substring in a string. jpayne@69: * The substring is found at code point boundaries. jpayne@69: * That means that if the substring begins with jpayne@69: * a trail surrogate or ends with a lead surrogate, jpayne@69: * then it is found only if these surrogates stand alone in the text. jpayne@69: * Otherwise, the substring edge units would be matched against jpayne@69: * halves of surrogate pairs. jpayne@69: * jpayne@69: * @param s The string to search. jpayne@69: * @param length The length of s (number of UChars), or -1 if it is NUL-terminated. jpayne@69: * @param substring The substring to find (NUL-terminated). jpayne@69: * @param subLength The length of substring (number of UChars), or -1 if it is NUL-terminated. jpayne@69: * @return A pointer to the first occurrence of substring in s, jpayne@69: * or s itself if the substring is empty, jpayne@69: * or NULL if substring is not in s. jpayne@69: * @stable ICU 2.4 jpayne@69: * jpayne@69: * @see u_strstr jpayne@69: * @see u_strFindLast jpayne@69: */ jpayne@69: U_STABLE UChar * U_EXPORT2 jpayne@69: u_strFindFirst(const UChar *s, int32_t length, const UChar *substring, int32_t subLength); jpayne@69: jpayne@69: /** jpayne@69: * Find the first occurrence of a BMP code point in a string. jpayne@69: * A surrogate code point is found only if its match in the text is not jpayne@69: * part of a surrogate pair. jpayne@69: * A NUL character is found at the string terminator. jpayne@69: * jpayne@69: * @param s The string to search (NUL-terminated). jpayne@69: * @param c The BMP code point to find. jpayne@69: * @return A pointer to the first occurrence of c in s jpayne@69: * or NULL if c is not in s. jpayne@69: * @stable ICU 2.0 jpayne@69: * jpayne@69: * @see u_strchr32 jpayne@69: * @see u_memchr jpayne@69: * @see u_strstr jpayne@69: * @see u_strFindFirst jpayne@69: */ jpayne@69: U_STABLE UChar * U_EXPORT2 jpayne@69: u_strchr(const UChar *s, UChar c); jpayne@69: jpayne@69: /** jpayne@69: * Find the first occurrence of a code point in a string. jpayne@69: * A surrogate code point is found only if its match in the text is not jpayne@69: * part of a surrogate pair. jpayne@69: * A NUL character is found at the string terminator. jpayne@69: * jpayne@69: * @param s The string to search (NUL-terminated). jpayne@69: * @param c The code point to find. jpayne@69: * @return A pointer to the first occurrence of c in s jpayne@69: * or NULL if c is not in s. jpayne@69: * @stable ICU 2.0 jpayne@69: * jpayne@69: * @see u_strchr jpayne@69: * @see u_memchr32 jpayne@69: * @see u_strstr jpayne@69: * @see u_strFindFirst jpayne@69: */ jpayne@69: U_STABLE UChar * U_EXPORT2 jpayne@69: u_strchr32(const UChar *s, UChar32 c); jpayne@69: jpayne@69: /** jpayne@69: * Find the last occurrence of a substring in a string. jpayne@69: * The substring is found at code point boundaries. jpayne@69: * That means that if the substring begins with jpayne@69: * a trail surrogate or ends with a lead surrogate, jpayne@69: * then it is found only if these surrogates stand alone in the text. jpayne@69: * Otherwise, the substring edge units would be matched against jpayne@69: * halves of surrogate pairs. jpayne@69: * jpayne@69: * @param s The string to search (NUL-terminated). jpayne@69: * @param substring The substring to find (NUL-terminated). jpayne@69: * @return A pointer to the last occurrence of substring in s, jpayne@69: * or s itself if the substring is empty, jpayne@69: * or NULL if substring is not in s. jpayne@69: * @stable ICU 2.4 jpayne@69: * jpayne@69: * @see u_strstr jpayne@69: * @see u_strFindFirst jpayne@69: * @see u_strFindLast jpayne@69: */ jpayne@69: U_STABLE UChar * U_EXPORT2 jpayne@69: u_strrstr(const UChar *s, const UChar *substring); jpayne@69: jpayne@69: /** jpayne@69: * Find the last occurrence of a substring in a string. jpayne@69: * The substring is found at code point boundaries. jpayne@69: * That means that if the substring begins with jpayne@69: * a trail surrogate or ends with a lead surrogate, jpayne@69: * then it is found only if these surrogates stand alone in the text. jpayne@69: * Otherwise, the substring edge units would be matched against jpayne@69: * halves of surrogate pairs. jpayne@69: * jpayne@69: * @param s The string to search. jpayne@69: * @param length The length of s (number of UChars), or -1 if it is NUL-terminated. jpayne@69: * @param substring The substring to find (NUL-terminated). jpayne@69: * @param subLength The length of substring (number of UChars), or -1 if it is NUL-terminated. jpayne@69: * @return A pointer to the last occurrence of substring in s, jpayne@69: * or s itself if the substring is empty, jpayne@69: * or NULL if substring is not in s. jpayne@69: * @stable ICU 2.4 jpayne@69: * jpayne@69: * @see u_strstr jpayne@69: * @see u_strFindLast jpayne@69: */ jpayne@69: U_STABLE UChar * U_EXPORT2 jpayne@69: u_strFindLast(const UChar *s, int32_t length, const UChar *substring, int32_t subLength); jpayne@69: jpayne@69: /** jpayne@69: * Find the last occurrence of a BMP code point in a string. jpayne@69: * A surrogate code point is found only if its match in the text is not jpayne@69: * part of a surrogate pair. jpayne@69: * A NUL character is found at the string terminator. jpayne@69: * jpayne@69: * @param s The string to search (NUL-terminated). jpayne@69: * @param c The BMP code point to find. jpayne@69: * @return A pointer to the last occurrence of c in s jpayne@69: * or NULL if c is not in s. jpayne@69: * @stable ICU 2.4 jpayne@69: * jpayne@69: * @see u_strrchr32 jpayne@69: * @see u_memrchr jpayne@69: * @see u_strrstr jpayne@69: * @see u_strFindLast jpayne@69: */ jpayne@69: U_STABLE UChar * U_EXPORT2 jpayne@69: u_strrchr(const UChar *s, UChar c); jpayne@69: jpayne@69: /** jpayne@69: * Find the last occurrence of a code point in a string. jpayne@69: * A surrogate code point is found only if its match in the text is not jpayne@69: * part of a surrogate pair. jpayne@69: * A NUL character is found at the string terminator. jpayne@69: * jpayne@69: * @param s The string to search (NUL-terminated). jpayne@69: * @param c The code point to find. jpayne@69: * @return A pointer to the last occurrence of c in s jpayne@69: * or NULL if c is not in s. jpayne@69: * @stable ICU 2.4 jpayne@69: * jpayne@69: * @see u_strrchr jpayne@69: * @see u_memchr32 jpayne@69: * @see u_strrstr jpayne@69: * @see u_strFindLast jpayne@69: */ jpayne@69: U_STABLE UChar * U_EXPORT2 jpayne@69: u_strrchr32(const UChar *s, UChar32 c); jpayne@69: jpayne@69: /** jpayne@69: * Locates the first occurrence in the string string of any of the characters jpayne@69: * in the string matchSet. jpayne@69: * Works just like C's strpbrk but with Unicode. jpayne@69: * jpayne@69: * @param string The string in which to search, NUL-terminated. jpayne@69: * @param matchSet A NUL-terminated string defining a set of code points jpayne@69: * for which to search in the text string. jpayne@69: * @return A pointer to the character in string that matches one of the jpayne@69: * characters in matchSet, or NULL if no such character is found. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE UChar * U_EXPORT2 jpayne@69: u_strpbrk(const UChar *string, const UChar *matchSet); jpayne@69: jpayne@69: /** jpayne@69: * Returns the number of consecutive characters in string, jpayne@69: * beginning with the first, that do not occur somewhere in matchSet. jpayne@69: * Works just like C's strcspn but with Unicode. jpayne@69: * jpayne@69: * @param string The string in which to search, NUL-terminated. jpayne@69: * @param matchSet A NUL-terminated string defining a set of code points jpayne@69: * for which to search in the text string. jpayne@69: * @return The number of initial characters in string that do not jpayne@69: * occur in matchSet. jpayne@69: * @see u_strspn jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE int32_t U_EXPORT2 jpayne@69: u_strcspn(const UChar *string, const UChar *matchSet); jpayne@69: jpayne@69: /** jpayne@69: * Returns the number of consecutive characters in string, jpayne@69: * beginning with the first, that occur somewhere in matchSet. jpayne@69: * Works just like C's strspn but with Unicode. jpayne@69: * jpayne@69: * @param string The string in which to search, NUL-terminated. jpayne@69: * @param matchSet A NUL-terminated string defining a set of code points jpayne@69: * for which to search in the text string. jpayne@69: * @return The number of initial characters in string that do jpayne@69: * occur in matchSet. jpayne@69: * @see u_strcspn jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE int32_t U_EXPORT2 jpayne@69: u_strspn(const UChar *string, const UChar *matchSet); jpayne@69: jpayne@69: /** jpayne@69: * The string tokenizer API allows an application to break a string into jpayne@69: * tokens. Unlike strtok(), the saveState (the current pointer within the jpayne@69: * original string) is maintained in saveState. In the first call, the jpayne@69: * argument src is a pointer to the string. In subsequent calls to jpayne@69: * return successive tokens of that string, src must be specified as jpayne@69: * NULL. The value saveState is set by this function to maintain the jpayne@69: * function's position within the string, and on each subsequent call jpayne@69: * you must give this argument the same variable. This function does jpayne@69: * handle surrogate pairs. This function is similar to the strtok_r() jpayne@69: * the POSIX Threads Extension (1003.1c-1995) version. jpayne@69: * jpayne@69: * @param src String containing token(s). This string will be modified. jpayne@69: * After the first call to u_strtok_r(), this argument must jpayne@69: * be NULL to get to the next token. jpayne@69: * @param delim Set of delimiter characters (Unicode code points). jpayne@69: * @param saveState The current pointer within the original string, jpayne@69: * which is set by this function. The saveState jpayne@69: * parameter should the address of a local variable of type jpayne@69: * UChar *. (i.e. defined "UChar *myLocalSaveState" and use jpayne@69: * &myLocalSaveState for this parameter). jpayne@69: * @return A pointer to the next token found in src, or NULL jpayne@69: * when there are no more tokens. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE UChar * U_EXPORT2 jpayne@69: u_strtok_r(UChar *src, jpayne@69: const UChar *delim, jpayne@69: UChar **saveState); jpayne@69: jpayne@69: /** jpayne@69: * Compare two Unicode strings for bitwise equality (code unit order). jpayne@69: * jpayne@69: * @param s1 A string to compare. jpayne@69: * @param s2 A string to compare. jpayne@69: * @return 0 if s1 and s2 are bitwise equal; a negative jpayne@69: * value if s1 is bitwise less than s2,; a positive jpayne@69: * value if s1 is bitwise greater than s2. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE int32_t U_EXPORT2 jpayne@69: u_strcmp(const UChar *s1, jpayne@69: const UChar *s2); jpayne@69: jpayne@69: /** jpayne@69: * Compare two Unicode strings in code point order. jpayne@69: * See u_strCompare for details. jpayne@69: * jpayne@69: * @param s1 A string to compare. jpayne@69: * @param s2 A string to compare. jpayne@69: * @return a negative/zero/positive integer corresponding to whether jpayne@69: * the first string is less than/equal to/greater than the second one jpayne@69: * in code point order jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE int32_t U_EXPORT2 jpayne@69: u_strcmpCodePointOrder(const UChar *s1, const UChar *s2); jpayne@69: jpayne@69: /** jpayne@69: * Compare two Unicode strings (binary order). jpayne@69: * jpayne@69: * The comparison can be done in code unit order or in code point order. jpayne@69: * They differ only in UTF-16 when jpayne@69: * comparing supplementary code points (U+10000..U+10ffff) jpayne@69: * to BMP code points near the end of the BMP (i.e., U+e000..U+ffff). jpayne@69: * In code unit order, high BMP code points sort after supplementary code points jpayne@69: * because they are stored as pairs of surrogates which are at U+d800..U+dfff. jpayne@69: * jpayne@69: * This functions works with strings of different explicitly specified lengths jpayne@69: * unlike the ANSI C-like u_strcmp() and u_memcmp() etc. jpayne@69: * NUL-terminated strings are possible with length arguments of -1. jpayne@69: * jpayne@69: * @param s1 First source string. jpayne@69: * @param length1 Length of first source string, or -1 if NUL-terminated. jpayne@69: * jpayne@69: * @param s2 Second source string. jpayne@69: * @param length2 Length of second source string, or -1 if NUL-terminated. jpayne@69: * jpayne@69: * @param codePointOrder Choose between code unit order (FALSE) jpayne@69: * and code point order (TRUE). jpayne@69: * jpayne@69: * @return <0 or 0 or >0 as usual for string comparisons jpayne@69: * jpayne@69: * @stable ICU 2.2 jpayne@69: */ jpayne@69: U_STABLE int32_t U_EXPORT2 jpayne@69: u_strCompare(const UChar *s1, int32_t length1, jpayne@69: const UChar *s2, int32_t length2, jpayne@69: UBool codePointOrder); jpayne@69: jpayne@69: /** jpayne@69: * Compare two Unicode strings (binary order) jpayne@69: * as presented by UCharIterator objects. jpayne@69: * Works otherwise just like u_strCompare(). jpayne@69: * jpayne@69: * Both iterators are reset to their start positions. jpayne@69: * When the function returns, it is undefined where the iterators jpayne@69: * have stopped. jpayne@69: * jpayne@69: * @param iter1 First source string iterator. jpayne@69: * @param iter2 Second source string iterator. jpayne@69: * @param codePointOrder Choose between code unit order (FALSE) jpayne@69: * and code point order (TRUE). jpayne@69: * jpayne@69: * @return <0 or 0 or >0 as usual for string comparisons jpayne@69: * jpayne@69: * @see u_strCompare jpayne@69: * jpayne@69: * @stable ICU 2.6 jpayne@69: */ jpayne@69: U_STABLE int32_t U_EXPORT2 jpayne@69: u_strCompareIter(UCharIterator *iter1, UCharIterator *iter2, UBool codePointOrder); jpayne@69: jpayne@69: /** jpayne@69: * Compare two strings case-insensitively using full case folding. jpayne@69: * This is equivalent to jpayne@69: * u_strCompare(u_strFoldCase(s1, options), jpayne@69: * u_strFoldCase(s2, options), jpayne@69: * (options&U_COMPARE_CODE_POINT_ORDER)!=0). jpayne@69: * jpayne@69: * The comparison can be done in UTF-16 code unit order or in code point order. jpayne@69: * They differ only when comparing supplementary code points (U+10000..U+10ffff) jpayne@69: * to BMP code points near the end of the BMP (i.e., U+e000..U+ffff). jpayne@69: * In code unit order, high BMP code points sort after supplementary code points jpayne@69: * because they are stored as pairs of surrogates which are at U+d800..U+dfff. jpayne@69: * jpayne@69: * This functions works with strings of different explicitly specified lengths jpayne@69: * unlike the ANSI C-like u_strcmp() and u_memcmp() etc. jpayne@69: * NUL-terminated strings are possible with length arguments of -1. jpayne@69: * jpayne@69: * @param s1 First source string. jpayne@69: * @param length1 Length of first source string, or -1 if NUL-terminated. jpayne@69: * jpayne@69: * @param s2 Second source string. jpayne@69: * @param length2 Length of second source string, or -1 if NUL-terminated. jpayne@69: * jpayne@69: * @param options A bit set of options: jpayne@69: * - U_FOLD_CASE_DEFAULT or 0 is used for default options: jpayne@69: * Comparison in code unit order with default case folding. jpayne@69: * jpayne@69: * - U_COMPARE_CODE_POINT_ORDER jpayne@69: * Set to choose code point order instead of code unit order jpayne@69: * (see u_strCompare for details). jpayne@69: * jpayne@69: * - U_FOLD_CASE_EXCLUDE_SPECIAL_I jpayne@69: * jpayne@69: * @param pErrorCode Must be a valid pointer to an error code value, jpayne@69: * which must not indicate a failure before the function call. jpayne@69: * jpayne@69: * @return <0 or 0 or >0 as usual for string comparisons jpayne@69: * jpayne@69: * @stable ICU 2.2 jpayne@69: */ jpayne@69: U_STABLE int32_t U_EXPORT2 jpayne@69: u_strCaseCompare(const UChar *s1, int32_t length1, jpayne@69: const UChar *s2, int32_t length2, jpayne@69: uint32_t options, jpayne@69: UErrorCode *pErrorCode); jpayne@69: jpayne@69: /** jpayne@69: * Compare two ustrings for bitwise equality. jpayne@69: * Compares at most n characters. jpayne@69: * jpayne@69: * @param ucs1 A string to compare (can be NULL/invalid if n<=0). jpayne@69: * @param ucs2 A string to compare (can be NULL/invalid if n<=0). jpayne@69: * @param n The maximum number of characters to compare; always returns 0 if n<=0. jpayne@69: * @return 0 if s1 and s2 are bitwise equal; a negative jpayne@69: * value if s1 is bitwise less than s2; a positive jpayne@69: * value if s1 is bitwise greater than s2. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE int32_t U_EXPORT2 jpayne@69: u_strncmp(const UChar *ucs1, jpayne@69: const UChar *ucs2, jpayne@69: int32_t n); jpayne@69: jpayne@69: /** jpayne@69: * Compare two Unicode strings in code point order. jpayne@69: * This is different in UTF-16 from u_strncmp() if supplementary characters are present. jpayne@69: * For details, see u_strCompare(). jpayne@69: * jpayne@69: * @param s1 A string to compare. jpayne@69: * @param s2 A string to compare. jpayne@69: * @param n The maximum number of characters to compare. jpayne@69: * @return a negative/zero/positive integer corresponding to whether jpayne@69: * the first string is less than/equal to/greater than the second one jpayne@69: * in code point order jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE int32_t U_EXPORT2 jpayne@69: u_strncmpCodePointOrder(const UChar *s1, const UChar *s2, int32_t n); jpayne@69: jpayne@69: /** jpayne@69: * Compare two strings case-insensitively using full case folding. jpayne@69: * This is equivalent to u_strcmp(u_strFoldCase(s1, options), u_strFoldCase(s2, options)). jpayne@69: * jpayne@69: * @param s1 A string to compare. jpayne@69: * @param s2 A string to compare. jpayne@69: * @param options A bit set of options: jpayne@69: * - U_FOLD_CASE_DEFAULT or 0 is used for default options: jpayne@69: * Comparison in code unit order with default case folding. jpayne@69: * jpayne@69: * - U_COMPARE_CODE_POINT_ORDER jpayne@69: * Set to choose code point order instead of code unit order jpayne@69: * (see u_strCompare for details). jpayne@69: * jpayne@69: * - U_FOLD_CASE_EXCLUDE_SPECIAL_I jpayne@69: * jpayne@69: * @return A negative, zero, or positive integer indicating the comparison result. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE int32_t U_EXPORT2 jpayne@69: u_strcasecmp(const UChar *s1, const UChar *s2, uint32_t options); jpayne@69: jpayne@69: /** jpayne@69: * Compare two strings case-insensitively using full case folding. jpayne@69: * This is equivalent to u_strcmp(u_strFoldCase(s1, at most n, options), jpayne@69: * u_strFoldCase(s2, at most n, options)). jpayne@69: * jpayne@69: * @param s1 A string to compare. jpayne@69: * @param s2 A string to compare. jpayne@69: * @param n The maximum number of characters each string to case-fold and then compare. jpayne@69: * @param options A bit set of options: jpayne@69: * - U_FOLD_CASE_DEFAULT or 0 is used for default options: jpayne@69: * Comparison in code unit order with default case folding. jpayne@69: * jpayne@69: * - U_COMPARE_CODE_POINT_ORDER jpayne@69: * Set to choose code point order instead of code unit order jpayne@69: * (see u_strCompare for details). jpayne@69: * jpayne@69: * - U_FOLD_CASE_EXCLUDE_SPECIAL_I jpayne@69: * jpayne@69: * @return A negative, zero, or positive integer indicating the comparison result. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE int32_t U_EXPORT2 jpayne@69: u_strncasecmp(const UChar *s1, const UChar *s2, int32_t n, uint32_t options); jpayne@69: jpayne@69: /** jpayne@69: * Compare two strings case-insensitively using full case folding. jpayne@69: * This is equivalent to u_strcmp(u_strFoldCase(s1, n, options), jpayne@69: * u_strFoldCase(s2, n, options)). jpayne@69: * jpayne@69: * @param s1 A string to compare. jpayne@69: * @param s2 A string to compare. jpayne@69: * @param length The number of characters in each string to case-fold and then compare. jpayne@69: * @param options A bit set of options: jpayne@69: * - U_FOLD_CASE_DEFAULT or 0 is used for default options: jpayne@69: * Comparison in code unit order with default case folding. jpayne@69: * jpayne@69: * - U_COMPARE_CODE_POINT_ORDER jpayne@69: * Set to choose code point order instead of code unit order jpayne@69: * (see u_strCompare for details). jpayne@69: * jpayne@69: * - U_FOLD_CASE_EXCLUDE_SPECIAL_I jpayne@69: * jpayne@69: * @return A negative, zero, or positive integer indicating the comparison result. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE int32_t U_EXPORT2 jpayne@69: u_memcasecmp(const UChar *s1, const UChar *s2, int32_t length, uint32_t options); jpayne@69: jpayne@69: /** jpayne@69: * Copy a ustring. Adds a null terminator. jpayne@69: * jpayne@69: * @param dst The destination string. jpayne@69: * @param src The source string. jpayne@69: * @return A pointer to dst. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE UChar* U_EXPORT2 jpayne@69: u_strcpy(UChar *dst, jpayne@69: const UChar *src); jpayne@69: jpayne@69: /** jpayne@69: * Copy a ustring. jpayne@69: * Copies at most n characters. The result will be null terminated jpayne@69: * if the length of src is less than n. jpayne@69: * jpayne@69: * @param dst The destination string. jpayne@69: * @param src The source string (can be NULL/invalid if n<=0). jpayne@69: * @param n The maximum number of characters to copy; no-op if <=0. jpayne@69: * @return A pointer to dst. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE UChar* U_EXPORT2 jpayne@69: u_strncpy(UChar *dst, jpayne@69: const UChar *src, jpayne@69: int32_t n); jpayne@69: jpayne@69: #if !UCONFIG_NO_CONVERSION jpayne@69: jpayne@69: /** jpayne@69: * Copy a byte string encoded in the default codepage to a ustring. jpayne@69: * Adds a null terminator. jpayne@69: * Performs a host byte to UChar conversion jpayne@69: * jpayne@69: * @param dst The destination string. jpayne@69: * @param src The source string. jpayne@69: * @return A pointer to dst. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE UChar* U_EXPORT2 u_uastrcpy(UChar *dst, jpayne@69: const char *src ); jpayne@69: jpayne@69: /** jpayne@69: * Copy a byte string encoded in the default codepage to a ustring. jpayne@69: * Copies at most n characters. The result will be null terminated jpayne@69: * if the length of src is less than n. jpayne@69: * Performs a host byte to UChar conversion jpayne@69: * jpayne@69: * @param dst The destination string. jpayne@69: * @param src The source string. jpayne@69: * @param n The maximum number of characters to copy. jpayne@69: * @return A pointer to dst. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE UChar* U_EXPORT2 u_uastrncpy(UChar *dst, jpayne@69: const char *src, jpayne@69: int32_t n); jpayne@69: jpayne@69: /** jpayne@69: * Copy ustring to a byte string encoded in the default codepage. jpayne@69: * Adds a null terminator. jpayne@69: * Performs a UChar to host byte conversion jpayne@69: * jpayne@69: * @param dst The destination string. jpayne@69: * @param src The source string. jpayne@69: * @return A pointer to dst. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE char* U_EXPORT2 u_austrcpy(char *dst, jpayne@69: const UChar *src ); jpayne@69: jpayne@69: /** jpayne@69: * Copy ustring to a byte string encoded in the default codepage. jpayne@69: * Copies at most n characters. The result will be null terminated jpayne@69: * if the length of src is less than n. jpayne@69: * Performs a UChar to host byte conversion jpayne@69: * jpayne@69: * @param dst The destination string. jpayne@69: * @param src The source string. jpayne@69: * @param n The maximum number of characters to copy. jpayne@69: * @return A pointer to dst. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE char* U_EXPORT2 u_austrncpy(char *dst, jpayne@69: const UChar *src, jpayne@69: int32_t n ); jpayne@69: jpayne@69: #endif jpayne@69: jpayne@69: /** jpayne@69: * Synonym for memcpy(), but with UChars only. jpayne@69: * @param dest The destination string jpayne@69: * @param src The source string (can be NULL/invalid if count<=0) jpayne@69: * @param count The number of characters to copy; no-op if <=0 jpayne@69: * @return A pointer to dest jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE UChar* U_EXPORT2 jpayne@69: u_memcpy(UChar *dest, const UChar *src, int32_t count); jpayne@69: jpayne@69: /** jpayne@69: * Synonym for memmove(), but with UChars only. jpayne@69: * @param dest The destination string jpayne@69: * @param src The source string (can be NULL/invalid if count<=0) jpayne@69: * @param count The number of characters to move; no-op if <=0 jpayne@69: * @return A pointer to dest jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE UChar* U_EXPORT2 jpayne@69: u_memmove(UChar *dest, const UChar *src, int32_t count); jpayne@69: jpayne@69: /** jpayne@69: * Initialize count characters of dest to c. jpayne@69: * jpayne@69: * @param dest The destination string. jpayne@69: * @param c The character to initialize the string. jpayne@69: * @param count The maximum number of characters to set. jpayne@69: * @return A pointer to dest. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE UChar* U_EXPORT2 jpayne@69: u_memset(UChar *dest, UChar c, int32_t count); jpayne@69: jpayne@69: /** jpayne@69: * Compare the first count UChars of each buffer. jpayne@69: * jpayne@69: * @param buf1 The first string to compare. jpayne@69: * @param buf2 The second string to compare. jpayne@69: * @param count The maximum number of UChars to compare. jpayne@69: * @return When buf1 < buf2, a negative number is returned. jpayne@69: * When buf1 == buf2, 0 is returned. jpayne@69: * When buf1 > buf2, a positive number is returned. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE int32_t U_EXPORT2 jpayne@69: u_memcmp(const UChar *buf1, const UChar *buf2, int32_t count); jpayne@69: jpayne@69: /** jpayne@69: * Compare two Unicode strings in code point order. jpayne@69: * This is different in UTF-16 from u_memcmp() if supplementary characters are present. jpayne@69: * For details, see u_strCompare(). jpayne@69: * jpayne@69: * @param s1 A string to compare. jpayne@69: * @param s2 A string to compare. jpayne@69: * @param count The maximum number of characters to compare. jpayne@69: * @return a negative/zero/positive integer corresponding to whether jpayne@69: * the first string is less than/equal to/greater than the second one jpayne@69: * in code point order jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE int32_t U_EXPORT2 jpayne@69: u_memcmpCodePointOrder(const UChar *s1, const UChar *s2, int32_t count); jpayne@69: jpayne@69: /** jpayne@69: * Find the first occurrence of a BMP code point in a string. jpayne@69: * A surrogate code point is found only if its match in the text is not jpayne@69: * part of a surrogate pair. jpayne@69: * A NUL character is found at the string terminator. jpayne@69: * jpayne@69: * @param s The string to search (contains count UChars). jpayne@69: * @param c The BMP code point to find. jpayne@69: * @param count The length of the string. jpayne@69: * @return A pointer to the first occurrence of c in s jpayne@69: * or NULL if c is not in s. jpayne@69: * @stable ICU 2.0 jpayne@69: * jpayne@69: * @see u_strchr jpayne@69: * @see u_memchr32 jpayne@69: * @see u_strFindFirst jpayne@69: */ jpayne@69: U_STABLE UChar* U_EXPORT2 jpayne@69: u_memchr(const UChar *s, UChar c, int32_t count); jpayne@69: jpayne@69: /** jpayne@69: * Find the first occurrence of a code point in a string. jpayne@69: * A surrogate code point is found only if its match in the text is not jpayne@69: * part of a surrogate pair. jpayne@69: * A NUL character is found at the string terminator. jpayne@69: * jpayne@69: * @param s The string to search (contains count UChars). jpayne@69: * @param c The code point to find. jpayne@69: * @param count The length of the string. jpayne@69: * @return A pointer to the first occurrence of c in s jpayne@69: * or NULL if c is not in s. jpayne@69: * @stable ICU 2.0 jpayne@69: * jpayne@69: * @see u_strchr32 jpayne@69: * @see u_memchr jpayne@69: * @see u_strFindFirst jpayne@69: */ jpayne@69: U_STABLE UChar* U_EXPORT2 jpayne@69: u_memchr32(const UChar *s, UChar32 c, int32_t count); jpayne@69: jpayne@69: /** jpayne@69: * Find the last occurrence of a BMP code point in a string. jpayne@69: * A surrogate code point is found only if its match in the text is not jpayne@69: * part of a surrogate pair. jpayne@69: * A NUL character is found at the string terminator. jpayne@69: * jpayne@69: * @param s The string to search (contains count UChars). jpayne@69: * @param c The BMP code point to find. jpayne@69: * @param count The length of the string. jpayne@69: * @return A pointer to the last occurrence of c in s jpayne@69: * or NULL if c is not in s. jpayne@69: * @stable ICU 2.4 jpayne@69: * jpayne@69: * @see u_strrchr jpayne@69: * @see u_memrchr32 jpayne@69: * @see u_strFindLast jpayne@69: */ jpayne@69: U_STABLE UChar* U_EXPORT2 jpayne@69: u_memrchr(const UChar *s, UChar c, int32_t count); jpayne@69: jpayne@69: /** jpayne@69: * Find the last occurrence of a code point in a string. jpayne@69: * A surrogate code point is found only if its match in the text is not jpayne@69: * part of a surrogate pair. jpayne@69: * A NUL character is found at the string terminator. jpayne@69: * jpayne@69: * @param s The string to search (contains count UChars). jpayne@69: * @param c The code point to find. jpayne@69: * @param count The length of the string. jpayne@69: * @return A pointer to the last occurrence of c in s jpayne@69: * or NULL if c is not in s. jpayne@69: * @stable ICU 2.4 jpayne@69: * jpayne@69: * @see u_strrchr32 jpayne@69: * @see u_memrchr jpayne@69: * @see u_strFindLast jpayne@69: */ jpayne@69: U_STABLE UChar* U_EXPORT2 jpayne@69: u_memrchr32(const UChar *s, UChar32 c, int32_t count); jpayne@69: jpayne@69: /** jpayne@69: * Unicode String literals in C. jpayne@69: * We need one macro to declare a variable for the string jpayne@69: * and to statically preinitialize it if possible, jpayne@69: * and a second macro to dynamically initialize such a string variable if necessary. jpayne@69: * jpayne@69: * The macros are defined for maximum performance. jpayne@69: * They work only for strings that contain "invariant characters", i.e., jpayne@69: * only latin letters, digits, and some punctuation. jpayne@69: * See utypes.h for details. jpayne@69: * jpayne@69: * A pair of macros for a single string must be used with the same jpayne@69: * parameters. jpayne@69: * The string parameter must be a C string literal. jpayne@69: * The length of the string, not including the terminating jpayne@69: * `NUL`, must be specified as a constant. jpayne@69: * The U_STRING_DECL macro should be invoked exactly once for one jpayne@69: * such string variable before it is used. jpayne@69: * jpayne@69: * Usage: jpayne@69: * jpayne@69: * U_STRING_DECL(ustringVar1, "Quick-Fox 2", 11); jpayne@69: * U_STRING_DECL(ustringVar2, "jumps 5%", 8); jpayne@69: * static UBool didInit=FALSE; jpayne@69: * jpayne@69: * int32_t function() { jpayne@69: * if(!didInit) { jpayne@69: * U_STRING_INIT(ustringVar1, "Quick-Fox 2", 11); jpayne@69: * U_STRING_INIT(ustringVar2, "jumps 5%", 8); jpayne@69: * didInit=TRUE; jpayne@69: * } jpayne@69: * return u_strcmp(ustringVar1, ustringVar2); jpayne@69: * } jpayne@69: * jpayne@69: * Note that the macros will NOT consistently work if their argument is another #`define`. jpayne@69: * The following will not work on all platforms, don't use it. jpayne@69: * jpayne@69: * #define GLUCK "Mr. Gluck" jpayne@69: * U_STRING_DECL(var, GLUCK, 9) jpayne@69: * U_STRING_INIT(var, GLUCK, 9) jpayne@69: * jpayne@69: * Instead, use the string literal "Mr. Gluck" as the argument to both macro jpayne@69: * calls. jpayne@69: * jpayne@69: * jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: #if defined(U_DECLARE_UTF16) jpayne@69: # define U_STRING_DECL(var, cs, length) static const UChar *var=(const UChar *)U_DECLARE_UTF16(cs) jpayne@69: /**@stable ICU 2.0 */ jpayne@69: # define U_STRING_INIT(var, cs, length) jpayne@69: #elif U_SIZEOF_WCHAR_T==U_SIZEOF_UCHAR && (U_CHARSET_FAMILY==U_ASCII_FAMILY || (U_SIZEOF_UCHAR == 2 && defined(U_WCHAR_IS_UTF16))) jpayne@69: # define U_STRING_DECL(var, cs, length) static const UChar var[(length)+1]=L ## cs jpayne@69: /**@stable ICU 2.0 */ jpayne@69: # define U_STRING_INIT(var, cs, length) jpayne@69: #elif U_SIZEOF_UCHAR==1 && U_CHARSET_FAMILY==U_ASCII_FAMILY jpayne@69: # define U_STRING_DECL(var, cs, length) static const UChar var[(length)+1]=cs jpayne@69: /**@stable ICU 2.0 */ jpayne@69: # define U_STRING_INIT(var, cs, length) jpayne@69: #else jpayne@69: # define U_STRING_DECL(var, cs, length) static UChar var[(length)+1] jpayne@69: /**@stable ICU 2.0 */ jpayne@69: # define U_STRING_INIT(var, cs, length) u_charsToUChars(cs, var, length+1) jpayne@69: #endif jpayne@69: jpayne@69: /** jpayne@69: * Unescape a string of characters and write the resulting jpayne@69: * Unicode characters to the destination buffer. The following escape jpayne@69: * sequences are recognized: jpayne@69: * jpayne@69: * \\uhhhh 4 hex digits; h in [0-9A-Fa-f] jpayne@69: * \\Uhhhhhhhh 8 hex digits jpayne@69: * \\xhh 1-2 hex digits jpayne@69: * \\x{h...} 1-8 hex digits jpayne@69: * \\ooo 1-3 octal digits; o in [0-7] jpayne@69: * \\cX control-X; X is masked with 0x1F jpayne@69: * jpayne@69: * as well as the standard ANSI C escapes: jpayne@69: * jpayne@69: * \\a => U+0007, \\b => U+0008, \\t => U+0009, \\n => U+000A, jpayne@69: * \\v => U+000B, \\f => U+000C, \\r => U+000D, \\e => U+001B, jpayne@69: * \\" => U+0022, \\' => U+0027, \\? => U+003F, \\\\ => U+005C jpayne@69: * jpayne@69: * Anything else following a backslash is generically escaped. For jpayne@69: * example, "[a\\-z]" returns "[a-z]". jpayne@69: * jpayne@69: * If an escape sequence is ill-formed, this method returns an empty jpayne@69: * string. An example of an ill-formed sequence is "\\u" followed by jpayne@69: * fewer than 4 hex digits. jpayne@69: * jpayne@69: * The above characters are recognized in the compiler's codepage, jpayne@69: * that is, they are coded as 'u', '\\', etc. Characters that are jpayne@69: * not parts of escape sequences are converted using u_charsToUChars(). jpayne@69: * jpayne@69: * This function is similar to UnicodeString::unescape() but not jpayne@69: * identical to it. The latter takes a source UnicodeString, so it jpayne@69: * does escape recognition but no conversion. jpayne@69: * jpayne@69: * @param src a zero-terminated string of invariant characters jpayne@69: * @param dest pointer to buffer to receive converted and unescaped jpayne@69: * text and, if there is room, a zero terminator. May be NULL for jpayne@69: * preflighting, in which case no UChars will be written, but the jpayne@69: * return value will still be valid. On error, an empty string is jpayne@69: * stored here (if possible). jpayne@69: * @param destCapacity the number of UChars that may be written at jpayne@69: * dest. Ignored if dest == NULL. jpayne@69: * @return the length of unescaped string. jpayne@69: * @see u_unescapeAt jpayne@69: * @see UnicodeString#unescape() jpayne@69: * @see UnicodeString#unescapeAt() jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE int32_t U_EXPORT2 jpayne@69: u_unescape(const char *src, jpayne@69: UChar *dest, int32_t destCapacity); jpayne@69: jpayne@69: U_CDECL_BEGIN jpayne@69: /** jpayne@69: * Callback function for u_unescapeAt() that returns a character of jpayne@69: * the source text given an offset and a context pointer. The context jpayne@69: * pointer will be whatever is passed into u_unescapeAt(). jpayne@69: * jpayne@69: * @param offset pointer to the offset that will be passed to u_unescapeAt(). jpayne@69: * @param context an opaque pointer passed directly into u_unescapeAt() jpayne@69: * @return the character represented by the escape sequence at jpayne@69: * offset jpayne@69: * @see u_unescapeAt jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: typedef UChar (U_CALLCONV *UNESCAPE_CHAR_AT)(int32_t offset, void *context); jpayne@69: U_CDECL_END jpayne@69: jpayne@69: /** jpayne@69: * Unescape a single sequence. The character at offset-1 is assumed jpayne@69: * (without checking) to be a backslash. This method takes a callback jpayne@69: * pointer to a function that returns the UChar at a given offset. By jpayne@69: * varying this callback, ICU functions are able to unescape char* jpayne@69: * strings, UnicodeString objects, and UFILE pointers. jpayne@69: * jpayne@69: * If offset is out of range, or if the escape sequence is ill-formed, jpayne@69: * (UChar32)0xFFFFFFFF is returned. See documentation of u_unescape() jpayne@69: * for a list of recognized sequences. jpayne@69: * jpayne@69: * @param charAt callback function that returns a UChar of the source jpayne@69: * text given an offset and a context pointer. jpayne@69: * @param offset pointer to the offset that will be passed to charAt. jpayne@69: * The offset value will be updated upon return to point after the jpayne@69: * last parsed character of the escape sequence. On error the offset jpayne@69: * is unchanged. jpayne@69: * @param length the number of characters in the source text. The jpayne@69: * last character of the source text is considered to be at offset jpayne@69: * length-1. jpayne@69: * @param context an opaque pointer passed directly into charAt. jpayne@69: * @return the character represented by the escape sequence at jpayne@69: * offset, or (UChar32)0xFFFFFFFF on error. jpayne@69: * @see u_unescape() jpayne@69: * @see UnicodeString#unescape() jpayne@69: * @see UnicodeString#unescapeAt() jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE UChar32 U_EXPORT2 jpayne@69: u_unescapeAt(UNESCAPE_CHAR_AT charAt, jpayne@69: int32_t *offset, jpayne@69: int32_t length, jpayne@69: void *context); jpayne@69: jpayne@69: /** jpayne@69: * Uppercase the characters in a string. jpayne@69: * Casing is locale-dependent and context-sensitive. jpayne@69: * The result may be longer or shorter than the original. jpayne@69: * The source string and the destination buffer are allowed to overlap. jpayne@69: * jpayne@69: * @param dest A buffer for the result string. The result will be zero-terminated if jpayne@69: * the buffer is large enough. jpayne@69: * @param destCapacity The size of the buffer (number of UChars). If it is 0, then jpayne@69: * dest may be NULL and the function will only return the length of the result jpayne@69: * without writing any of the result string. jpayne@69: * @param src The original string jpayne@69: * @param srcLength The length of the original string. If -1, then src must be zero-terminated. jpayne@69: * @param locale The locale to consider, or "" for the root locale or NULL for the default locale. jpayne@69: * @param pErrorCode Must be a valid pointer to an error code value, jpayne@69: * which must not indicate a failure before the function call. jpayne@69: * @return The length of the result string. It may be greater than destCapacity. In that case, jpayne@69: * only some of the result was written to the destination buffer. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE int32_t U_EXPORT2 jpayne@69: u_strToUpper(UChar *dest, int32_t destCapacity, jpayne@69: const UChar *src, int32_t srcLength, jpayne@69: const char *locale, jpayne@69: UErrorCode *pErrorCode); jpayne@69: jpayne@69: /** jpayne@69: * Lowercase the characters in a string. jpayne@69: * Casing is locale-dependent and context-sensitive. jpayne@69: * The result may be longer or shorter than the original. jpayne@69: * The source string and the destination buffer are allowed to overlap. jpayne@69: * jpayne@69: * @param dest A buffer for the result string. The result will be zero-terminated if jpayne@69: * the buffer is large enough. jpayne@69: * @param destCapacity The size of the buffer (number of UChars). If it is 0, then jpayne@69: * dest may be NULL and the function will only return the length of the result jpayne@69: * without writing any of the result string. jpayne@69: * @param src The original string jpayne@69: * @param srcLength The length of the original string. If -1, then src must be zero-terminated. jpayne@69: * @param locale The locale to consider, or "" for the root locale or NULL for the default locale. jpayne@69: * @param pErrorCode Must be a valid pointer to an error code value, jpayne@69: * which must not indicate a failure before the function call. jpayne@69: * @return The length of the result string. It may be greater than destCapacity. In that case, jpayne@69: * only some of the result was written to the destination buffer. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE int32_t U_EXPORT2 jpayne@69: u_strToLower(UChar *dest, int32_t destCapacity, jpayne@69: const UChar *src, int32_t srcLength, jpayne@69: const char *locale, jpayne@69: UErrorCode *pErrorCode); jpayne@69: jpayne@69: #if !UCONFIG_NO_BREAK_ITERATION jpayne@69: jpayne@69: /** jpayne@69: * Titlecase a string. jpayne@69: * Casing is locale-dependent and context-sensitive. jpayne@69: * Titlecasing uses a break iterator to find the first characters of words jpayne@69: * that are to be titlecased. It titlecases those characters and lowercases jpayne@69: * all others. jpayne@69: * jpayne@69: * The titlecase break iterator can be provided to customize for arbitrary jpayne@69: * styles, using rules and dictionaries beyond the standard iterators. jpayne@69: * It may be more efficient to always provide an iterator to avoid jpayne@69: * opening and closing one for each string. jpayne@69: * The standard titlecase iterator for the root locale implements the jpayne@69: * algorithm of Unicode TR 21. jpayne@69: * jpayne@69: * This function uses only the setText(), first() and next() methods of the jpayne@69: * provided break iterator. jpayne@69: * jpayne@69: * The result may be longer or shorter than the original. jpayne@69: * The source string and the destination buffer are allowed to overlap. jpayne@69: * jpayne@69: * @param dest A buffer for the result string. The result will be zero-terminated if jpayne@69: * the buffer is large enough. jpayne@69: * @param destCapacity The size of the buffer (number of UChars). If it is 0, then jpayne@69: * dest may be NULL and the function will only return the length of the result jpayne@69: * without writing any of the result string. jpayne@69: * @param src The original string jpayne@69: * @param srcLength The length of the original string. If -1, then src must be zero-terminated. jpayne@69: * @param titleIter A break iterator to find the first characters of words jpayne@69: * that are to be titlecased. jpayne@69: * If none is provided (NULL), then a standard titlecase jpayne@69: * break iterator is opened. jpayne@69: * @param locale The locale to consider, or "" for the root locale or NULL for the default locale. jpayne@69: * @param pErrorCode Must be a valid pointer to an error code value, jpayne@69: * which must not indicate a failure before the function call. jpayne@69: * @return The length of the result string. It may be greater than destCapacity. In that case, jpayne@69: * only some of the result was written to the destination buffer. jpayne@69: * @stable ICU 2.1 jpayne@69: */ jpayne@69: U_STABLE int32_t U_EXPORT2 jpayne@69: u_strToTitle(UChar *dest, int32_t destCapacity, jpayne@69: const UChar *src, int32_t srcLength, jpayne@69: UBreakIterator *titleIter, jpayne@69: const char *locale, jpayne@69: UErrorCode *pErrorCode); jpayne@69: jpayne@69: #endif jpayne@69: jpayne@69: /** jpayne@69: * Case-folds the characters in a string. jpayne@69: * jpayne@69: * Case-folding is locale-independent and not context-sensitive, jpayne@69: * but there is an option for whether to include or exclude mappings for dotted I jpayne@69: * and dotless i that are marked with 'T' in CaseFolding.txt. jpayne@69: * jpayne@69: * The result may be longer or shorter than the original. jpayne@69: * The source string and the destination buffer are allowed to overlap. jpayne@69: * jpayne@69: * @param dest A buffer for the result string. The result will be zero-terminated if jpayne@69: * the buffer is large enough. jpayne@69: * @param destCapacity The size of the buffer (number of UChars). If it is 0, then jpayne@69: * dest may be NULL and the function will only return the length of the result jpayne@69: * without writing any of the result string. jpayne@69: * @param src The original string jpayne@69: * @param srcLength The length of the original string. If -1, then src must be zero-terminated. jpayne@69: * @param options Either U_FOLD_CASE_DEFAULT or U_FOLD_CASE_EXCLUDE_SPECIAL_I jpayne@69: * @param pErrorCode Must be a valid pointer to an error code value, jpayne@69: * which must not indicate a failure before the function call. jpayne@69: * @return The length of the result string. It may be greater than destCapacity. In that case, jpayne@69: * only some of the result was written to the destination buffer. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE int32_t U_EXPORT2 jpayne@69: u_strFoldCase(UChar *dest, int32_t destCapacity, jpayne@69: const UChar *src, int32_t srcLength, jpayne@69: uint32_t options, jpayne@69: UErrorCode *pErrorCode); jpayne@69: jpayne@69: #if defined(U_WCHAR_IS_UTF16) || defined(U_WCHAR_IS_UTF32) || !UCONFIG_NO_CONVERSION jpayne@69: /** jpayne@69: * Convert a UTF-16 string to a wchar_t string. jpayne@69: * If it is known at compile time that wchar_t strings are in UTF-16 or UTF-32, then jpayne@69: * this function simply calls the fast, dedicated function for that. jpayne@69: * Otherwise, two conversions UTF-16 -> default charset -> wchar_t* are performed. jpayne@69: * jpayne@69: * @param dest A buffer for the result string. The result will be zero-terminated if jpayne@69: * the buffer is large enough. jpayne@69: * @param destCapacity The size of the buffer (number of wchar_t's). If it is 0, then jpayne@69: * dest may be NULL and the function will only return the length of the jpayne@69: * result without writing any of the result string (pre-flighting). jpayne@69: * @param pDestLength A pointer to receive the number of units written to the destination. If jpayne@69: * pDestLength!=NULL then *pDestLength is always set to the jpayne@69: * number of output units corresponding to the transformation of jpayne@69: * all the input units, even in case of a buffer overflow. jpayne@69: * @param src The original source string jpayne@69: * @param srcLength The length of the original string. If -1, then src must be zero-terminated. jpayne@69: * @param pErrorCode Must be a valid pointer to an error code value, jpayne@69: * which must not indicate a failure before the function call. jpayne@69: * @return The pointer to destination buffer. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE wchar_t* U_EXPORT2 jpayne@69: u_strToWCS(wchar_t *dest, jpayne@69: int32_t destCapacity, jpayne@69: int32_t *pDestLength, jpayne@69: const UChar *src, jpayne@69: int32_t srcLength, jpayne@69: UErrorCode *pErrorCode); jpayne@69: /** jpayne@69: * Convert a wchar_t string to UTF-16. jpayne@69: * If it is known at compile time that wchar_t strings are in UTF-16 or UTF-32, then jpayne@69: * this function simply calls the fast, dedicated function for that. jpayne@69: * Otherwise, two conversions wchar_t* -> default charset -> UTF-16 are performed. jpayne@69: * jpayne@69: * @param dest A buffer for the result string. The result will be zero-terminated if jpayne@69: * the buffer is large enough. jpayne@69: * @param destCapacity The size of the buffer (number of UChars). If it is 0, then jpayne@69: * dest may be NULL and the function will only return the length of the jpayne@69: * result without writing any of the result string (pre-flighting). jpayne@69: * @param pDestLength A pointer to receive the number of units written to the destination. If jpayne@69: * pDestLength!=NULL then *pDestLength is always set to the jpayne@69: * number of output units corresponding to the transformation of jpayne@69: * all the input units, even in case of a buffer overflow. jpayne@69: * @param src The original source string jpayne@69: * @param srcLength The length of the original string. If -1, then src must be zero-terminated. jpayne@69: * @param pErrorCode Must be a valid pointer to an error code value, jpayne@69: * which must not indicate a failure before the function call. jpayne@69: * @return The pointer to destination buffer. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE UChar* U_EXPORT2 jpayne@69: u_strFromWCS(UChar *dest, jpayne@69: int32_t destCapacity, jpayne@69: int32_t *pDestLength, jpayne@69: const wchar_t *src, jpayne@69: int32_t srcLength, jpayne@69: UErrorCode *pErrorCode); jpayne@69: #endif /* defined(U_WCHAR_IS_UTF16) || defined(U_WCHAR_IS_UTF32) || !UCONFIG_NO_CONVERSION */ jpayne@69: jpayne@69: /** jpayne@69: * Convert a UTF-16 string to UTF-8. jpayne@69: * If the input string is not well-formed, then the U_INVALID_CHAR_FOUND error code is set. jpayne@69: * jpayne@69: * @param dest A buffer for the result string. The result will be zero-terminated if jpayne@69: * the buffer is large enough. jpayne@69: * @param destCapacity The size of the buffer (number of chars). If it is 0, then jpayne@69: * dest may be NULL and the function will only return the length of the jpayne@69: * result without writing any of the result string (pre-flighting). jpayne@69: * @param pDestLength A pointer to receive the number of units written to the destination. If jpayne@69: * pDestLength!=NULL then *pDestLength is always set to the jpayne@69: * number of output units corresponding to the transformation of jpayne@69: * all the input units, even in case of a buffer overflow. jpayne@69: * @param src The original source string jpayne@69: * @param srcLength The length of the original string. If -1, then src must be zero-terminated. jpayne@69: * @param pErrorCode Must be a valid pointer to an error code value, jpayne@69: * which must not indicate a failure before the function call. jpayne@69: * @return The pointer to destination buffer. jpayne@69: * @stable ICU 2.0 jpayne@69: * @see u_strToUTF8WithSub jpayne@69: * @see u_strFromUTF8 jpayne@69: */ jpayne@69: U_STABLE char* U_EXPORT2 jpayne@69: u_strToUTF8(char *dest, jpayne@69: int32_t destCapacity, jpayne@69: int32_t *pDestLength, jpayne@69: const UChar *src, jpayne@69: int32_t srcLength, jpayne@69: UErrorCode *pErrorCode); jpayne@69: jpayne@69: /** jpayne@69: * Convert a UTF-8 string to UTF-16. jpayne@69: * If the input string is not well-formed, then the U_INVALID_CHAR_FOUND error code is set. jpayne@69: * jpayne@69: * @param dest A buffer for the result string. The result will be zero-terminated if jpayne@69: * the buffer is large enough. jpayne@69: * @param destCapacity The size of the buffer (number of UChars). If it is 0, then jpayne@69: * dest may be NULL and the function will only return the length of the jpayne@69: * result without writing any of the result string (pre-flighting). jpayne@69: * @param pDestLength A pointer to receive the number of units written to the destination. If jpayne@69: * pDestLength!=NULL then *pDestLength is always set to the jpayne@69: * number of output units corresponding to the transformation of jpayne@69: * all the input units, even in case of a buffer overflow. jpayne@69: * @param src The original source string jpayne@69: * @param srcLength The length of the original string. If -1, then src must be zero-terminated. jpayne@69: * @param pErrorCode Must be a valid pointer to an error code value, jpayne@69: * which must not indicate a failure before the function call. jpayne@69: * @return The pointer to destination buffer. jpayne@69: * @stable ICU 2.0 jpayne@69: * @see u_strFromUTF8WithSub jpayne@69: * @see u_strFromUTF8Lenient jpayne@69: */ jpayne@69: U_STABLE UChar* U_EXPORT2 jpayne@69: u_strFromUTF8(UChar *dest, jpayne@69: int32_t destCapacity, jpayne@69: int32_t *pDestLength, jpayne@69: const char *src, jpayne@69: int32_t srcLength, jpayne@69: UErrorCode *pErrorCode); jpayne@69: jpayne@69: /** jpayne@69: * Convert a UTF-16 string to UTF-8. jpayne@69: * jpayne@69: * Same as u_strToUTF8() except for the additional subchar which is output for jpayne@69: * illegal input sequences, instead of stopping with the U_INVALID_CHAR_FOUND error code. jpayne@69: * With subchar==U_SENTINEL, this function behaves exactly like u_strToUTF8(). jpayne@69: * jpayne@69: * @param dest A buffer for the result string. The result will be zero-terminated if jpayne@69: * the buffer is large enough. jpayne@69: * @param destCapacity The size of the buffer (number of chars). If it is 0, then jpayne@69: * dest may be NULL and the function will only return the length of the jpayne@69: * result without writing any of the result string (pre-flighting). jpayne@69: * @param pDestLength A pointer to receive the number of units written to the destination. If jpayne@69: * pDestLength!=NULL then *pDestLength is always set to the jpayne@69: * number of output units corresponding to the transformation of jpayne@69: * all the input units, even in case of a buffer overflow. jpayne@69: * @param src The original source string jpayne@69: * @param srcLength The length of the original string. If -1, then src must be zero-terminated. jpayne@69: * @param subchar The substitution character to use in place of an illegal input sequence, jpayne@69: * or U_SENTINEL if the function is to return with U_INVALID_CHAR_FOUND instead. jpayne@69: * A substitution character can be any valid Unicode code point (up to U+10FFFF) jpayne@69: * except for surrogate code points (U+D800..U+DFFF). jpayne@69: * The recommended value is U+FFFD "REPLACEMENT CHARACTER". jpayne@69: * @param pNumSubstitutions Output parameter receiving the number of substitutions if subchar>=0. jpayne@69: * Set to 0 if no substitutions occur or subchar<0. jpayne@69: * pNumSubstitutions can be NULL. jpayne@69: * @param pErrorCode Pointer to a standard ICU error code. Its input value must jpayne@69: * pass the U_SUCCESS() test, or else the function returns jpayne@69: * immediately. Check for U_FAILURE() on output or use with jpayne@69: * function chaining. (See User Guide for details.) jpayne@69: * @return The pointer to destination buffer. jpayne@69: * @see u_strToUTF8 jpayne@69: * @see u_strFromUTF8WithSub jpayne@69: * @stable ICU 3.6 jpayne@69: */ jpayne@69: U_STABLE char* U_EXPORT2 jpayne@69: u_strToUTF8WithSub(char *dest, jpayne@69: int32_t destCapacity, jpayne@69: int32_t *pDestLength, jpayne@69: const UChar *src, jpayne@69: int32_t srcLength, jpayne@69: UChar32 subchar, int32_t *pNumSubstitutions, jpayne@69: UErrorCode *pErrorCode); jpayne@69: jpayne@69: /** jpayne@69: * Convert a UTF-8 string to UTF-16. jpayne@69: * jpayne@69: * Same as u_strFromUTF8() except for the additional subchar which is output for jpayne@69: * illegal input sequences, instead of stopping with the U_INVALID_CHAR_FOUND error code. jpayne@69: * With subchar==U_SENTINEL, this function behaves exactly like u_strFromUTF8(). jpayne@69: * jpayne@69: * @param dest A buffer for the result string. The result will be zero-terminated if jpayne@69: * the buffer is large enough. jpayne@69: * @param destCapacity The size of the buffer (number of UChars). If it is 0, then jpayne@69: * dest may be NULL and the function will only return the length of the jpayne@69: * result without writing any of the result string (pre-flighting). jpayne@69: * @param pDestLength A pointer to receive the number of units written to the destination. If jpayne@69: * pDestLength!=NULL then *pDestLength is always set to the jpayne@69: * number of output units corresponding to the transformation of jpayne@69: * all the input units, even in case of a buffer overflow. jpayne@69: * @param src The original source string jpayne@69: * @param srcLength The length of the original string. If -1, then src must be zero-terminated. jpayne@69: * @param subchar The substitution character to use in place of an illegal input sequence, jpayne@69: * or U_SENTINEL if the function is to return with U_INVALID_CHAR_FOUND instead. jpayne@69: * A substitution character can be any valid Unicode code point (up to U+10FFFF) jpayne@69: * except for surrogate code points (U+D800..U+DFFF). jpayne@69: * The recommended value is U+FFFD "REPLACEMENT CHARACTER". jpayne@69: * @param pNumSubstitutions Output parameter receiving the number of substitutions if subchar>=0. jpayne@69: * Set to 0 if no substitutions occur or subchar<0. jpayne@69: * pNumSubstitutions can be NULL. jpayne@69: * @param pErrorCode Pointer to a standard ICU error code. Its input value must jpayne@69: * pass the U_SUCCESS() test, or else the function returns jpayne@69: * immediately. Check for U_FAILURE() on output or use with jpayne@69: * function chaining. (See User Guide for details.) jpayne@69: * @return The pointer to destination buffer. jpayne@69: * @see u_strFromUTF8 jpayne@69: * @see u_strFromUTF8Lenient jpayne@69: * @see u_strToUTF8WithSub jpayne@69: * @stable ICU 3.6 jpayne@69: */ jpayne@69: U_STABLE UChar* U_EXPORT2 jpayne@69: u_strFromUTF8WithSub(UChar *dest, jpayne@69: int32_t destCapacity, jpayne@69: int32_t *pDestLength, jpayne@69: const char *src, jpayne@69: int32_t srcLength, jpayne@69: UChar32 subchar, int32_t *pNumSubstitutions, jpayne@69: UErrorCode *pErrorCode); jpayne@69: jpayne@69: /** jpayne@69: * Convert a UTF-8 string to UTF-16. jpayne@69: * jpayne@69: * Same as u_strFromUTF8() except that this function is designed to be very fast, jpayne@69: * which it achieves by being lenient about malformed UTF-8 sequences. jpayne@69: * This function is intended for use in environments where UTF-8 text is jpayne@69: * expected to be well-formed. jpayne@69: * jpayne@69: * Its semantics are: jpayne@69: * - Well-formed UTF-8 text is correctly converted to well-formed UTF-16 text. jpayne@69: * - The function will not read beyond the input string, nor write beyond jpayne@69: * the destCapacity. jpayne@69: * - Malformed UTF-8 results in "garbage" 16-bit Unicode strings which may not jpayne@69: * be well-formed UTF-16. jpayne@69: * The function will resynchronize to valid code point boundaries jpayne@69: * within a small number of code points after an illegal sequence. jpayne@69: * - Non-shortest forms are not detected and will result in "spoofing" output. jpayne@69: * jpayne@69: * For further performance improvement, if srcLength is given (>=0), jpayne@69: * then it must be destCapacity>=srcLength. jpayne@69: * jpayne@69: * There is no inverse u_strToUTF8Lenient() function because there is practically jpayne@69: * no performance gain from not checking that a UTF-16 string is well-formed. jpayne@69: * jpayne@69: * @param dest A buffer for the result string. The result will be zero-terminated if jpayne@69: * the buffer is large enough. jpayne@69: * @param destCapacity The size of the buffer (number of UChars). If it is 0, then jpayne@69: * dest may be NULL and the function will only return the length of the jpayne@69: * result without writing any of the result string (pre-flighting). jpayne@69: * Unlike for other ICU functions, if srcLength>=0 then it jpayne@69: * must be destCapacity>=srcLength. jpayne@69: * @param pDestLength A pointer to receive the number of units written to the destination. If jpayne@69: * pDestLength!=NULL then *pDestLength is always set to the jpayne@69: * number of output units corresponding to the transformation of jpayne@69: * all the input units, even in case of a buffer overflow. jpayne@69: * Unlike for other ICU functions, if srcLength>=0 but jpayne@69: * destCapacity=0. jpayne@69: * Set to 0 if no substitutions occur or subchar<0. jpayne@69: * pNumSubstitutions can be NULL. jpayne@69: * @param pErrorCode Pointer to a standard ICU error code. Its input value must jpayne@69: * pass the U_SUCCESS() test, or else the function returns jpayne@69: * immediately. Check for U_FAILURE() on output or use with jpayne@69: * function chaining. (See User Guide for details.) jpayne@69: * @return The pointer to destination buffer. jpayne@69: * @see u_strToUTF32 jpayne@69: * @see u_strFromUTF32WithSub jpayne@69: * @stable ICU 4.2 jpayne@69: */ jpayne@69: U_STABLE UChar32* U_EXPORT2 jpayne@69: u_strToUTF32WithSub(UChar32 *dest, jpayne@69: int32_t destCapacity, jpayne@69: int32_t *pDestLength, jpayne@69: const UChar *src, jpayne@69: int32_t srcLength, jpayne@69: UChar32 subchar, int32_t *pNumSubstitutions, jpayne@69: UErrorCode *pErrorCode); jpayne@69: jpayne@69: /** jpayne@69: * Convert a UTF-32 string to UTF-16. jpayne@69: * jpayne@69: * Same as u_strFromUTF32() except for the additional subchar which is output for jpayne@69: * illegal input sequences, instead of stopping with the U_INVALID_CHAR_FOUND error code. jpayne@69: * With subchar==U_SENTINEL, this function behaves exactly like u_strFromUTF32(). jpayne@69: * jpayne@69: * @param dest A buffer for the result string. The result will be zero-terminated if jpayne@69: * the buffer is large enough. jpayne@69: * @param destCapacity The size of the buffer (number of UChars). If it is 0, then jpayne@69: * dest may be NULL and the function will only return the length of the jpayne@69: * result without writing any of the result string (pre-flighting). jpayne@69: * @param pDestLength A pointer to receive the number of units written to the destination. If jpayne@69: * pDestLength!=NULL then *pDestLength is always set to the jpayne@69: * number of output units corresponding to the transformation of jpayne@69: * all the input units, even in case of a buffer overflow. jpayne@69: * @param src The original source string jpayne@69: * @param srcLength The length of the original string. If -1, then src must be zero-terminated. jpayne@69: * @param subchar The substitution character to use in place of an illegal input sequence, jpayne@69: * or U_SENTINEL if the function is to return with U_INVALID_CHAR_FOUND instead. jpayne@69: * A substitution character can be any valid Unicode code point (up to U+10FFFF) jpayne@69: * except for surrogate code points (U+D800..U+DFFF). jpayne@69: * The recommended value is U+FFFD "REPLACEMENT CHARACTER". jpayne@69: * @param pNumSubstitutions Output parameter receiving the number of substitutions if subchar>=0. jpayne@69: * Set to 0 if no substitutions occur or subchar<0. jpayne@69: * pNumSubstitutions can be NULL. jpayne@69: * @param pErrorCode Pointer to a standard ICU error code. Its input value must jpayne@69: * pass the U_SUCCESS() test, or else the function returns jpayne@69: * immediately. Check for U_FAILURE() on output or use with jpayne@69: * function chaining. (See User Guide for details.) jpayne@69: * @return The pointer to destination buffer. jpayne@69: * @see u_strFromUTF32 jpayne@69: * @see u_strToUTF32WithSub jpayne@69: * @stable ICU 4.2 jpayne@69: */ jpayne@69: U_STABLE UChar* U_EXPORT2 jpayne@69: u_strFromUTF32WithSub(UChar *dest, jpayne@69: int32_t destCapacity, jpayne@69: int32_t *pDestLength, jpayne@69: const UChar32 *src, jpayne@69: int32_t srcLength, jpayne@69: UChar32 subchar, int32_t *pNumSubstitutions, jpayne@69: UErrorCode *pErrorCode); jpayne@69: jpayne@69: /** jpayne@69: * Convert a 16-bit Unicode string to Java Modified UTF-8. jpayne@69: * See http://java.sun.com/javase/6/docs/api/java/io/DataInput.html#modified-utf-8 jpayne@69: * jpayne@69: * This function behaves according to the documentation for Java DataOutput.writeUTF() jpayne@69: * except that it does not encode the output length in the destination buffer jpayne@69: * and does not have an output length restriction. jpayne@69: * See http://java.sun.com/javase/6/docs/api/java/io/DataOutput.html#writeUTF(java.lang.String) jpayne@69: * jpayne@69: * The input string need not be well-formed UTF-16. jpayne@69: * (Therefore there is no subchar parameter.) jpayne@69: * jpayne@69: * @param dest A buffer for the result string. The result will be zero-terminated if jpayne@69: * the buffer is large enough. jpayne@69: * @param destCapacity The size of the buffer (number of chars). If it is 0, then jpayne@69: * dest may be NULL and the function will only return the length of the jpayne@69: * result without writing any of the result string (pre-flighting). jpayne@69: * @param pDestLength A pointer to receive the number of units written to the destination. If jpayne@69: * pDestLength!=NULL then *pDestLength is always set to the jpayne@69: * number of output units corresponding to the transformation of jpayne@69: * all the input units, even in case of a buffer overflow. jpayne@69: * @param src The original source string jpayne@69: * @param srcLength The length of the original string. If -1, then src must be zero-terminated. jpayne@69: * @param pErrorCode Pointer to a standard ICU error code. Its input value must jpayne@69: * pass the U_SUCCESS() test, or else the function returns jpayne@69: * immediately. Check for U_FAILURE() on output or use with jpayne@69: * function chaining. (See User Guide for details.) jpayne@69: * @return The pointer to destination buffer. jpayne@69: * @stable ICU 4.4 jpayne@69: * @see u_strToUTF8WithSub jpayne@69: * @see u_strFromJavaModifiedUTF8WithSub jpayne@69: */ jpayne@69: U_STABLE char* U_EXPORT2 jpayne@69: u_strToJavaModifiedUTF8( jpayne@69: char *dest, jpayne@69: int32_t destCapacity, jpayne@69: int32_t *pDestLength, jpayne@69: const UChar *src, jpayne@69: int32_t srcLength, jpayne@69: UErrorCode *pErrorCode); jpayne@69: jpayne@69: /** jpayne@69: * Convert a Java Modified UTF-8 string to a 16-bit Unicode string. jpayne@69: * If the input string is not well-formed and no substitution char is specified, jpayne@69: * then the U_INVALID_CHAR_FOUND error code is set. jpayne@69: * jpayne@69: * This function behaves according to the documentation for Java DataInput.readUTF() jpayne@69: * except that it takes a length parameter rather than jpayne@69: * interpreting the first two input bytes as the length. jpayne@69: * See http://java.sun.com/javase/6/docs/api/java/io/DataInput.html#readUTF() jpayne@69: * jpayne@69: * The output string may not be well-formed UTF-16. jpayne@69: * jpayne@69: * @param dest A buffer for the result string. The result will be zero-terminated if jpayne@69: * the buffer is large enough. jpayne@69: * @param destCapacity The size of the buffer (number of UChars). If it is 0, then jpayne@69: * dest may be NULL and the function will only return the length of the jpayne@69: * result without writing any of the result string (pre-flighting). jpayne@69: * @param pDestLength A pointer to receive the number of units written to the destination. If jpayne@69: * pDestLength!=NULL then *pDestLength is always set to the jpayne@69: * number of output units corresponding to the transformation of jpayne@69: * all the input units, even in case of a buffer overflow. jpayne@69: * @param src The original source string jpayne@69: * @param srcLength The length of the original string. If -1, then src must be zero-terminated. jpayne@69: * @param subchar The substitution character to use in place of an illegal input sequence, jpayne@69: * or U_SENTINEL if the function is to return with U_INVALID_CHAR_FOUND instead. jpayne@69: * A substitution character can be any valid Unicode code point (up to U+10FFFF) jpayne@69: * except for surrogate code points (U+D800..U+DFFF). jpayne@69: * The recommended value is U+FFFD "REPLACEMENT CHARACTER". jpayne@69: * @param pNumSubstitutions Output parameter receiving the number of substitutions if subchar>=0. jpayne@69: * Set to 0 if no substitutions occur or subchar<0. jpayne@69: * pNumSubstitutions can be NULL. jpayne@69: * @param pErrorCode Pointer to a standard ICU error code. Its input value must jpayne@69: * pass the U_SUCCESS() test, or else the function returns jpayne@69: * immediately. Check for U_FAILURE() on output or use with jpayne@69: * function chaining. (See User Guide for details.) jpayne@69: * @return The pointer to destination buffer. jpayne@69: * @see u_strFromUTF8WithSub jpayne@69: * @see u_strFromUTF8Lenient jpayne@69: * @see u_strToJavaModifiedUTF8 jpayne@69: * @stable ICU 4.4 jpayne@69: */ jpayne@69: U_STABLE UChar* U_EXPORT2 jpayne@69: u_strFromJavaModifiedUTF8WithSub( jpayne@69: UChar *dest, jpayne@69: int32_t destCapacity, jpayne@69: int32_t *pDestLength, jpayne@69: const char *src, jpayne@69: int32_t srcLength, jpayne@69: UChar32 subchar, int32_t *pNumSubstitutions, jpayne@69: UErrorCode *pErrorCode); jpayne@69: jpayne@69: #endif