2 **********************************************************************
3 * Copyright (C) 1998-2006, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 **********************************************************************
9 * Modification History:
11 * Date Name Description
12 * 12/07/98 bertrand Creation.
13 ******************************************************************************
19 #include "unicode/utypes.h"
20 #include "unicode/putil.h"
21 #include "unicode/uiter.h"
23 /** Simple declaration for u_strToTitle() to avoid including unicode/ubrk.h. @stable ICU 2.1*/
24 #ifndef UBRK_TYPEDEF_UBREAK_ITERATOR
25 # define UBRK_TYPEDEF_UBREAK_ITERATOR
26 typedef void UBreakIterator
;
31 * \brief C API: Unicode string handling functions
33 * These C API functions provide general Unicode string handling.
35 * Some functions are equivalent in name, signature, and behavior to the ANSI C <string.h>
36 * functions. (For example, they do not check for bad arguments like NULL string pointers.)
37 * In some cases, only the thread-safe variant of such a function is implemented here
40 * Other functions provide more Unicode-specific functionality like locale-specific
41 * upper/lower-casing and string comparison in code point order.
43 * ICU uses 16-bit Unicode (UTF-16) in the form of arrays of UChar code units.
44 * UTF-16 encodes each Unicode code point with either one or two UChar code units.
45 * (This is the default form of Unicode, and a forward-compatible extension of the original,
46 * fixed-width form that was known as UCS-2. UTF-16 superseded UCS-2 with Unicode 2.0
49 * Some APIs accept a 32-bit UChar32 value for a single code point.
51 * ICU also handles 16-bit Unicode text with unpaired surrogates.
52 * Such text is not well-formed UTF-16.
53 * Code-point-related functions treat unpaired surrogates as surrogate code points,
54 * i.e., as separate units.
56 * Although UTF-16 is a variable-width encoding form (like some legacy multi-byte encodings),
57 * it is much more efficient even for random access because the code unit values
58 * for single-unit characters vs. lead units vs. trail units are completely disjoint.
59 * This means that it is easy to determine character (code point) boundaries from
60 * random offsets in the string.
62 * Unicode (UTF-16) string processing is optimized for the single-unit case.
63 * Although it is important to support supplementary characters
64 * (which use pairs of lead/trail code units called "surrogates"),
65 * their occurrence is rare. Almost all characters in modern use require only
66 * a single UChar code unit (i.e., their code point values are <=0xffff).
68 * For more details see the User Guide Strings chapter (http://icu.sourceforge.net/userguide/strings.html).
69 * For a discussion of the handling of unpaired surrogates see also
70 * Jitterbug 2145 and its icu mailing list proposal on 2002-sep-18.
74 * \defgroup ustring_ustrlen
78 * Determine the length of an array of UChar.
80 * @param s The array of UChars, NULL (U+0000) terminated.
81 * @return The number of UChars in <code>chars</code>, minus the terminator.
84 U_STABLE
int32_t U_EXPORT2
85 u_strlen(const UChar
*s
);
89 * Count Unicode code points in the length UChar code units of the string.
90 * A code point may occupy either one or two UChar code units.
91 * Counting code points involves reading all code units.
93 * This functions is basically the inverse of the U16_FWD_N() macro (see utf.h).
95 * @param s The input string.
96 * @param length The number of UChar code units to be checked, or -1 to count all
97 * code points before the first NUL (U+0000).
98 * @return The number of code points in the specified code units.
101 U_STABLE
int32_t U_EXPORT2
102 u_countChar32(const UChar
*s
, int32_t length
);
105 * Check if the string contains more Unicode code points than a certain number.
106 * This is more efficient than counting all code points in the entire string
107 * and comparing that number with a threshold.
108 * This function may not need to scan the string at all if the length is known
109 * (not -1 for NUL-termination) and falls within a certain range, and
110 * never needs to count more than 'number+1' code points.
111 * Logically equivalent to (u_countChar32(s, length)>number).
112 * A Unicode code point may occupy either one or two UChar code units.
114 * @param s The input string.
115 * @param length The length of the string, or -1 if it is NUL-terminated.
116 * @param number The number of code points in the string is compared against
117 * the 'number' parameter.
118 * @return Boolean value for whether the string contains more Unicode code points
119 * than 'number'. Same as (u_countChar32(s, length)>number).
122 U_STABLE UBool U_EXPORT2
123 u_strHasMoreChar32Than(const UChar
*s
, int32_t length
, int32_t number
);
126 * Concatenate two ustrings. Appends a copy of <code>src</code>,
127 * including the null terminator, to <code>dst</code>. The initial copied
128 * character from <code>src</code> overwrites the null terminator in <code>dst</code>.
130 * @param dst The destination string.
131 * @param src The source string.
132 * @return A pointer to <code>dst</code>.
135 U_STABLE UChar
* U_EXPORT2
140 * Concatenate two ustrings.
141 * Appends at most <code>n</code> characters from <code>src</code> to <code>dst</code>.
142 * Adds a terminating NUL.
143 * If src is too long, then only <code>n-1</code> characters will be copied
144 * before the terminating NUL.
145 * If <code>n<=0</code> then dst is not modified.
147 * @param dst The destination string.
148 * @param src The source string.
149 * @param n The maximum number of characters to compare.
150 * @return A pointer to <code>dst</code>.
153 U_STABLE UChar
* U_EXPORT2
154 u_strncat(UChar
*dst
,
159 * Find the first occurrence of a substring in a string.
160 * The substring is found at code point boundaries.
161 * That means that if the substring begins with
162 * a trail surrogate or ends with a lead surrogate,
163 * then it is found only if these surrogates stand alone in the text.
164 * Otherwise, the substring edge units would be matched against
165 * halves of surrogate pairs.
167 * @param s The string to search (NUL-terminated).
168 * @param substring The substring to find (NUL-terminated).
169 * @return A pointer to the first occurrence of <code>substring</code> in <code>s</code>,
170 * or <code>s</code> itself if the <code>substring</code> is empty,
171 * or <code>NULL</code> if <code>substring</code> is not in <code>s</code>.
175 * @see u_strFindFirst
178 U_STABLE UChar
* U_EXPORT2
179 u_strstr(const UChar
*s
, const UChar
*substring
);
182 * Find the first occurrence of a substring in a string.
183 * The substring is found at code point boundaries.
184 * That means that if the substring begins with
185 * a trail surrogate or ends with a lead surrogate,
186 * then it is found only if these surrogates stand alone in the text.
187 * Otherwise, the substring edge units would be matched against
188 * halves of surrogate pairs.
190 * @param s The string to search.
191 * @param length The length of s (number of UChars), or -1 if it is NUL-terminated.
192 * @param substring The substring to find (NUL-terminated).
193 * @param subLength The length of substring (number of UChars), or -1 if it is NUL-terminated.
194 * @return A pointer to the first occurrence of <code>substring</code> in <code>s</code>,
195 * or <code>s</code> itself if the <code>substring</code> is empty,
196 * or <code>NULL</code> if <code>substring</code> is not in <code>s</code>.
202 U_STABLE UChar
* U_EXPORT2
203 u_strFindFirst(const UChar
*s
, int32_t length
, const UChar
*substring
, int32_t subLength
);
206 * Find the first occurrence of a BMP code point in a string.
207 * A surrogate code point is found only if its match in the text is not
208 * part of a surrogate pair.
209 * A NUL character is found at the string terminator.
211 * @param s The string to search (NUL-terminated).
212 * @param c The BMP code point to find.
213 * @return A pointer to the first occurrence of <code>c</code> in <code>s</code>
214 * or <code>NULL</code> if <code>c</code> is not in <code>s</code>.
220 * @see u_strFindFirst
222 U_STABLE UChar
* U_EXPORT2
223 u_strchr(const UChar
*s
, UChar c
);
226 * Find the first occurrence of a code point in a string.
227 * A surrogate code point is found only if its match in the text is not
228 * part of a surrogate pair.
229 * A NUL character is found at the string terminator.
231 * @param s The string to search (NUL-terminated).
232 * @param c The code point to find.
233 * @return A pointer to the first occurrence of <code>c</code> in <code>s</code>
234 * or <code>NULL</code> if <code>c</code> is not in <code>s</code>.
240 * @see u_strFindFirst
242 U_STABLE UChar
* U_EXPORT2
243 u_strchr32(const UChar
*s
, UChar32 c
);
246 * Find the last occurrence of a substring in a string.
247 * The substring is found at code point boundaries.
248 * That means that if the substring begins with
249 * a trail surrogate or ends with a lead surrogate,
250 * then it is found only if these surrogates stand alone in the text.
251 * Otherwise, the substring edge units would be matched against
252 * halves of surrogate pairs.
254 * @param s The string to search (NUL-terminated).
255 * @param substring The substring to find (NUL-terminated).
256 * @return A pointer to the last occurrence of <code>substring</code> in <code>s</code>,
257 * or <code>s</code> itself if the <code>substring</code> is empty,
258 * or <code>NULL</code> if <code>substring</code> is not in <code>s</code>.
262 * @see u_strFindFirst
265 U_STABLE UChar
* U_EXPORT2
266 u_strrstr(const UChar
*s
, const UChar
*substring
);
269 * Find the last occurrence of a substring in a string.
270 * The substring is found at code point boundaries.
271 * That means that if the substring begins with
272 * a trail surrogate or ends with a lead surrogate,
273 * then it is found only if these surrogates stand alone in the text.
274 * Otherwise, the substring edge units would be matched against
275 * halves of surrogate pairs.
277 * @param s The string to search.
278 * @param length The length of s (number of UChars), or -1 if it is NUL-terminated.
279 * @param substring The substring to find (NUL-terminated).
280 * @param subLength The length of substring (number of UChars), or -1 if it is NUL-terminated.
281 * @return A pointer to the last occurrence of <code>substring</code> in <code>s</code>,
282 * or <code>s</code> itself if the <code>substring</code> is empty,
283 * or <code>NULL</code> if <code>substring</code> is not in <code>s</code>.
289 U_STABLE UChar
* U_EXPORT2
290 u_strFindLast(const UChar
*s
, int32_t length
, const UChar
*substring
, int32_t subLength
);
293 * Find the last occurrence of a BMP code point in a string.
294 * A surrogate code point is found only if its match in the text is not
295 * part of a surrogate pair.
296 * A NUL character is found at the string terminator.
298 * @param s The string to search (NUL-terminated).
299 * @param c The BMP code point to find.
300 * @return A pointer to the last occurrence of <code>c</code> in <code>s</code>
301 * or <code>NULL</code> if <code>c</code> is not in <code>s</code>.
309 U_STABLE UChar
* U_EXPORT2
310 u_strrchr(const UChar
*s
, UChar c
);
313 * Find the last occurrence of a code point in a string.
314 * A surrogate code point is found only if its match in the text is not
315 * part of a surrogate pair.
316 * A NUL character is found at the string terminator.
318 * @param s The string to search (NUL-terminated).
319 * @param c The code point to find.
320 * @return A pointer to the last occurrence of <code>c</code> in <code>s</code>
321 * or <code>NULL</code> if <code>c</code> is not in <code>s</code>.
329 U_STABLE UChar
* U_EXPORT2
330 u_strrchr32(const UChar
*s
, UChar32 c
);
333 * Locates the first occurrence in the string <code>string</code> of any of the characters
334 * in the string <code>matchSet</code>.
335 * Works just like C's strpbrk but with Unicode.
337 * @param string The string in which to search, NUL-terminated.
338 * @param matchSet A NUL-terminated string defining a set of code points
339 * for which to search in the text string.
340 * @return A pointer to the character in <code>string</code> that matches one of the
341 * characters in <code>matchSet</code>, or NULL if no such character is found.
344 U_STABLE UChar
* U_EXPORT2
345 u_strpbrk(const UChar
*string
, const UChar
*matchSet
);
348 * Returns the number of consecutive characters in <code>string</code>,
349 * beginning with the first, that do not occur somewhere in <code>matchSet</code>.
350 * Works just like C's strcspn but with Unicode.
352 * @param string The string in which to search, NUL-terminated.
353 * @param matchSet A NUL-terminated string defining a set of code points
354 * for which to search in the text string.
355 * @return The number of initial characters in <code>string</code> that do not
356 * occur in <code>matchSet</code>.
360 U_STABLE
int32_t U_EXPORT2
361 u_strcspn(const UChar
*string
, const UChar
*matchSet
);
364 * Returns the number of consecutive characters in <code>string</code>,
365 * beginning with the first, that occur somewhere in <code>matchSet</code>.
366 * Works just like C's strspn but with Unicode.
368 * @param string The string in which to search, NUL-terminated.
369 * @param matchSet A NUL-terminated string defining a set of code points
370 * for which to search in the text string.
371 * @return The number of initial characters in <code>string</code> that do
372 * occur in <code>matchSet</code>.
376 U_STABLE
int32_t U_EXPORT2
377 u_strspn(const UChar
*string
, const UChar
*matchSet
);
380 * The string tokenizer API allows an application to break a string into
381 * tokens. Unlike strtok(), the saveState (the current pointer within the
382 * original string) is maintained in saveState. In the first call, the
383 * argument src is a pointer to the string. In subsequent calls to
384 * return successive tokens of that string, src must be specified as
385 * NULL. The value saveState is set by this function to maintain the
386 * function's position within the string, and on each subsequent call
387 * you must give this argument the same variable. This function does
388 * handle surrogate pairs. This function is similar to the strtok_r()
389 * the POSIX Threads Extension (1003.1c-1995) version.
391 * @param src String containing token(s). This string will be modified.
392 * After the first call to u_strtok_r(), this argument must
393 * be NULL to get to the next token.
394 * @param delim Set of delimiter characters (Unicode code points).
395 * @param saveState The current pointer within the original string,
396 * which is set by this function. The saveState
397 * parameter should the address of a local variable of type
398 * UChar *. (i.e. defined "Uhar *myLocalSaveState" and use
399 * &myLocalSaveState for this parameter).
400 * @return A pointer to the next token found in src, or NULL
401 * when there are no more tokens.
404 U_STABLE UChar
* U_EXPORT2
405 u_strtok_r(UChar
*src
,
410 * Compare two Unicode strings for bitwise equality (code unit order).
412 * @param s1 A string to compare.
413 * @param s2 A string to compare.
414 * @return 0 if <code>s1</code> and <code>s2</code> are bitwise equal; a negative
415 * value if <code>s1</code> is bitwise less than <code>s2,</code>; a positive
416 * value if <code>s1</code> is bitwise greater than <code>s2</code>.
419 U_STABLE
int32_t U_EXPORT2
420 u_strcmp(const UChar
*s1
,
424 * Compare two Unicode strings in code point order.
425 * See u_strCompare for details.
427 * @param s1 A string to compare.
428 * @param s2 A string to compare.
429 * @return a negative/zero/positive integer corresponding to whether
430 * the first string is less than/equal to/greater than the second one
431 * in code point order
434 U_STABLE
int32_t U_EXPORT2
435 u_strcmpCodePointOrder(const UChar
*s1
, const UChar
*s2
);
438 * Compare two Unicode strings (binary order).
440 * The comparison can be done in code unit order or in code point order.
441 * They differ only in UTF-16 when
442 * comparing supplementary code points (U+10000..U+10ffff)
443 * to BMP code points near the end of the BMP (i.e., U+e000..U+ffff).
444 * In code unit order, high BMP code points sort after supplementary code points
445 * because they are stored as pairs of surrogates which are at U+d800..U+dfff.
447 * This functions works with strings of different explicitly specified lengths
448 * unlike the ANSI C-like u_strcmp() and u_memcmp() etc.
449 * NUL-terminated strings are possible with length arguments of -1.
451 * @param s1 First source string.
452 * @param length1 Length of first source string, or -1 if NUL-terminated.
454 * @param s2 Second source string.
455 * @param length2 Length of second source string, or -1 if NUL-terminated.
457 * @param codePointOrder Choose between code unit order (FALSE)
458 * and code point order (TRUE).
460 * @return <0 or 0 or >0 as usual for string comparisons
464 U_STABLE
int32_t U_EXPORT2
465 u_strCompare(const UChar
*s1
, int32_t length1
,
466 const UChar
*s2
, int32_t length2
,
467 UBool codePointOrder
);
470 * Compare two Unicode strings (binary order)
471 * as presented by UCharIterator objects.
472 * Works otherwise just like u_strCompare().
474 * Both iterators are reset to their start positions.
475 * When the function returns, it is undefined where the iterators
478 * @param iter1 First source string iterator.
479 * @param iter2 Second source string iterator.
480 * @param codePointOrder Choose between code unit order (FALSE)
481 * and code point order (TRUE).
483 * @return <0 or 0 or >0 as usual for string comparisons
489 U_STABLE
int32_t U_EXPORT2
490 u_strCompareIter(UCharIterator
*iter1
, UCharIterator
*iter2
, UBool codePointOrder
);
492 #ifndef U_COMPARE_CODE_POINT_ORDER
493 /* see also unistr.h and unorm.h */
495 * Option bit for u_strCaseCompare, u_strcasecmp, unorm_compare, etc:
496 * Compare strings in code point order instead of code unit order.
499 #define U_COMPARE_CODE_POINT_ORDER 0x8000
503 * Compare two strings case-insensitively using full case folding.
504 * This is equivalent to
505 * u_strCompare(u_strFoldCase(s1, options),
506 * u_strFoldCase(s2, options),
507 * (options&U_COMPARE_CODE_POINT_ORDER)!=0).
509 * The comparison can be done in UTF-16 code unit order or in code point order.
510 * They differ only when comparing supplementary code points (U+10000..U+10ffff)
511 * to BMP code points near the end of the BMP (i.e., U+e000..U+ffff).
512 * In code unit order, high BMP code points sort after supplementary code points
513 * because they are stored as pairs of surrogates which are at U+d800..U+dfff.
515 * This functions works with strings of different explicitly specified lengths
516 * unlike the ANSI C-like u_strcmp() and u_memcmp() etc.
517 * NUL-terminated strings are possible with length arguments of -1.
519 * @param s1 First source string.
520 * @param length1 Length of first source string, or -1 if NUL-terminated.
522 * @param s2 Second source string.
523 * @param length2 Length of second source string, or -1 if NUL-terminated.
525 * @param options A bit set of options:
526 * - U_FOLD_CASE_DEFAULT or 0 is used for default options:
527 * Comparison in code unit order with default case folding.
529 * - U_COMPARE_CODE_POINT_ORDER
530 * Set to choose code point order instead of code unit order
531 * (see u_strCompare for details).
533 * - U_FOLD_CASE_EXCLUDE_SPECIAL_I
535 * @param pErrorCode Must be a valid pointer to an error code value,
536 * which must not indicate a failure before the function call.
538 * @return <0 or 0 or >0 as usual for string comparisons
542 U_STABLE
int32_t U_EXPORT2
543 u_strCaseCompare(const UChar
*s1
, int32_t length1
,
544 const UChar
*s2
, int32_t length2
,
546 UErrorCode
*pErrorCode
);
549 * Compare two ustrings for bitwise equality.
550 * Compares at most <code>n</code> characters.
552 * @param ucs1 A string to compare.
553 * @param ucs2 A string to compare.
554 * @param n The maximum number of characters to compare.
555 * @return 0 if <code>s1</code> and <code>s2</code> are bitwise equal; a negative
556 * value if <code>s1</code> is bitwise less than <code>s2</code>; a positive
557 * value if <code>s1</code> is bitwise greater than <code>s2</code>.
560 U_STABLE
int32_t U_EXPORT2
561 u_strncmp(const UChar
*ucs1
,
566 * Compare two Unicode strings in code point order.
567 * This is different in UTF-16 from u_strncmp() if supplementary characters are present.
568 * For details, see u_strCompare().
570 * @param s1 A string to compare.
571 * @param s2 A string to compare.
572 * @param n The maximum number of characters to compare.
573 * @return a negative/zero/positive integer corresponding to whether
574 * the first string is less than/equal to/greater than the second one
575 * in code point order
578 U_STABLE
int32_t U_EXPORT2
579 u_strncmpCodePointOrder(const UChar
*s1
, const UChar
*s2
, int32_t n
);
582 * Compare two strings case-insensitively using full case folding.
583 * This is equivalent to u_strcmp(u_strFoldCase(s1, options), u_strFoldCase(s2, options)).
585 * @param s1 A string to compare.
586 * @param s2 A string to compare.
587 * @param options A bit set of options:
588 * - U_FOLD_CASE_DEFAULT or 0 is used for default options:
589 * Comparison in code unit order with default case folding.
591 * - U_COMPARE_CODE_POINT_ORDER
592 * Set to choose code point order instead of code unit order
593 * (see u_strCompare for details).
595 * - U_FOLD_CASE_EXCLUDE_SPECIAL_I
597 * @return A negative, zero, or positive integer indicating the comparison result.
600 U_STABLE
int32_t U_EXPORT2
601 u_strcasecmp(const UChar
*s1
, const UChar
*s2
, uint32_t options
);
604 * Compare two strings case-insensitively using full case folding.
605 * This is equivalent to u_strcmp(u_strFoldCase(s1, at most n, options),
606 * u_strFoldCase(s2, at most n, options)).
608 * @param s1 A string to compare.
609 * @param s2 A string to compare.
610 * @param n The maximum number of characters each string to case-fold and then compare.
611 * @param options A bit set of options:
612 * - U_FOLD_CASE_DEFAULT or 0 is used for default options:
613 * Comparison in code unit order with default case folding.
615 * - U_COMPARE_CODE_POINT_ORDER
616 * Set to choose code point order instead of code unit order
617 * (see u_strCompare for details).
619 * - U_FOLD_CASE_EXCLUDE_SPECIAL_I
621 * @return A negative, zero, or positive integer indicating the comparison result.
624 U_STABLE
int32_t U_EXPORT2
625 u_strncasecmp(const UChar
*s1
, const UChar
*s2
, int32_t n
, uint32_t options
);
628 * Compare two strings case-insensitively using full case folding.
629 * This is equivalent to u_strcmp(u_strFoldCase(s1, n, options),
630 * u_strFoldCase(s2, n, options)).
632 * @param s1 A string to compare.
633 * @param s2 A string to compare.
634 * @param length The number of characters in each string to case-fold and then compare.
635 * @param options A bit set of options:
636 * - U_FOLD_CASE_DEFAULT or 0 is used for default options:
637 * Comparison in code unit order with default case folding.
639 * - U_COMPARE_CODE_POINT_ORDER
640 * Set to choose code point order instead of code unit order
641 * (see u_strCompare for details).
643 * - U_FOLD_CASE_EXCLUDE_SPECIAL_I
645 * @return A negative, zero, or positive integer indicating the comparison result.
648 U_STABLE
int32_t U_EXPORT2
649 u_memcasecmp(const UChar
*s1
, const UChar
*s2
, int32_t length
, uint32_t options
);
652 * Copy a ustring. Adds a null terminator.
654 * @param dst The destination string.
655 * @param src The source string.
656 * @return A pointer to <code>dst</code>.
659 U_STABLE UChar
* U_EXPORT2
665 * Copies at most <code>n</code> characters. The result will be null terminated
666 * if the length of <code>src</code> is less than <code>n</code>.
668 * @param dst The destination string.
669 * @param src The source string.
670 * @param n The maximum number of characters to copy.
671 * @return A pointer to <code>dst</code>.
674 U_STABLE UChar
* U_EXPORT2
675 u_strncpy(UChar
*dst
,
679 #if !UCONFIG_NO_CONVERSION
682 * Copy a byte string encoded in the default codepage to a ustring.
683 * Adds a null terminator.
684 * Performs a host byte to UChar conversion
686 * @param dst The destination string.
687 * @param src The source string.
688 * @return A pointer to <code>dst</code>.
691 U_STABLE UChar
* U_EXPORT2
u_uastrcpy(UChar
*dst
,
695 * Copy a byte string encoded in the default codepage to a ustring.
696 * Copies at most <code>n</code> characters. The result will be null terminated
697 * if the length of <code>src</code> is less than <code>n</code>.
698 * Performs a host byte to UChar conversion
700 * @param dst The destination string.
701 * @param src The source string.
702 * @param n The maximum number of characters to copy.
703 * @return A pointer to <code>dst</code>.
706 U_STABLE UChar
* U_EXPORT2
u_uastrncpy(UChar
*dst
,
711 * Copy ustring to a byte string encoded in the default codepage.
712 * Adds a null terminator.
713 * Performs a UChar to host byte conversion
715 * @param dst The destination string.
716 * @param src The source string.
717 * @return A pointer to <code>dst</code>.
720 U_STABLE
char* U_EXPORT2
u_austrcpy(char *dst
,
724 * Copy ustring to a byte string encoded in the default codepage.
725 * Copies at most <code>n</code> characters. The result will be null terminated
726 * if the length of <code>src</code> is less than <code>n</code>.
727 * Performs a UChar to host byte conversion
729 * @param dst The destination string.
730 * @param src The source string.
731 * @param n The maximum number of characters to copy.
732 * @return A pointer to <code>dst</code>.
735 U_STABLE
char* U_EXPORT2
u_austrncpy(char *dst
,
742 * Synonym for memcpy(), but with UChars only.
743 * @param dest The destination string
744 * @param src The source string
745 * @param count The number of characters to copy
746 * @return A pointer to <code>dest</code>
749 U_STABLE UChar
* U_EXPORT2
750 u_memcpy(UChar
*dest
, const UChar
*src
, int32_t count
);
753 * Synonym for memmove(), but with UChars only.
754 * @param dest The destination string
755 * @param src The source string
756 * @param count The number of characters to move
757 * @return A pointer to <code>dest</code>
760 U_STABLE UChar
* U_EXPORT2
761 u_memmove(UChar
*dest
, const UChar
*src
, int32_t count
);
764 * Initialize <code>count</code> characters of <code>dest</code> to <code>c</code>.
766 * @param dest The destination string.
767 * @param c The character to initialize the string.
768 * @param count The maximum number of characters to set.
769 * @return A pointer to <code>dest</code>.
772 U_STABLE UChar
* U_EXPORT2
773 u_memset(UChar
*dest
, UChar c
, int32_t count
);
776 * Compare the first <code>count</code> UChars of each buffer.
778 * @param buf1 The first string to compare.
779 * @param buf2 The second string to compare.
780 * @param count The maximum number of UChars to compare.
781 * @return When buf1 < buf2, a negative number is returned.
782 * When buf1 == buf2, 0 is returned.
783 * When buf1 > buf2, a positive number is returned.
786 U_STABLE
int32_t U_EXPORT2
787 u_memcmp(const UChar
*buf1
, const UChar
*buf2
, int32_t count
);
790 * Compare two Unicode strings in code point order.
791 * This is different in UTF-16 from u_memcmp() if supplementary characters are present.
792 * For details, see u_strCompare().
794 * @param s1 A string to compare.
795 * @param s2 A string to compare.
796 * @param count The maximum number of characters to compare.
797 * @return a negative/zero/positive integer corresponding to whether
798 * the first string is less than/equal to/greater than the second one
799 * in code point order
802 U_STABLE
int32_t U_EXPORT2
803 u_memcmpCodePointOrder(const UChar
*s1
, const UChar
*s2
, int32_t count
);
806 * Find the first occurrence of a BMP code point in a string.
807 * A surrogate code point is found only if its match in the text is not
808 * part of a surrogate pair.
809 * A NUL character is found at the string terminator.
811 * @param s The string to search (contains <code>count</code> UChars).
812 * @param c The BMP code point to find.
813 * @param count The length of the string.
814 * @return A pointer to the first occurrence of <code>c</code> in <code>s</code>
815 * or <code>NULL</code> if <code>c</code> is not in <code>s</code>.
820 * @see u_strFindFirst
822 U_STABLE UChar
* U_EXPORT2
823 u_memchr(const UChar
*s
, UChar c
, int32_t count
);
826 * Find the first occurrence of a code point in a string.
827 * A surrogate code point is found only if its match in the text is not
828 * part of a surrogate pair.
829 * A NUL character is found at the string terminator.
831 * @param s The string to search (contains <code>count</code> UChars).
832 * @param c The code point to find.
833 * @param count The length of the string.
834 * @return A pointer to the first occurrence of <code>c</code> in <code>s</code>
835 * or <code>NULL</code> if <code>c</code> is not in <code>s</code>.
840 * @see u_strFindFirst
842 U_STABLE UChar
* U_EXPORT2
843 u_memchr32(const UChar
*s
, UChar32 c
, int32_t count
);
846 * Find the last occurrence of a BMP code point in a string.
847 * A surrogate code point is found only if its match in the text is not
848 * part of a surrogate pair.
849 * A NUL character is found at the string terminator.
851 * @param s The string to search (contains <code>count</code> UChars).
852 * @param c The BMP code point to find.
853 * @param count The length of the string.
854 * @return A pointer to the last occurrence of <code>c</code> in <code>s</code>
855 * or <code>NULL</code> if <code>c</code> is not in <code>s</code>.
862 U_STABLE UChar
* U_EXPORT2
863 u_memrchr(const UChar
*s
, UChar c
, int32_t count
);
866 * Find the last occurrence of a code point in a string.
867 * A surrogate code point is found only if its match in the text is not
868 * part of a surrogate pair.
869 * A NUL character is found at the string terminator.
871 * @param s The string to search (contains <code>count</code> UChars).
872 * @param c The code point to find.
873 * @param count The length of the string.
874 * @return A pointer to the last occurrence of <code>c</code> in <code>s</code>
875 * or <code>NULL</code> if <code>c</code> is not in <code>s</code>.
882 U_STABLE UChar
* U_EXPORT2
883 u_memrchr32(const UChar
*s
, UChar32 c
, int32_t count
);
886 * Unicode String literals in C.
887 * We need one macro to declare a variable for the string
888 * and to statically preinitialize it if possible,
889 * and a second macro to dynamically intialize such a string variable if necessary.
891 * The macros are defined for maximum performance.
892 * They work only for strings that contain "invariant characters", i.e.,
893 * only latin letters, digits, and some punctuation.
894 * See utypes.h for details.
896 * A pair of macros for a single string must be used with the same
898 * The string parameter must be a C string literal.
899 * The length of the string, not including the terminating
900 * <code>NUL</code>, must be specified as a constant.
901 * The U_STRING_DECL macro should be invoked exactly once for one
902 * such string variable before it is used.
906 * U_STRING_DECL(ustringVar1, "Quick-Fox 2", 11);
907 * U_STRING_DECL(ustringVar2, "jumps 5%", 8);
908 * static UBool didInit=FALSE;
910 * int32_t function() {
912 * U_STRING_INIT(ustringVar1, "Quick-Fox 2", 11);
913 * U_STRING_INIT(ustringVar2, "jumps 5%", 8);
916 * return u_strcmp(ustringVar1, ustringVar2);
921 #if U_SIZEOF_WCHAR_T==U_SIZEOF_UCHAR && (U_CHARSET_FAMILY==U_ASCII_FAMILY || (U_SIZEOF_UCHAR == 2 && defined(U_WCHAR_IS_UTF16)))
922 # define U_STRING_DECL(var, cs, length) static const wchar_t var[(length)+1]={ L ## cs }
923 /**@stable ICU 2.0 */
924 # define U_STRING_INIT(var, cs, length)
925 #elif U_SIZEOF_UCHAR==1 && U_CHARSET_FAMILY==U_ASCII_FAMILY
926 # define U_STRING_DECL(var, cs, length) static const UChar var[(length)+1]={ (const UChar *)cs }
927 /**@stable ICU 2.0 */
928 # define U_STRING_INIT(var, cs, length)
930 # define U_STRING_DECL(var, cs, length) static UChar var[(length)+1]
931 /**@stable ICU 2.0 */
932 # define U_STRING_INIT(var, cs, length) u_charsToUChars(cs, var, length+1)
936 * Unescape a string of characters and write the resulting
937 * Unicode characters to the destination buffer. The following escape
938 * sequences are recognized:
940 * \\uhhhh 4 hex digits; h in [0-9A-Fa-f]
941 * \\Uhhhhhhhh 8 hex digits
942 * \\xhh 1-2 hex digits
943 * \\x{h...} 1-8 hex digits
944 * \\ooo 1-3 octal digits; o in [0-7]
945 * \\cX control-X; X is masked with 0x1F
947 * as well as the standard ANSI C escapes:
949 * \\a => U+0007, \\b => U+0008, \\t => U+0009, \\n => U+000A,
950 * \\v => U+000B, \\f => U+000C, \\r => U+000D, \\e => U+001B,
951 * \\" => U+0022, \\' => U+0027, \\? => U+003F, \\\\ => U+005C
953 * Anything else following a backslash is generically escaped. For
954 * example, "[a\\-z]" returns "[a-z]".
956 * If an escape sequence is ill-formed, this method returns an empty
957 * string. An example of an ill-formed sequence is "\\u" followed by
958 * fewer than 4 hex digits.
960 * The above characters are recognized in the compiler's codepage,
961 * that is, they are coded as 'u', '\\', etc. Characters that are
962 * not parts of escape sequences are converted using u_charsToUChars().
964 * This function is similar to UnicodeString::unescape() but not
965 * identical to it. The latter takes a source UnicodeString, so it
966 * does escape recognition but no conversion.
968 * @param src a zero-terminated string of invariant characters
969 * @param dest pointer to buffer to receive converted and unescaped
970 * text and, if there is room, a zero terminator. May be NULL for
971 * preflighting, in which case no UChars will be written, but the
972 * return value will still be valid. On error, an empty string is
973 * stored here (if possible).
974 * @param destCapacity the number of UChars that may be written at
975 * dest. Ignored if dest == NULL.
976 * @return the length of unescaped string.
978 * @see UnicodeString#unescape()
979 * @see UnicodeString#unescapeAt()
982 U_STABLE
int32_t U_EXPORT2
983 u_unescape(const char *src
,
984 UChar
*dest
, int32_t destCapacity
);
988 * Callback function for u_unescapeAt() that returns a character of
989 * the source text given an offset and a context pointer. The context
990 * pointer will be whatever is passed into u_unescapeAt().
992 * @param offset pointer to the offset that will be passed to u_unescapeAt().
993 * @param context an opaque pointer passed directly into u_unescapeAt()
994 * @return the character represented by the escape sequence at
999 typedef UChar (U_CALLCONV
*UNESCAPE_CHAR_AT
)(int32_t offset
, void *context
);
1003 * Unescape a single sequence. The character at offset-1 is assumed
1004 * (without checking) to be a backslash. This method takes a callback
1005 * pointer to a function that returns the UChar at a given offset. By
1006 * varying this callback, ICU functions are able to unescape char*
1007 * strings, UnicodeString objects, and UFILE pointers.
1009 * If offset is out of range, or if the escape sequence is ill-formed,
1010 * (UChar32)0xFFFFFFFF is returned. See documentation of u_unescape()
1011 * for a list of recognized sequences.
1013 * @param charAt callback function that returns a UChar of the source
1014 * text given an offset and a context pointer.
1015 * @param offset pointer to the offset that will be passed to charAt.
1016 * The offset value will be updated upon return to point after the
1017 * last parsed character of the escape sequence. On error the offset
1019 * @param length the number of characters in the source text. The
1020 * last character of the source text is considered to be at offset
1022 * @param context an opaque pointer passed directly into charAt.
1023 * @return the character represented by the escape sequence at
1024 * offset, or (UChar32)0xFFFFFFFF on error.
1026 * @see UnicodeString#unescape()
1027 * @see UnicodeString#unescapeAt()
1030 U_STABLE UChar32 U_EXPORT2
1031 u_unescapeAt(UNESCAPE_CHAR_AT charAt
,
1037 * Uppercase the characters in a string.
1038 * Casing is locale-dependent and context-sensitive.
1039 * The result may be longer or shorter than the original.
1040 * The source string and the destination buffer are allowed to overlap.
1042 * @param dest A buffer for the result string. The result will be zero-terminated if
1043 * the buffer is large enough.
1044 * @param destCapacity The size of the buffer (number of UChars). If it is 0, then
1045 * dest may be NULL and the function will only return the length of the result
1046 * without writing any of the result string.
1047 * @param src The original string
1048 * @param srcLength The length of the original string. If -1, then src must be zero-terminated.
1049 * @param locale The locale to consider, or "" for the root locale or NULL for the default locale.
1050 * @param pErrorCode Must be a valid pointer to an error code value,
1051 * which must not indicate a failure before the function call.
1052 * @return The length of the result string. It may be greater than destCapacity. In that case,
1053 * only some of the result was written to the destination buffer.
1056 U_STABLE
int32_t U_EXPORT2
1057 u_strToUpper(UChar
*dest
, int32_t destCapacity
,
1058 const UChar
*src
, int32_t srcLength
,
1060 UErrorCode
*pErrorCode
);
1063 * Lowercase the characters in a string.
1064 * Casing is locale-dependent and context-sensitive.
1065 * The result may be longer or shorter than the original.
1066 * The source string and the destination buffer are allowed to overlap.
1068 * @param dest A buffer for the result string. The result will be zero-terminated if
1069 * the buffer is large enough.
1070 * @param destCapacity The size of the buffer (number of UChars). If it is 0, then
1071 * dest may be NULL and the function will only return the length of the result
1072 * without writing any of the result string.
1073 * @param src The original string
1074 * @param srcLength The length of the original string. If -1, then src must be zero-terminated.
1075 * @param locale The locale to consider, or "" for the root locale or NULL for the default locale.
1076 * @param pErrorCode Must be a valid pointer to an error code value,
1077 * which must not indicate a failure before the function call.
1078 * @return The length of the result string. It may be greater than destCapacity. In that case,
1079 * only some of the result was written to the destination buffer.
1082 U_STABLE
int32_t U_EXPORT2
1083 u_strToLower(UChar
*dest
, int32_t destCapacity
,
1084 const UChar
*src
, int32_t srcLength
,
1086 UErrorCode
*pErrorCode
);
1088 #if !UCONFIG_NO_BREAK_ITERATION
1091 * Titlecase a string.
1092 * Casing is locale-dependent and context-sensitive.
1093 * Titlecasing uses a break iterator to find the first characters of words
1094 * that are to be titlecased. It titlecases those characters and lowercases
1097 * The titlecase break iterator can be provided to customize for arbitrary
1098 * styles, using rules and dictionaries beyond the standard iterators.
1099 * It may be more efficient to always provide an iterator to avoid
1100 * opening and closing one for each string.
1101 * The standard titlecase iterator for the root locale implements the
1102 * algorithm of Unicode TR 21.
1104 * This function uses only the first() and next() methods of the
1105 * provided break iterator.
1107 * The result may be longer or shorter than the original.
1108 * The source string and the destination buffer are allowed to overlap.
1110 * @param dest A buffer for the result string. The result will be zero-terminated if
1111 * the buffer is large enough.
1112 * @param destCapacity The size of the buffer (number of UChars). If it is 0, then
1113 * dest may be NULL and the function will only return the length of the result
1114 * without writing any of the result string.
1115 * @param src The original string
1116 * @param srcLength The length of the original string. If -1, then src must be zero-terminated.
1117 * @param titleIter A break iterator to find the first characters of words
1118 * that are to be titlecased.
1119 * If none is provided (NULL), then a standard titlecase
1120 * break iterator is opened.
1121 * @param locale The locale to consider, or "" for the root locale or NULL for the default locale.
1122 * @param pErrorCode Must be a valid pointer to an error code value,
1123 * which must not indicate a failure before the function call.
1124 * @return The length of the result string. It may be greater than destCapacity. In that case,
1125 * only some of the result was written to the destination buffer.
1128 U_STABLE
int32_t U_EXPORT2
1129 u_strToTitle(UChar
*dest
, int32_t destCapacity
,
1130 const UChar
*src
, int32_t srcLength
,
1131 UBreakIterator
*titleIter
,
1133 UErrorCode
*pErrorCode
);
1138 * Case-fold the characters in a string.
1139 * Case-folding is locale-independent and not context-sensitive,
1140 * but there is an option for whether to include or exclude mappings for dotted I
1141 * and dotless i that are marked with 'I' in CaseFolding.txt.
1142 * The result may be longer or shorter than the original.
1143 * The source string and the destination buffer are allowed to overlap.
1145 * @param dest A buffer for the result string. The result will be zero-terminated if
1146 * the buffer is large enough.
1147 * @param destCapacity The size of the buffer (number of UChars). If it is 0, then
1148 * dest may be NULL and the function will only return the length of the result
1149 * without writing any of the result string.
1150 * @param src The original string
1151 * @param srcLength The length of the original string. If -1, then src must be zero-terminated.
1152 * @param options Either U_FOLD_CASE_DEFAULT or U_FOLD_CASE_EXCLUDE_SPECIAL_I
1153 * @param pErrorCode Must be a valid pointer to an error code value,
1154 * which must not indicate a failure before the function call.
1155 * @return The length of the result string. It may be greater than destCapacity. In that case,
1156 * only some of the result was written to the destination buffer.
1159 U_STABLE
int32_t U_EXPORT2
1160 u_strFoldCase(UChar
*dest
, int32_t destCapacity
,
1161 const UChar
*src
, int32_t srcLength
,
1163 UErrorCode
*pErrorCode
);
1165 #if defined(U_WCHAR_IS_UTF16) || defined(U_WCHAR_IS_UTF32) || !UCONFIG_NO_CONVERSION
1167 * Converts a sequence of UChars to wchar_t units.
1169 * @param dest A buffer for the result string. The result will be zero-terminated if
1170 * the buffer is large enough.
1171 * @param destCapacity The size of the buffer (number of wchar_t's). If it is 0, then
1172 * dest may be NULL and the function will only return the length of the
1173 * result without writing any of the result string (pre-flighting).
1174 * @param pDestLength A pointer to receive the number of units written to the destination. If
1175 * pDestLength!=NULL then *pDestLength is always set to the
1176 * number of output units corresponding to the transformation of
1177 * all the input units, even in case of a buffer overflow.
1178 * @param src The original source string
1179 * @param srcLength The length of the original string. If -1, then src must be zero-terminated.
1180 * @param pErrorCode Must be a valid pointer to an error code value,
1181 * which must not indicate a failure before the function call.
1182 * @return The pointer to destination buffer.
1185 U_STABLE
wchar_t* U_EXPORT2
1186 u_strToWCS(wchar_t *dest
,
1187 int32_t destCapacity
,
1188 int32_t *pDestLength
,
1191 UErrorCode
*pErrorCode
);
1193 * Converts a sequence of wchar_t units to UChars
1195 * @param dest A buffer for the result string. The result will be zero-terminated if
1196 * the buffer is large enough.
1197 * @param destCapacity The size of the buffer (number of UChars). If it is 0, then
1198 * dest may be NULL and the function will only return the length of the
1199 * result without writing any of the result string (pre-flighting).
1200 * @param pDestLength A pointer to receive the number of units written to the destination. If
1201 * pDestLength!=NULL then *pDestLength is always set to the
1202 * number of output units corresponding to the transformation of
1203 * all the input units, even in case of a buffer overflow.
1204 * @param src The original source string
1205 * @param srcLength The length of the original string. If -1, then src must be zero-terminated.
1206 * @param pErrorCode Must be a valid pointer to an error code value,
1207 * which must not indicate a failure before the function call.
1208 * @return The pointer to destination buffer.
1211 U_STABLE UChar
* U_EXPORT2
1212 u_strFromWCS(UChar
*dest
,
1213 int32_t destCapacity
,
1214 int32_t *pDestLength
,
1217 UErrorCode
*pErrorCode
);
1218 #endif /* defined(U_WCHAR_IS_UTF16) || defined(U_WCHAR_IS_UTF32) || !UCONFIG_NO_CONVERSION */
1221 * Converts a sequence of UChars (UTF-16) to UTF-8 bytes
1223 * @param dest A buffer for the result string. The result will be zero-terminated if
1224 * the buffer is large enough.
1225 * @param destCapacity The size of the buffer (number of chars). If it is 0, then
1226 * dest may be NULL and the function will only return the length of the
1227 * result without writing any of the result string (pre-flighting).
1228 * @param pDestLength A pointer to receive the number of units written to the destination. If
1229 * pDestLength!=NULL then *pDestLength is always set to the
1230 * number of output units corresponding to the transformation of
1231 * all the input units, even in case of a buffer overflow.
1232 * @param src The original source string
1233 * @param srcLength The length of the original string. If -1, then src must be zero-terminated.
1234 * @param pErrorCode Must be a valid pointer to an error code value,
1235 * which must not indicate a failure before the function call.
1236 * @return The pointer to destination buffer.
1238 * @see u_strToUTF8WithSub
1239 * @see u_strFromUTF8
1241 U_STABLE
char* U_EXPORT2
1242 u_strToUTF8(char *dest
,
1243 int32_t destCapacity
,
1244 int32_t *pDestLength
,
1247 UErrorCode
*pErrorCode
);
1250 * Converts a sequence of UTF-8 bytes to UChars (UTF-16).
1252 * @param dest A buffer for the result string. The result will be zero-terminated if
1253 * the buffer is large enough.
1254 * @param destCapacity The size of the buffer (number of UChars). If it is 0, then
1255 * dest may be NULL and the function will only return the length of the
1256 * result without writing any of the result string (pre-flighting).
1257 * @param pDestLength A pointer to receive the number of units written to the destination. If
1258 * pDestLength!=NULL then *pDestLength is always set to the
1259 * number of output units corresponding to the transformation of
1260 * all the input units, even in case of a buffer overflow.
1261 * @param src The original source string
1262 * @param srcLength The length of the original string. If -1, then src must be zero-terminated.
1263 * @param pErrorCode Must be a valid pointer to an error code value,
1264 * which must not indicate a failure before the function call.
1265 * @return The pointer to destination buffer.
1267 * @see u_strFromUTF8WithSub
1268 * @see u_strFromUTF8Lenient
1270 U_STABLE UChar
* U_EXPORT2
1271 u_strFromUTF8(UChar
*dest
,
1272 int32_t destCapacity
,
1273 int32_t *pDestLength
,
1276 UErrorCode
*pErrorCode
);
1279 * Converts a sequence of UChars (UTF-16) to UTF-8 bytes.
1280 * Same as u_strToUTF8() except for the additional subchar which is output for
1281 * illegal input sequences, instead of stopping with the U_INVALID_CHAR_FOUND error code.
1282 * With subchar==U_SENTINEL, this function behaves exactly like u_strToUTF8().
1284 * @param dest A buffer for the result string. The result will be zero-terminated if
1285 * the buffer is large enough.
1286 * @param destCapacity The size of the buffer (number of chars). If it is 0, then
1287 * dest may be NULL and the function will only return the length of the
1288 * result without writing any of the result string (pre-flighting).
1289 * @param pDestLength A pointer to receive the number of units written to the destination. If
1290 * pDestLength!=NULL then *pDestLength is always set to the
1291 * number of output units corresponding to the transformation of
1292 * all the input units, even in case of a buffer overflow.
1293 * @param src The original source string
1294 * @param srcLength The length of the original string. If -1, then src must be zero-terminated.
1295 * @param subchar The substitution character to use in place of an illegal input sequence,
1296 * or U_SENTINEL if the function is to return with U_INVALID_CHAR_FOUND instead.
1297 * A substitution character can be any valid Unicode code point (up to U+10FFFF)
1298 * except for surrogate code points (U+D800..U+DFFF).
1299 * The recommended value is U+FFFD "REPLACEMENT CHARACTER".
1300 * @param pNumSubstitutions Output parameter receiving the number of substitutions if subchar>=0.
1301 * Set to 0 if no substitutions occur or subchar<0.
1302 * pNumSubstitutions can be NULL.
1303 * @param pErrorCode Pointer to a standard ICU error code. Its input value must
1304 * pass the U_SUCCESS() test, or else the function returns
1305 * immediately. Check for U_FAILURE() on output or use with
1306 * function chaining. (See User Guide for details.)
1307 * @return The pointer to destination buffer.
1309 * @see u_strFromUTF8WithSub
1312 U_DRAFT
char* U_EXPORT2
1313 u_strToUTF8WithSub(char *dest
,
1314 int32_t destCapacity
,
1315 int32_t *pDestLength
,
1318 UChar32 subchar
, int32_t *pNumSubstitutions
,
1319 UErrorCode
*pErrorCode
);
1322 * Converts a sequence of UTF-8 bytes to UChars (UTF-16).
1323 * Same as u_strFromUTF8() except for the additional subchar which is output for
1324 * illegal input sequences, instead of stopping with the U_INVALID_CHAR_FOUND error code.
1325 * With subchar==U_SENTINEL, this function behaves exactly like u_strFromUTF8().
1327 * @param dest A buffer for the result string. The result will be zero-terminated if
1328 * the buffer is large enough.
1329 * @param destCapacity The size of the buffer (number of UChars). If it is 0, then
1330 * dest may be NULL and the function will only return the length of the
1331 * result without writing any of the result string (pre-flighting).
1332 * @param pDestLength A pointer to receive the number of units written to the destination. If
1333 * pDestLength!=NULL then *pDestLength is always set to the
1334 * number of output units corresponding to the transformation of
1335 * all the input units, even in case of a buffer overflow.
1336 * @param src The original source string
1337 * @param srcLength The length of the original string. If -1, then src must be zero-terminated.
1338 * @param subchar The substitution character to use in place of an illegal input sequence,
1339 * or U_SENTINEL if the function is to return with U_INVALID_CHAR_FOUND instead.
1340 * A substitution character can be any valid Unicode code point (up to U+10FFFF)
1341 * except for surrogate code points (U+D800..U+DFFF).
1342 * The recommended value is U+FFFD "REPLACEMENT CHARACTER".
1343 * @param pNumSubstitutions Output parameter receiving the number of substitutions if subchar>=0.
1344 * Set to 0 if no substitutions occur or subchar<0.
1345 * pNumSubstitutions can be NULL.
1346 * @param pErrorCode Pointer to a standard ICU error code. Its input value must
1347 * pass the U_SUCCESS() test, or else the function returns
1348 * immediately. Check for U_FAILURE() on output or use with
1349 * function chaining. (See User Guide for details.)
1350 * @return The pointer to destination buffer.
1351 * @see u_strFromUTF8
1352 * @see u_strFromUTF8Lenient
1353 * @see u_strToUTF8WithSub
1356 U_DRAFT UChar
* U_EXPORT2
1357 u_strFromUTF8WithSub(UChar
*dest
,
1358 int32_t destCapacity
,
1359 int32_t *pDestLength
,
1362 UChar32 subchar
, int32_t *pNumSubstitutions
,
1363 UErrorCode
*pErrorCode
);
1366 * Converts a sequence of UTF-8 bytes to UChars (UTF-16).
1367 * Same as u_strFromUTF8() except that this function is designed to be very fast,
1368 * which it achieves by being lenient about malformed UTF-8 sequences.
1369 * This function is intended for use in environments where UTF-8 text is
1370 * expected to be well-formed.
1372 * Its semantics are:
1373 * - Well-formed UTF-8 text is correctly converted to well-formed UTF-16 text.
1374 * - The function will not read beyond the input string, nor write beyond
1376 * - Malformed UTF-8 results in "garbage" 16-bit Unicode strings which may not
1377 * be well-formed UTF-16.
1378 * The function will resynchronize to valid code point boundaries
1379 * within a small number of code points after an illegal sequence.
1380 * - Non-shortest forms are not detected and will result in "spoofing" output.
1382 * For further performance improvement, if srcLength is given (>=0),
1383 * then it must be destCapacity>=srcLength.
1385 * @param dest A buffer for the result string. The result will be zero-terminated if
1386 * the buffer is large enough.
1387 * @param destCapacity The size of the buffer (number of UChars). If it is 0, then
1388 * dest may be NULL and the function will only return the length of the
1389 * result without writing any of the result string (pre-flighting).
1390 * Unlike for other ICU functions, if srcLength>=0 then it
1391 * must be destCapacity>=srcLength.
1392 * @param pDestLength A pointer to receive the number of units written to the destination. If
1393 * pDestLength!=NULL then *pDestLength is always set to the
1394 * number of output units corresponding to the transformation of
1395 * all the input units, even in case of a buffer overflow.
1396 * Unlike for other ICU functions, if srcLength>=0 but
1397 * destCapacity<srcLength, then *pDestLength will be set to srcLength
1398 * (and U_BUFFER_OVERFLOW_ERROR will be set)
1399 * regardless of the actual result length.
1400 * @param src The original source string
1401 * @param srcLength The length of the original string. If -1, then src must be zero-terminated.
1402 * @param pErrorCode Pointer to a standard ICU error code. Its input value must
1403 * pass the U_SUCCESS() test, or else the function returns
1404 * immediately. Check for U_FAILURE() on output or use with
1405 * function chaining. (See User Guide for details.)
1406 * @return The pointer to destination buffer.
1407 * @see u_strFromUTF8
1408 * @see u_strFromUTF8WithSub
1409 * @see u_strToUTF8WithSub
1412 U_CAPI UChar
* U_EXPORT2
1413 u_strFromUTF8Lenient(UChar
*dest
,
1414 int32_t destCapacity
,
1415 int32_t *pDestLength
,
1418 UErrorCode
*pErrorCode
);
1421 * Converts a sequence of UChars (UTF-16) to UTF32 units.
1423 * @param dest A buffer for the result string. The result will be zero-terminated if
1424 * the buffer is large enough.
1425 * @param destCapacity The size of the buffer (number of UChar32s). If it is 0, then
1426 * dest may be NULL and the function will only return the length of the
1427 * result without writing any of the result string (pre-flighting).
1428 * @param pDestLength A pointer to receive the number of units written to the destination. If
1429 * pDestLength!=NULL then *pDestLength is always set to the
1430 * number of output units corresponding to the transformation of
1431 * all the input units, even in case of a buffer overflow.
1432 * @param src The original source string
1433 * @param srcLength The length of the original string. If -1, then src must be zero-terminated.
1434 * @param pErrorCode Must be a valid pointer to an error code value,
1435 * which must not indicate a failure before the function call.
1436 * @return The pointer to destination buffer.
1439 U_STABLE UChar32
* U_EXPORT2
1440 u_strToUTF32(UChar32
*dest
,
1441 int32_t destCapacity
,
1442 int32_t *pDestLength
,
1445 UErrorCode
*pErrorCode
);
1448 * Converts a sequence of UTF32 units to UChars (UTF-16)
1450 * @param dest A buffer for the result string. The result will be zero-terminated if
1451 * the buffer is large enough.
1452 * @param destCapacity The size of the buffer (number of UChars). If it is 0, then
1453 * dest may be NULL and the function will only return the length of the
1454 * result without writing any of the result string (pre-flighting).
1455 * @param pDestLength A pointer to receive the number of units written to the destination. If
1456 * pDestLength!=NULL then *pDestLength is always set to the
1457 * number of output units corresponding to the transformation of
1458 * all the input units, even in case of a buffer overflow.
1459 * @param src The original source string
1460 * @param srcLength The length of the original string. If -1, then src must be zero-terminated.
1461 * @param pErrorCode Must be a valid pointer to an error code value,
1462 * which must not indicate a failure before the function call.
1463 * @return The pointer to destination buffer.
1466 U_STABLE UChar
* U_EXPORT2
1467 u_strFromUTF32(UChar
*dest
,
1468 int32_t destCapacity
,
1469 int32_t *pDestLength
,
1472 UErrorCode
*pErrorCode
);