2
**********************************************************************
3
* Copyright (C) 1998-2001, 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
******************************************************************************
18
#include "unicode/utypes.h"
20
/** Simple declaration for u_strToTitle() to avoid including unicode/ubrk.h. */
21
#ifndef UBRK_TYPEDEF_UBREAK_ITERATOR
22
# define UBRK_TYPEDEF_UBREAK_ITERATOR
23
typedef void *UBreakIterator;
28
* \brief C API: Unicode string handling functions
30
* These C API functions provide Unicode string handling.
32
* Some functions are equivalent in name, signature, and behavior to the ANSI C <string.h>
33
* functions. (For example, they do not check for bad arguments like NULL string pointers.)
34
* In some cases, only the thread-safe variant of such a function is implemented here
37
* Other functions provide more Unicode-specific functionality like locale-specific
38
* upper/lower-casing and string comparison in code point order.
40
* ICU uses 16-bit Unicode (UTF-16) in the form of arrays of UChar code units.
41
* UTF-16 encodes each Unicode code point with either one or two UChar code units.
42
* Some APIs accept a 32-bit UChar32 value for a single code point.
43
* (This is the default form of Unicode, and a forward-compatible extension of the original,
44
* fixed-width form that was known as UCS-2. UTF-16 superseded UCS-2 with Unicode 2.0
47
* Although UTF-16 is a variable-width encoding form (like some legacy multi-byte encodings),
48
* it is much more efficient even for random access because the code unit values
49
* for single-unit characters vs. lead units vs. trail units are completely disjoint.
50
* This means that it is easy to determine character (code point) boundaries from
51
* random offsets in the string.
52
* (It also means, e.g., that u_strstr() does not need to verify that a match was
53
* found on actual character boundaries; with some legacy encodings, strstr() may need to
54
* scan back to the start of the text to verify this.)
56
* Unicode (UTF-16) string processing is optimized for the single-unit case.
57
* Although it is important to support supplementary characters
58
* (which use pairs of lead/trail code units called "surrogates"),
59
* their occurrence is rare. Almost all characters in modern use require only
60
* a single UChar code unit (i.e., their code point values are <=0xffff).
64
* Determine the length of an array of UChar.
66
* @param s The array of UChars, NULL (U+0000) terminated.
67
* @return The number of UChars in <TT>chars</TT>, minus the terminator.
70
U_CAPI int32_t U_EXPORT2
71
u_strlen(const UChar *s);
74
* Count Unicode code points in the length UChar code units of the string.
75
* A code point may occupy either one or two UChar code units.
76
* Counting code points involves reading all code units.
78
* This functions is basically the inverse of the UTF_FWD_N() macro (see utf.h).
80
* @param s The input string.
81
* @param length The number of UChar code units to be checked, or -1 to count all
82
* code points before the first NUL (U+0000).
83
* @return The number of code points in the specified code units.
86
U_CAPI int32_t U_EXPORT2
87
u_countChar32(const UChar *s, int32_t length);
90
* Concatenate two ustrings. Appends a copy of <TT>src</TT>,
91
* including the null terminator, to <TT>dst</TT>. The initial copied
92
* character from <TT>src</TT> overwrites the null terminator in <TT>dst</TT>.
94
* @param dst The destination string.
95
* @param src The source string.
96
* @return A pointer to <TT>dst</TT>.
99
U_CAPI UChar* U_EXPORT2
104
* Concatenate two ustrings.
105
* Appends at most <TT>n</TT> characters from <TT>src</TT> to <TT>dst</TT>.
106
* Adds a null terminator.
108
* @param dst The destination string.
109
* @param src The source string.
110
* @param n The maximum number of characters to compare.
111
* @return A pointer to <TT>dst</TT>.
114
U_CAPI UChar* U_EXPORT2
115
u_strncat(UChar *dst,
120
* Find the first occurrence of a specified character in a ustring.
122
* @param s The string to search.
123
* @param c The character to find.
124
* @return A pointer to the first occurrence of <TT>c</TT> in <TT>s</TT>,
125
* or a null pointer if <TT>s</TT> does not contain <TT>c</TT>.
128
U_CAPI UChar* U_EXPORT2
129
u_strchr(const UChar *s,
133
* Find the first occurrence of a substring in a string.
135
* @param s The string to search.
136
* @return A pointer to the first occurrence of <TT>substring</TT> in
137
* <TT>s</TT>, or a null pointer if <TT>substring</TT>
138
* is not in <TT>s</TT>.
141
U_CAPI UChar * U_EXPORT2
142
u_strstr(const UChar *s, const UChar *substring);
145
* Find the first occurence of a specified code point in a string.
147
* This function finds code points, which differs for BMP code points
148
* from u_strchr() only for surrogates:
149
* While u_strchr() finds any surrogate code units in a string,
150
* u_strchr32() finds only unmatched surrogate code points,
151
* i.e., only those that do not combine with an adjacent surrogate
152
* to form a supplementary code point.
153
* For example, in a string "\ud800\udc00" u_strchr()
154
* will find code units U+d800 at 0 and U+dc00 at 1,
155
* but u_strchr32() will find neither because they
156
* combine to the code point U+10000.
157
* Either function will find U+d800 in "a\ud800b".
158
* This behavior ensures that UTF_GET_CHAR(u_strchr32(c))==c.
160
* @param s The string to search.
161
* @param c The code point (0..0x10ffff) to find.
162
* @return A pointer to the first occurrence of <TT>c</TT> in <TT>s</TT>,
163
* or a null pointer if there is no such character.
164
* If <TT>c</TT> is represented with several UChars, then the returned
165
* pointer will point to the first of them.
168
U_CAPI UChar * U_EXPORT2
169
u_strchr32(const UChar *s, UChar32 c);
172
* Locates the first occurrence in the string str of any of the characters
173
* in the string accept.
174
* Works just like C's strpbrk but with Unicode.
176
* @return A pointer to the character in str that matches one of the
177
* characters in accept, or NULL if no such character is found.
180
U_CAPI UChar * U_EXPORT2
181
u_strpbrk(const UChar *string, const UChar *matchSet);
184
* Returns the number of consecutive characters in string1,
185
* beginning with the first, that do not occur somewhere in string2.
186
* Works just like C's strcspn but with Unicode.
191
U_CAPI int32_t U_EXPORT2
192
u_strcspn(const UChar *string, const UChar *matchSet);
195
* Returns the number of consecutive characters in string1,
196
* beginning with the first, that occur somewhere in string2.
197
* Works just like C's strspn but with Unicode.
202
U_CAPI int32_t U_EXPORT2
203
u_strspn(const UChar *string, const UChar *matchSet);
206
* The string tokenizer API allows an application to break a string into
207
* tokens. Unlike strtok(), the saveState (the current pointer within the
208
* original string) is maintained in saveState. In the first call, the
209
* argument src is a pointer to the string. In subsequent calls to
210
* return successive tokens of that string, src must be specified as
211
* NULL. The value saveState is set by this function to maintain the
212
* function's position within the string, and on each subsequent call
213
* you must give this argument the same variable. This function does
214
* handle surrogate pairs. This function is similar to the strtok_r()
215
* the POSIX Threads Extension (1003.1c-1995) version.
217
* @param src String containing token(s). This string will be modified.
218
* After the first call to u_strtok_r(), this argument must
219
* be NULL to get to the next token.
220
* @param delim Set of delimiter characters (Unicode code points).
221
* @param saveState The current pointer within the original string,
222
* which is set by this function.
223
* @return A pointer to the next token found in src, or NULL
224
* when there are no more tokens.
227
U_CAPI UChar * U_EXPORT2
228
u_strtok_r(UChar *src,
233
* Compare two Unicode strings for bitwise equality (code unit order).
235
* @param s1 A string to compare.
236
* @param s2 A string to compare.
237
* @return 0 if <TT>s1</TT> and <TT>s2</TT> are bitwise equal; a negative
238
* value if <TT>s1</TT> is bitwise less than <TT>s2,/TT>; a positive
239
* value if <TT>s1</TT> is bitwise greater than <TT>s2,/TT>.
242
U_CAPI int32_t U_EXPORT2
243
u_strcmp(const UChar *s1,
247
* Compare two Unicode strings in code point order.
248
* This is different in UTF-16 from u_strcmp() if supplementary characters are present:
249
* In UTF-16, supplementary characters (with code points U+10000 and above) are
250
* stored with pairs of surrogate code units. These have values from 0xd800 to
251
* 0xdfff, which means that they compare as less than some other BMP characters
252
* like U+feff. This function compares Unicode strings in code point order.
253
* If eihter of the UTF-16 strings is malformed (i.e., it contains unpaired
254
* surrogates), then the result is not defined.
256
* @param s1 A string to compare.
257
* @param s2 A string to compare.
258
* @return a negative/zero/positive integer corresponding to whether
259
* the first string is less than/equal to/greater than the second one
260
* in code point order
263
U_CAPI int32_t U_EXPORT2
264
u_strcmpCodePointOrder(const UChar *s1, const UChar *s2);
267
* Compare two ustrings for bitwise equality.
268
* Compares at most <TT>n</TT> characters.
270
* @param s1 A string to compare.
271
* @param s2 A string to compare.
272
* @param n The maximum number of characters to compare.
273
* @return 0 if <TT>s1</TT> and <TT>s2</TT> are bitwise equal; a negative
274
* value if <TT>s1</TT> is bitwise less than <TT>s2,/TT>; a positive
275
* value if <TT>s1</TT> is bitwise greater than <TT>s2,/TT>.
278
U_CAPI int32_t U_EXPORT2
279
u_strncmp(const UChar *ucs1,
284
* Compare two Unicode strings in code point order.
285
* This is different in UTF-16 from u_strncmp() if supplementary characters are present.
286
* For details, see u_strcmpCodePointOrder().
288
* @param s1 A string to compare.
289
* @param s2 A string to compare.
290
* @param n The maximum number of characters to compare.
291
* @return a negative/zero/positive integer corresponding to whether
292
* the first string is less than/equal to/greater than the second one
293
* in code point order
296
U_CAPI int32_t U_EXPORT2
297
u_strncmpCodePointOrder(const UChar *s1, const UChar *s2, int32_t n);
300
* Compare two strings case-insensitively using full case folding.
301
* This is equivalent to u_strcmp(u_strFoldCase(s1, options), u_strFoldCase(s2, options)).
303
* @param s1 A string to compare.
304
* @param s2 A string to compare.
305
* @param options Either U_FOLD_CASE_DEFAULT or U_FOLD_CASE_EXCLUDE_SPECIAL_I
306
* @return A negative, zero, or positive integer indicating the comparison result.
309
U_CAPI int32_t U_EXPORT2
310
u_strcasecmp(const UChar *s1, const UChar *s2, uint32_t options);
313
* Compare two strings case-insensitively using full case folding.
314
* This is equivalent to u_strcmp(u_strFoldCase(s1, at most n, options),
315
* u_strFoldCase(s2, at most n, options)).
317
* @param s1 A string to compare.
318
* @param s2 A string to compare.
319
* @param n The maximum number of characters each string to case-fold and then compare.
320
* @param options Either U_FOLD_CASE_DEFAULT or U_FOLD_CASE_EXCLUDE_SPECIAL_I
321
* @return A negative, zero, or positive integer indicating the comparison result.
324
U_CAPI int32_t U_EXPORT2
325
u_strncasecmp(const UChar *s1, const UChar *s2, int32_t n, uint32_t options);
328
* Compare two strings case-insensitively using full case folding.
329
* This is equivalent to u_strcmp(u_strFoldCase(s1, n, options),
330
* u_strFoldCase(s2, n, options)).
332
* @param s1 A string to compare.
333
* @param s2 A string to compare.
334
* @param n The number of characters in each string to case-fold and then compare.
335
* @param options Either U_FOLD_CASE_DEFAULT or U_FOLD_CASE_EXCLUDE_SPECIAL_I
336
* @return A negative, zero, or positive integer indicating the comparison result.
339
U_CAPI int32_t U_EXPORT2
340
u_memcasecmp(const UChar *s1, const UChar *s2, int32_t length, uint32_t options);
343
* Copy a ustring. Adds a null terminator.
345
* @param dst The destination string.
346
* @param src The source string.
347
* @return A pointer to <TT>dst</TT>.
350
U_CAPI UChar* U_EXPORT2
356
* Copies at most <TT>n</TT> characters. The result will be null terminated
357
* if the length of <TT>src</TT> is less than <TT>n</TT>.
359
* @param dst The destination string.
360
* @param src The source string.
361
* @param n The maximum number of characters to copy.
362
* @return A pointer to <TT>dst</TT>.
365
U_CAPI UChar* U_EXPORT2
366
u_strncpy(UChar *dst,
371
* Copy a byte string encoded in the default codepage to a ustring.
372
* Adds a null terminator.
373
* Performs a host byte to UChar conversion
375
* @param dst The destination string.
376
* @param src The source string.
377
* @return A pointer to <TT>dst</TT>.
380
U_CAPI UChar* U_EXPORT2 u_uastrcpy(UChar *dst,
384
* Copy a byte string encoded in the default codepage to a ustring.
385
* Copies at most <TT>n</TT> characters. The result will be null terminated
386
* if the length of <TT>src</TT> is less than <TT>n</TT>.
387
* Performs a host byte to UChar conversion
389
* @param dst The destination string.
390
* @param src The source string.
391
* @param n The maximum number of characters to copy.
392
* @return A pointer to <TT>dst</TT>.
395
U_CAPI UChar* U_EXPORT2 u_uastrncpy(UChar *dst,
400
* Copy ustring to a byte string encoded in the default codepage.
401
* Adds a null terminator.
402
* Performs a UChar to host byte conversion
404
* @param dst The destination string.
405
* @param src The source string.
406
* @return A pointer to <TT>dst</TT>.
409
U_CAPI char* U_EXPORT2 u_austrcpy(char *dst,
413
* Copy ustring to a byte string encoded in the default codepage.
414
* Copies at most <TT>n</TT> characters. The result will be null terminated
415
* if the length of <TT>src</TT> is less than <TT>n</TT>.
416
* Performs a UChar to host byte conversion
418
* @param dst The destination string.
419
* @param src The source string.
420
* @param n The maximum number of characters to copy.
421
* @return A pointer to <TT>dst</TT>.
424
U_CAPI char* U_EXPORT2 u_austrncpy(char *dst,
429
* Synonym for memcpy(), but with UChars only.
432
U_CAPI UChar* U_EXPORT2
433
u_memcpy(UChar *dest, const UChar *src, int32_t count);
436
* Synonym for memmove(), but with UChars only.
439
U_CAPI UChar* U_EXPORT2
440
u_memmove(UChar *dest, const UChar *src, int32_t count);
443
* Initialize <TT>count</TT> characters of <TT>dest</TT> to <TT>c</TT>.
445
* @param dest The destination string.
446
* @param c The character to initialize the string.
447
* @param count The maximum number of characters to set.
448
* @return A pointer to <TT>dest</TT>.
451
U_CAPI UChar* U_EXPORT2
452
u_memset(UChar *dest, UChar c, int32_t count);
455
* Compare the first <TT>count</TT> UChars of each buffer.
457
* @param buf1 The first string to compare.
458
* @param buf2 The second string to compare.
459
* @param count The maximum number of UChars to compare.
460
* @return When buf1 < buf2, a negative number is returned.
461
* When buf1 == buf2, 0 is returned.
462
* When buf1 > buf2, a positive number is returned.
465
U_CAPI int32_t U_EXPORT2
466
u_memcmp(UChar *buf1, UChar *buf2, int32_t count);
469
* Compare two Unicode strings in code point order.
470
* This is different in UTF-16 from u_memcmp() if supplementary characters are present.
471
* For details, see u_strcmpCodePointOrder().
473
* @param s1 A string to compare.
474
* @param s2 A string to compare.
475
* @param n The maximum number of characters to compare.
476
* @return a negative/zero/positive integer corresponding to whether
477
* the first string is less than/equal to/greater than the second one
478
* in code point order
481
U_CAPI int32_t U_EXPORT2
482
u_memcmpCodePointOrder(const UChar *s1, const UChar *s2, int32_t count);
485
* Search for a UChar within a Unicode string until <TT>count</TT>
488
* @param src string to search in
489
* @param ch character to find
490
* @param count maximum number of UChars in <TT>src</TT>to search for
492
* @return A pointer within src, pointing to <TT>ch</TT>, or NULL if it
496
U_CAPI UChar* U_EXPORT2
497
u_memchr(UChar *src, UChar ch, int32_t count);
500
* Search for a UChar32 within a Unicode string until <TT>count</TT>
501
* is reached. This also includes surrogates in UTF-16.
503
* @param src string to search in
504
* @param ch character to find
505
* @param count maximum number of UChars in <TT>src</TT>to search for
507
* @return A pointer within src, pointing to <TT>ch</TT>, or NULL if it
511
U_CAPI UChar* U_EXPORT2
512
u_memchr32(UChar *src, UChar32 ch, int32_t count);
515
* Unicode String literals in C.
516
* We need one macro to declare a variable for the string
517
* and to statically preinitialize it if possible,
518
* and a second macro to dynamically intialize such a string variable if necessary.
520
* The macros are defined for maximum performance.
521
* They work only for strings that contain "invariant characters", i.e.,
522
* only latin letters, digits, and some punctuation.
523
* See utypes.h for details.
525
* A pair of macros for a single string must be used with the same
527
* The string parameter must be a C string literal.
528
* The length of the string, not including the terminating
529
* <code>NUL</code>, must be specified as a constant.
530
* The U_STRING_DECL macro should be invoked exactly once for one
531
* such string variable before it is used.
535
*   U_STRING_DECL(ustringVar1, "Quick-Fox 2", 11);
536
*   U_STRING_DECL(ustringVar2, "jumps 5%", 8);
537
*   static UBool didInit=FALSE;
539
*   int32_t function() {
540
*   if(!didInit) {
541
*   U_STRING_INIT(ustringVar1, "Quick-Fox 2", 11);
542
*   U_STRING_INIT(ustringVar2, "jumps 5%", 8);
543
*   didInit=TRUE;
545
*   return u_strcmp(ustringVar1, ustringVar2);
550
#if U_SIZEOF_WCHAR_T==U_SIZEOF_UCHAR && U_CHARSET_FAMILY==U_ASCII_FAMILY
551
# define U_STRING_DECL(var, cs, length) static const wchar_t var[(length)+1]={ L ## cs }
552
# define U_STRING_INIT(var, cs, length)
553
#elif U_SIZEOF_UCHAR==1 && U_CHARSET_FAMILY==U_ASCII_FAMILY
554
# define U_STRING_DECL(var, cs, length) static const UChar var[(length)+1]={ (const UChar *)cs }
555
# define U_STRING_INIT(var, cs, length)
557
# define U_STRING_DECL(var, cs, length) static UChar var[(length)+1]
558
# define U_STRING_INIT(var, cs, length) u_charsToUChars(cs, var, length+1)
562
* Unescape a string of characters and write the resulting
563
* Unicode characters to the destination buffer. The following escape
564
* sequences are recognized:
566
* \uhhhh 4 hex digits; h in [0-9A-Fa-f]
567
* \Uhhhhhhhh 8 hex digits
568
* \xhh 1-2 hex digits
569
* \ooo 1-3 octal digits; o in [0-7]
571
* as well as the standard ANSI C escapes:
573
* \a => U+0007, \b => U+0008, \t => U+0009, \n => U+000A,
574
* \v => U+000B, \f => U+000C, \r => U+000D,
575
* \" => U+0022, \' => U+0027, \? => U+003F, \\ => U+005C
577
* Anything else following a backslash is generically escaped. For
578
* example, "[a\-z]" returns "[a-z]".
580
* If an escape sequence is ill-formed, this method returns an empty
581
* string. An example of an ill-formed sequence is "\u" followed by
582
* fewer than 4 hex digits.
584
* The above characters are recognized in the compiler's codepage,
585
* that is, they are coded as 'u', '\\', etc. Characters that are
586
* not parts of escape sequences are converted using u_charsToUChars().
588
* This function is similar to UnicodeString::unescape() but not
589
* identical to it. The latter takes a source UnicodeString, so it
590
* does escape recognition but no conversion.
592
* @param src a zero-terminated string of invariant characters
593
* @param dest pointer to buffer to receive converted and unescaped
594
* text and, if there is room, a zero terminator. May be NULL for
595
* preflighting, in which case no UChars will be written, but the
596
* return value will still be valid. On error, an empty string is
597
* stored here (if possible).
598
* @param destCapacity the number of UChars that may be written at
599
* dest. Ignored if dest == NULL.
600
* @return the capacity required to fully convert all of the source
601
* text, including the zero terminator, or 0 on error.
603
* @see UnicodeString#unescape()
604
* @see UnicodeString#unescapeAt()
607
U_CAPI int32_t U_EXPORT2
608
u_unescape(const char *src,
609
UChar *dest, int32_t destCapacity);
612
* Callback function for u_unescapeAt() that returns a character of
613
* the source text given an offset and a context pointer. The context
614
* pointer will be whatever is passed into u_unescapeAt().
620
typedef UChar (*UNESCAPE_CHAR_AT)(int32_t offset, void *context);
624
* Unescape a single sequence. The character at offset-1 is assumed
625
* (without checking) to be a backslash. This method takes a callback
626
* pointer to a function that returns the UChar at a given offset. By
627
* varying this callback, ICU functions are able to unescape char*
628
* strings, UnicodeString objects, and UFILE pointers.
630
* If offset is out of range, or if the escape sequence is ill-formed,
631
* (UChar32)0xFFFFFFFF is returned. See documentation of u_unescape()
632
* for a list of recognized sequences.
634
* @param charAt callback function that returns a UChar of the source
635
* text given an offset and a context pointer.
636
* @param offset pointer to the offset that will be passed to charAt.
637
* The offset value will be updated upon return to point after the
638
* last parsed character of the escape sequence. On error the offset
640
* @param length the number of characters in the source text. The
641
* last character of the source text is considered to be at offset
643
* @param context an opaque pointer passed directly into charAt.
644
* @return the character represented by the escape sequence at
645
* offset, or (UChar32)0xFFFFFFFF on error.
647
* @see UnicodeString#unescape()
648
* @see UnicodeString#unescapeAt()
651
U_CAPI UChar32 U_EXPORT2
652
u_unescapeAt(UNESCAPE_CHAR_AT charAt,
658
* Uppercase the characters in a string.
659
* Casing is locale-dependent and context-sensitive.
660
* The result may be longer or shorter than the original.
661
* The source string and the destination buffer are allowed to overlap.
663
* @param dest A buffer for the result string. The result will be zero-terminated if
664
* the buffer is large enough.
665
* @param destCapacity The size of the buffer (number of UChars). If it is 0, then
666
* dest may be NULL and the function will only return the length of the result
667
* without writing any of the result string.
668
* @param src The original string
669
* @param srcLength The length of the original string. If -1, then src must be zero-terminated.
670
* @param locale The locale to consider, or "" for the root locale or NULL for the default locale.
671
* @param pErrorCode Must be a valid pointer to an error code value,
672
* which must not indicate a failure before the function call.
673
* @return The length of the result string. It may be greater than destCapacity. In that case,
674
* only some of the result was written to the destination buffer.
677
U_CAPI int32_t U_EXPORT2
678
u_strToUpper(UChar *dest, int32_t destCapacity,
679
const UChar *src, int32_t srcLength,
681
UErrorCode *pErrorCode);
684
* Lowercase the characters in a string.
685
* Casing is locale-dependent and context-sensitive.
686
* The result may be longer or shorter than the original.
687
* The source string and the destination buffer are allowed to overlap.
689
* @param dest A buffer for the result string. The result will be zero-terminated if
690
* the buffer is large enough.
691
* @param destCapacity The size of the buffer (number of UChars). If it is 0, then
692
* dest may be NULL and the function will only return the length of the result
693
* without writing any of the result string.
694
* @param src The original string
695
* @param srcLength The length of the original string. If -1, then src must be zero-terminated.
696
* @param locale The locale to consider, or "" for the root locale or NULL for the default locale.
697
* @param pErrorCode Must be a valid pointer to an error code value,
698
* which must not indicate a failure before the function call.
699
* @return The length of the result string. It may be greater than destCapacity. In that case,
700
* only some of the result was written to the destination buffer.
703
U_CAPI int32_t U_EXPORT2
704
u_strToLower(UChar *dest, int32_t destCapacity,
705
const UChar *src, int32_t srcLength,
707
UErrorCode *pErrorCode);
710
* Titlecase a string.
711
* Casing is locale-dependent and context-sensitive.
712
* Titlecasing uses a break iterator to find the first characters of words
713
* that are to be titlecased. It titlecases those characters and lowercases
716
* The titlecase break iterator can be provided to customize for arbitrary
717
* styles, using rules and dictionaries beyond the standard iterators.
718
* It may be more efficient to always provide an iterator to avoid
719
* opening and closing one for each string.
720
* The standard titlecase iterator for the root locale implements the
721
* algorithm of Unicode TR 21.
723
* This function uses only the first() and next() methods of the
724
* provided break iterator.
726
* The result may be longer or shorter than the original.
727
* The source string and the destination buffer are allowed to overlap.
729
* @param dest A buffer for the result string. The result will be zero-terminated if
730
* the buffer is large enough.
731
* @param destCapacity The size of the buffer (number of UChars). If it is 0, then
732
* dest may be NULL and the function will only return the length of the result
733
* without writing any of the result string.
734
* @param src The original string
735
* @param srcLength The length of the original string. If -1, then src must be zero-terminated.
736
* @param titleIter A break iterator to find the first characters of words
737
* that are to be titlecased.
738
* If none is provided (NULL), then a standard titlecase
739
* break iterator is opened.
740
* @param locale The locale to consider, or "" for the root locale or NULL for the default locale.
741
* @param pErrorCode Must be a valid pointer to an error code value,
742
* which must not indicate a failure before the function call.
743
* @return The length of the result string. It may be greater than destCapacity. In that case,
744
* only some of the result was written to the destination buffer.
747
U_CAPI int32_t U_EXPORT2
748
u_strToTitle(UChar *dest, int32_t destCapacity,
749
const UChar *src, int32_t srcLength,
750
UBreakIterator *titleIter,
752
UErrorCode *pErrorCode);
755
* Case-fold the characters in a string.
756
* Case-folding is locale-independent and not context-sensitive,
757
* but there is an option for whether to include or exclude mappings for dotted I
758
* and dotless i that are marked with 'I' in CaseFolding.txt.
759
* The result may be longer or shorter than the original.
760
* The source string and the destination buffer are allowed to overlap.
762
* @param dest A buffer for the result string. The result will be zero-terminated if
763
* the buffer is large enough.
764
* @param destCapacity The size of the buffer (number of UChars). If it is 0, then
765
* dest may be NULL and the function will only return the length of the result
766
* without writing any of the result string.
767
* @param src The original string
768
* @param srcLength The length of the original string. If -1, then src must be zero-terminated.
769
* @param options Either U_FOLD_CASE_DEFAULT or U_FOLD_CASE_EXCLUDE_SPECIAL_I
770
* @param pErrorCode Must be a valid pointer to an error code value,
771
* which must not indicate a failure before the function call.
772
* @return The length of the result string. It may be greater than destCapacity. In that case,
773
* only some of the result was written to the destination buffer.
776
U_CAPI int32_t U_EXPORT2
777
u_strFoldCase(UChar *dest, int32_t destCapacity,
778
const UChar *src, int32_t srcLength,
780
UErrorCode *pErrorCode);
783
* Converts a sequence of UChars to wchar_t units.
785
* @param dest A buffer for the result string. The result will be zero-terminated if
786
* the buffer is large enough.
787
* @param destCapacity The size of the buffer (number of UChars). If it is 0, then
788
* dest may be NULL and the function will only return the length of the
789
* result without writing any of the result string (pre-flighting).
790
* @param pDestLength A pointer to receive the number of units written to the destination. If
791
* pDestLength!=NULL then *pDestLength is always set to the
792
* number of output units corresponding to the transformation of
793
* all the input units, even in case of a buffer overflow.
794
* @param src The original source string
795
* @param srcLength The length of the original string. If -1, then src must be zero-terminated.
796
* @param pErrorCode Must be a valid pointer to an error code value,
797
* which must not indicate a failure before the function call.
798
* @return The pointer to destination buffer.
801
U_CAPI wchar_t* U_EXPORT2
802
u_strToWCS(wchar_t *dest,
803
int32_t destCapacity,
804
int32_t *pDestLength,
807
UErrorCode *pErrorCode);
809
* Converts a sequence of wchar_t units to UChars
811
* @param dest A buffer for the result string. The result will be zero-terminated if
812
* the buffer is large enough.
813
* @param destCapacity The size of the buffer (number of UChars). If it is 0, then
814
* dest may be NULL and the function will only return the length of the
815
* result without writing any of the result string (pre-flighting).
816
* @param pDestLength A pointer to receive the number of units written to the destination. If
817
* pDestLength!=NULL then *pDestLength is always set to the
818
* number of output units corresponding to the transformation of
819
* all the input units, even in case of a buffer overflow.
820
* @param src The original source string
821
* @param srcLength The length of the original string. If -1, then src must be zero-terminated.
822
* @param pErrorCode Must be a valid pointer to an error code value,
823
* which must not indicate a failure before the function call.
824
* @return The pointer to destination buffer.
827
U_CAPI UChar* U_EXPORT2
828
u_strFromWCS(UChar *dest,
829
int32_t destCapacity,
830
int32_t *pDestLength,
833
UErrorCode *pErrorCode);
835
* Converts a sequence of UChars (UTF-16) to UTF-8 bytes
837
* @param dest A buffer for the result string. The result will be zero-terminated if
838
* the buffer is large enough.
839
* @param destCapacity The size of the buffer (number of UChars). If it is 0, then
840
* dest may be NULL and the function will only return the length of the
841
* result without writing any of the result string (pre-flighting).
842
* @param pDestLength A pointer to receive the number of units written to the destination. If
843
* pDestLength!=NULL then *pDestLength is always set to the
844
* number of output units corresponding to the transformation of
845
* all the input units, even in case of a buffer overflow.
846
* @param src The original source string
847
* @param srcLength The length of the original string. If -1, then src must be zero-terminated.
848
* @param pErrorCode Must be a valid pointer to an error code value,
849
* which must not indicate a failure before the function call.
850
* @return The pointer to destination buffer.
853
U_CAPI char* U_EXPORT2
854
u_strToUTF8(char *dest,
855
int32_t destCapacity,
856
int32_t *pDestLength,
859
UErrorCode *pErrorCode);
862
* Converts a sequence of UTF-8 bytes to UChars (UTF-16).
864
* @param dest A buffer for the result string. The result will be zero-terminated if
865
* the buffer is large enough.
866
* @param destCapacity The size of the buffer (number of UChars). If it is 0, then
867
* dest may be NULL and the function will only return the length of the
868
* result without writing any of the result string (pre-flighting).
869
* @param pDestLength A pointer to receive the number of units written to the destination. If
870
* pDestLength!=NULL then *pDestLength is always set to the
871
* number of output units corresponding to the transformation of
872
* all the input units, even in case of a buffer overflow.
873
* @param src The original source string
874
* @param srcLength The length of the original string. If -1, then src must be zero-terminated.
875
* @param pErrorCode Must be a valid pointer to an error code value,
876
* which must not indicate a failure before the function call.
877
* @return The pointer to destination buffer.
880
U_CAPI UChar* U_EXPORT2
881
u_strFromUTF8(UChar *dest,
882
int32_t destCapacity,
883
int32_t *pDestLength,
886
UErrorCode *pErrorCode);
889
* Converts a sequence of UTF32 units to UChars
891
* @param dest A buffer for the result string. The result will be zero-terminated if
892
* the buffer is large enough.
893
* @param destCapacity The size of the buffer (number of UChars). If it is 0, then
894
* dest may be NULL and the function will only return the length of the
895
* result without writing any of the result string (pre-flighting).
896
* @param pDestLength A pointer to receive the number of units written to the destination. If
897
* pDestLength!=NULL then *pDestLength is always set to the
898
* number of output units corresponding to the transformation of
899
* all the input units, even in case of a buffer overflow.
900
* @param src The original source string
901
* @param srcLength The length of the original string. If -1, then src must be zero-terminated.
902
* @param pErrorCode Must be a valid pointer to an error code value,
903
* which must not indicate a failure before the function call.
904
* @return The pointer to destination buffer.
907
U_CAPI UChar32* U_EXPORT2
908
u_strToUTF32(UChar32 *dest,
909
int32_t destCapacity,
910
int32_t *pDestLength,
913
UErrorCode *pErrorCode);
916
* Converts a sequence of UChars to UTF32 units.
918
* @param dest A buffer for the result string. The result will be zero-terminated if
919
* the buffer is large enough.
920
* @param destCapacity The size of the buffer (number of UChars). If it is 0, then
921
* dest may be NULL and the function will only return the length of the
922
* result without writing any of the result string (pre-flighting).
923
* @param pDestLength A pointer to receive the number of units written to the destination. If
924
* pDestLength!=NULL then *pDestLength is always set to the
925
* number of output units corresponding to the transformation of
926
* all the input units, even in case of a buffer overflow.
927
* @param src The original source string
928
* @param srcLength The length of the original string. If -1, then src must be zero-terminated.
929
* @param pErrorCode Must be a valid pointer to an error code value,
930
* which must not indicate a failure before the function call.
931
* @return The pointer to destination buffer.
934
U_CAPI UChar* U_EXPORT2
935
u_strFromUTF32(UChar *dest,
936
int32_t destCapacity,
937
int32_t *pDestLength,
940
UErrorCode *pErrorCode);