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