]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | ********************************************************************** | |
3 | * Copyright (C) 1998-2006, International Business Machines | |
4 | * Corporation and others. All Rights Reserved. | |
5 | ********************************************************************** | |
6 | * | |
7 | * File ustring.h | |
8 | * | |
9 | * Modification History: | |
10 | * | |
11 | * Date Name Description | |
12 | * 12/07/98 bertrand Creation. | |
13 | ****************************************************************************** | |
14 | */ | |
15 | ||
16 | #ifndef USTRING_H | |
17 | #define USTRING_H | |
18 | ||
19 | #include "unicode/utypes.h" | |
20 | #include "unicode/putil.h" | |
21 | #include "unicode/uiter.h" | |
22 | ||
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; | |
27 | #endif | |
28 | ||
29 | /** | |
30 | * \file | |
31 | * \brief C API: Unicode string handling functions | |
32 | * | |
33 | * These C API functions provide general Unicode string handling. | |
34 | * | |
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 | |
38 | * (see u_strtok_r()). | |
39 | * | |
40 | * Other functions provide more Unicode-specific functionality like locale-specific | |
41 | * upper/lower-casing and string comparison in code point order. | |
42 | * | |
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 | |
47 | * in 1996.) | |
48 | * | |
49 | * Some APIs accept a 32-bit UChar32 value for a single code point. | |
50 | * | |
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. | |
55 | * | |
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. | |
61 | * | |
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). | |
67 | * | |
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. | |
71 | */ | |
72 | ||
73 | /** | |
74 | * \defgroup ustring_ustrlen | |
75 | */ | |
76 | /*@{*/ | |
77 | /** | |
78 | * Determine the length of an array of UChar. | |
79 | * | |
80 | * @param s The array of UChars, NULL (U+0000) terminated. | |
81 | * @return The number of UChars in <code>chars</code>, minus the terminator. | |
82 | * @stable ICU 2.0 | |
83 | */ | |
84 | U_STABLE int32_t U_EXPORT2 | |
85 | u_strlen(const UChar *s); | |
86 | /*@}*/ | |
87 | ||
88 | /** | |
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. | |
92 | * | |
93 | * This functions is basically the inverse of the U16_FWD_N() macro (see utf.h). | |
94 | * | |
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. | |
99 | * @stable ICU 2.0 | |
100 | */ | |
101 | U_STABLE int32_t U_EXPORT2 | |
102 | u_countChar32(const UChar *s, int32_t length); | |
103 | ||
104 | /** | |
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. | |
113 | * | |
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). | |
120 | * @stable ICU 2.4 | |
121 | */ | |
122 | U_STABLE UBool U_EXPORT2 | |
123 | u_strHasMoreChar32Than(const UChar *s, int32_t length, int32_t number); | |
124 | ||
125 | /** | |
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>. | |
129 | * | |
130 | * @param dst The destination string. | |
131 | * @param src The source string. | |
132 | * @return A pointer to <code>dst</code>. | |
133 | * @stable ICU 2.0 | |
134 | */ | |
135 | U_STABLE UChar* U_EXPORT2 | |
136 | u_strcat(UChar *dst, | |
137 | const UChar *src); | |
138 | ||
139 | /** | |
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. | |
146 | * | |
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>. | |
151 | * @stable ICU 2.0 | |
152 | */ | |
153 | U_STABLE UChar* U_EXPORT2 | |
154 | u_strncat(UChar *dst, | |
155 | const UChar *src, | |
156 | int32_t n); | |
157 | ||
158 | /** | |
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. | |
166 | * | |
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>. | |
172 | * @stable ICU 2.0 | |
173 | * | |
174 | * @see u_strrstr | |
175 | * @see u_strFindFirst | |
176 | * @see u_strFindLast | |
177 | */ | |
178 | U_STABLE UChar * U_EXPORT2 | |
179 | u_strstr(const UChar *s, const UChar *substring); | |
180 | ||
181 | /** | |
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. | |
189 | * | |
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>. | |
197 | * @stable ICU 2.4 | |
198 | * | |
199 | * @see u_strstr | |
200 | * @see u_strFindLast | |
201 | */ | |
202 | U_STABLE UChar * U_EXPORT2 | |
203 | u_strFindFirst(const UChar *s, int32_t length, const UChar *substring, int32_t subLength); | |
204 | ||
205 | /** | |
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. | |
210 | * | |
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>. | |
215 | * @stable ICU 2.0 | |
216 | * | |
217 | * @see u_strchr32 | |
218 | * @see u_memchr | |
219 | * @see u_strstr | |
220 | * @see u_strFindFirst | |
221 | */ | |
222 | U_STABLE UChar * U_EXPORT2 | |
223 | u_strchr(const UChar *s, UChar c); | |
224 | ||
225 | /** | |
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. | |
230 | * | |
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>. | |
235 | * @stable ICU 2.0 | |
236 | * | |
237 | * @see u_strchr | |
238 | * @see u_memchr32 | |
239 | * @see u_strstr | |
240 | * @see u_strFindFirst | |
241 | */ | |
242 | U_STABLE UChar * U_EXPORT2 | |
243 | u_strchr32(const UChar *s, UChar32 c); | |
244 | ||
245 | /** | |
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. | |
253 | * | |
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>. | |
259 | * @stable ICU 2.4 | |
260 | * | |
261 | * @see u_strstr | |
262 | * @see u_strFindFirst | |
263 | * @see u_strFindLast | |
264 | */ | |
265 | U_STABLE UChar * U_EXPORT2 | |
266 | u_strrstr(const UChar *s, const UChar *substring); | |
267 | ||
268 | /** | |
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. | |
276 | * | |
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>. | |
284 | * @stable ICU 2.4 | |
285 | * | |
286 | * @see u_strstr | |
287 | * @see u_strFindLast | |
288 | */ | |
289 | U_STABLE UChar * U_EXPORT2 | |
290 | u_strFindLast(const UChar *s, int32_t length, const UChar *substring, int32_t subLength); | |
291 | ||
292 | /** | |
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. | |
297 | * | |
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>. | |
302 | * @stable ICU 2.4 | |
303 | * | |
304 | * @see u_strrchr32 | |
305 | * @see u_memrchr | |
306 | * @see u_strrstr | |
307 | * @see u_strFindLast | |
308 | */ | |
309 | U_STABLE UChar * U_EXPORT2 | |
310 | u_strrchr(const UChar *s, UChar c); | |
311 | ||
312 | /** | |
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. | |
317 | * | |
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>. | |
322 | * @stable ICU 2.4 | |
323 | * | |
324 | * @see u_strrchr | |
325 | * @see u_memchr32 | |
326 | * @see u_strrstr | |
327 | * @see u_strFindLast | |
328 | */ | |
329 | U_STABLE UChar * U_EXPORT2 | |
330 | u_strrchr32(const UChar *s, UChar32 c); | |
331 | ||
332 | /** | |
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. | |
336 | * | |
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. | |
342 | * @stable ICU 2.0 | |
343 | */ | |
344 | U_STABLE UChar * U_EXPORT2 | |
345 | u_strpbrk(const UChar *string, const UChar *matchSet); | |
346 | ||
347 | /** | |
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. | |
351 | * | |
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>. | |
357 | * @see u_strspn | |
358 | * @stable ICU 2.0 | |
359 | */ | |
360 | U_STABLE int32_t U_EXPORT2 | |
361 | u_strcspn(const UChar *string, const UChar *matchSet); | |
362 | ||
363 | /** | |
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. | |
367 | * | |
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>. | |
373 | * @see u_strcspn | |
374 | * @stable ICU 2.0 | |
375 | */ | |
376 | U_STABLE int32_t U_EXPORT2 | |
377 | u_strspn(const UChar *string, const UChar *matchSet); | |
378 | ||
379 | /** | |
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. | |
390 | * | |
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. | |
402 | * @stable ICU 2.0 | |
403 | */ | |
404 | U_STABLE UChar * U_EXPORT2 | |
405 | u_strtok_r(UChar *src, | |
406 | const UChar *delim, | |
407 | UChar **saveState); | |
408 | ||
409 | /** | |
410 | * Compare two Unicode strings for bitwise equality (code unit order). | |
411 | * | |
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>. | |
417 | * @stable ICU 2.0 | |
418 | */ | |
419 | U_STABLE int32_t U_EXPORT2 | |
420 | u_strcmp(const UChar *s1, | |
421 | const UChar *s2); | |
422 | ||
423 | /** | |
424 | * Compare two Unicode strings in code point order. | |
425 | * See u_strCompare for details. | |
426 | * | |
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 | |
432 | * @stable ICU 2.0 | |
433 | */ | |
434 | U_STABLE int32_t U_EXPORT2 | |
435 | u_strcmpCodePointOrder(const UChar *s1, const UChar *s2); | |
436 | ||
437 | /** | |
438 | * Compare two Unicode strings (binary order). | |
439 | * | |
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. | |
446 | * | |
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. | |
450 | * | |
451 | * @param s1 First source string. | |
452 | * @param length1 Length of first source string, or -1 if NUL-terminated. | |
453 | * | |
454 | * @param s2 Second source string. | |
455 | * @param length2 Length of second source string, or -1 if NUL-terminated. | |
456 | * | |
457 | * @param codePointOrder Choose between code unit order (FALSE) | |
458 | * and code point order (TRUE). | |
459 | * | |
460 | * @return <0 or 0 or >0 as usual for string comparisons | |
461 | * | |
462 | * @stable ICU 2.2 | |
463 | */ | |
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); | |
468 | ||
469 | /** | |
470 | * Compare two Unicode strings (binary order) | |
471 | * as presented by UCharIterator objects. | |
472 | * Works otherwise just like u_strCompare(). | |
473 | * | |
474 | * Both iterators are reset to their start positions. | |
475 | * When the function returns, it is undefined where the iterators | |
476 | * have stopped. | |
477 | * | |
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). | |
482 | * | |
483 | * @return <0 or 0 or >0 as usual for string comparisons | |
484 | * | |
485 | * @see u_strCompare | |
486 | * | |
487 | * @stable ICU 2.6 | |
488 | */ | |
489 | U_STABLE int32_t U_EXPORT2 | |
490 | u_strCompareIter(UCharIterator *iter1, UCharIterator *iter2, UBool codePointOrder); | |
491 | ||
492 | #ifndef U_COMPARE_CODE_POINT_ORDER | |
493 | /* see also unistr.h and unorm.h */ | |
494 | /** | |
495 | * Option bit for u_strCaseCompare, u_strcasecmp, unorm_compare, etc: | |
496 | * Compare strings in code point order instead of code unit order. | |
497 | * @stable ICU 2.2 | |
498 | */ | |
499 | #define U_COMPARE_CODE_POINT_ORDER 0x8000 | |
500 | #endif | |
501 | ||
502 | /** | |
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). | |
508 | * | |
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. | |
514 | * | |
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. | |
518 | * | |
519 | * @param s1 First source string. | |
520 | * @param length1 Length of first source string, or -1 if NUL-terminated. | |
521 | * | |
522 | * @param s2 Second source string. | |
523 | * @param length2 Length of second source string, or -1 if NUL-terminated. | |
524 | * | |
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. | |
528 | * | |
529 | * - U_COMPARE_CODE_POINT_ORDER | |
530 | * Set to choose code point order instead of code unit order | |
531 | * (see u_strCompare for details). | |
532 | * | |
533 | * - U_FOLD_CASE_EXCLUDE_SPECIAL_I | |
534 | * | |
535 | * @param pErrorCode Must be a valid pointer to an error code value, | |
536 | * which must not indicate a failure before the function call. | |
537 | * | |
538 | * @return <0 or 0 or >0 as usual for string comparisons | |
539 | * | |
540 | * @stable ICU 2.2 | |
541 | */ | |
542 | U_STABLE int32_t U_EXPORT2 | |
543 | u_strCaseCompare(const UChar *s1, int32_t length1, | |
544 | const UChar *s2, int32_t length2, | |
545 | uint32_t options, | |
546 | UErrorCode *pErrorCode); | |
547 | ||
548 | /** | |
549 | * Compare two ustrings for bitwise equality. | |
550 | * Compares at most <code>n</code> characters. | |
551 | * | |
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>. | |
558 | * @stable ICU 2.0 | |
559 | */ | |
560 | U_STABLE int32_t U_EXPORT2 | |
561 | u_strncmp(const UChar *ucs1, | |
562 | const UChar *ucs2, | |
563 | int32_t n); | |
564 | ||
565 | /** | |
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(). | |
569 | * | |
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 | |
576 | * @stable ICU 2.0 | |
577 | */ | |
578 | U_STABLE int32_t U_EXPORT2 | |
579 | u_strncmpCodePointOrder(const UChar *s1, const UChar *s2, int32_t n); | |
580 | ||
581 | /** | |
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)). | |
584 | * | |
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. | |
590 | * | |
591 | * - U_COMPARE_CODE_POINT_ORDER | |
592 | * Set to choose code point order instead of code unit order | |
593 | * (see u_strCompare for details). | |
594 | * | |
595 | * - U_FOLD_CASE_EXCLUDE_SPECIAL_I | |
596 | * | |
597 | * @return A negative, zero, or positive integer indicating the comparison result. | |
598 | * @stable ICU 2.0 | |
599 | */ | |
600 | U_STABLE int32_t U_EXPORT2 | |
601 | u_strcasecmp(const UChar *s1, const UChar *s2, uint32_t options); | |
602 | ||
603 | /** | |
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)). | |
607 | * | |
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. | |
614 | * | |
615 | * - U_COMPARE_CODE_POINT_ORDER | |
616 | * Set to choose code point order instead of code unit order | |
617 | * (see u_strCompare for details). | |
618 | * | |
619 | * - U_FOLD_CASE_EXCLUDE_SPECIAL_I | |
620 | * | |
621 | * @return A negative, zero, or positive integer indicating the comparison result. | |
622 | * @stable ICU 2.0 | |
623 | */ | |
624 | U_STABLE int32_t U_EXPORT2 | |
625 | u_strncasecmp(const UChar *s1, const UChar *s2, int32_t n, uint32_t options); | |
626 | ||
627 | /** | |
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)). | |
631 | * | |
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. | |
638 | * | |
639 | * - U_COMPARE_CODE_POINT_ORDER | |
640 | * Set to choose code point order instead of code unit order | |
641 | * (see u_strCompare for details). | |
642 | * | |
643 | * - U_FOLD_CASE_EXCLUDE_SPECIAL_I | |
644 | * | |
645 | * @return A negative, zero, or positive integer indicating the comparison result. | |
646 | * @stable ICU 2.0 | |
647 | */ | |
648 | U_STABLE int32_t U_EXPORT2 | |
649 | u_memcasecmp(const UChar *s1, const UChar *s2, int32_t length, uint32_t options); | |
650 | ||
651 | /** | |
652 | * Copy a ustring. Adds a null terminator. | |
653 | * | |
654 | * @param dst The destination string. | |
655 | * @param src The source string. | |
656 | * @return A pointer to <code>dst</code>. | |
657 | * @stable ICU 2.0 | |
658 | */ | |
659 | U_STABLE UChar* U_EXPORT2 | |
660 | u_strcpy(UChar *dst, | |
661 | const UChar *src); | |
662 | ||
663 | /** | |
664 | * Copy a ustring. | |
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>. | |
667 | * | |
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>. | |
672 | * @stable ICU 2.0 | |
673 | */ | |
674 | U_STABLE UChar* U_EXPORT2 | |
675 | u_strncpy(UChar *dst, | |
676 | const UChar *src, | |
677 | int32_t n); | |
678 | ||
679 | #if !UCONFIG_NO_CONVERSION | |
680 | ||
681 | /** | |
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 | |
685 | * | |
686 | * @param dst The destination string. | |
687 | * @param src The source string. | |
688 | * @return A pointer to <code>dst</code>. | |
689 | * @stable ICU 2.0 | |
690 | */ | |
691 | U_STABLE UChar* U_EXPORT2 u_uastrcpy(UChar *dst, | |
692 | const char *src ); | |
693 | ||
694 | /** | |
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 | |
699 | * | |
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>. | |
704 | * @stable ICU 2.0 | |
705 | */ | |
706 | U_STABLE UChar* U_EXPORT2 u_uastrncpy(UChar *dst, | |
707 | const char *src, | |
708 | int32_t n); | |
709 | ||
710 | /** | |
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 | |
714 | * | |
715 | * @param dst The destination string. | |
716 | * @param src The source string. | |
717 | * @return A pointer to <code>dst</code>. | |
718 | * @stable ICU 2.0 | |
719 | */ | |
720 | U_STABLE char* U_EXPORT2 u_austrcpy(char *dst, | |
721 | const UChar *src ); | |
722 | ||
723 | /** | |
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 | |
728 | * | |
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>. | |
733 | * @stable ICU 2.0 | |
734 | */ | |
735 | U_STABLE char* U_EXPORT2 u_austrncpy(char *dst, | |
736 | const UChar *src, | |
737 | int32_t n ); | |
738 | ||
739 | #endif | |
740 | ||
741 | /** | |
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> | |
747 | * @stable ICU 2.0 | |
748 | */ | |
749 | U_STABLE UChar* U_EXPORT2 | |
750 | u_memcpy(UChar *dest, const UChar *src, int32_t count); | |
751 | ||
752 | /** | |
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> | |
758 | * @stable ICU 2.0 | |
759 | */ | |
760 | U_STABLE UChar* U_EXPORT2 | |
761 | u_memmove(UChar *dest, const UChar *src, int32_t count); | |
762 | ||
763 | /** | |
764 | * Initialize <code>count</code> characters of <code>dest</code> to <code>c</code>. | |
765 | * | |
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>. | |
770 | * @stable ICU 2.0 | |
771 | */ | |
772 | U_STABLE UChar* U_EXPORT2 | |
773 | u_memset(UChar *dest, UChar c, int32_t count); | |
774 | ||
775 | /** | |
776 | * Compare the first <code>count</code> UChars of each buffer. | |
777 | * | |
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. | |
784 | * @stable ICU 2.0 | |
785 | */ | |
786 | U_STABLE int32_t U_EXPORT2 | |
787 | u_memcmp(const UChar *buf1, const UChar *buf2, int32_t count); | |
788 | ||
789 | /** | |
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(). | |
793 | * | |
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 | |
800 | * @stable ICU 2.0 | |
801 | */ | |
802 | U_STABLE int32_t U_EXPORT2 | |
803 | u_memcmpCodePointOrder(const UChar *s1, const UChar *s2, int32_t count); | |
804 | ||
805 | /** | |
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. | |
810 | * | |
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>. | |
816 | * @stable ICU 2.0 | |
817 | * | |
818 | * @see u_strchr | |
819 | * @see u_memchr32 | |
820 | * @see u_strFindFirst | |
821 | */ | |
822 | U_STABLE UChar* U_EXPORT2 | |
823 | u_memchr(const UChar *s, UChar c, int32_t count); | |
824 | ||
825 | /** | |
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. | |
830 | * | |
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>. | |
836 | * @stable ICU 2.0 | |
837 | * | |
838 | * @see u_strchr32 | |
839 | * @see u_memchr | |
840 | * @see u_strFindFirst | |
841 | */ | |
842 | U_STABLE UChar* U_EXPORT2 | |
843 | u_memchr32(const UChar *s, UChar32 c, int32_t count); | |
844 | ||
845 | /** | |
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. | |
850 | * | |
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>. | |
856 | * @stable ICU 2.4 | |
857 | * | |
858 | * @see u_strrchr | |
859 | * @see u_memrchr32 | |
860 | * @see u_strFindLast | |
861 | */ | |
862 | U_STABLE UChar* U_EXPORT2 | |
863 | u_memrchr(const UChar *s, UChar c, int32_t count); | |
864 | ||
865 | /** | |
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. | |
870 | * | |
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>. | |
876 | * @stable ICU 2.4 | |
877 | * | |
878 | * @see u_strrchr32 | |
879 | * @see u_memrchr | |
880 | * @see u_strFindLast | |
881 | */ | |
882 | U_STABLE UChar* U_EXPORT2 | |
883 | u_memrchr32(const UChar *s, UChar32 c, int32_t count); | |
884 | ||
885 | /** | |
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. | |
890 | * | |
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. | |
895 | * | |
896 | * A pair of macros for a single string must be used with the same | |
897 | * parameters. | |
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. | |
903 | * | |
904 | * Usage: | |
905 | * <pre> | |
906 | * U_STRING_DECL(ustringVar1, "Quick-Fox 2", 11); | |
907 | * U_STRING_DECL(ustringVar2, "jumps 5%", 8); | |
908 | * static UBool didInit=FALSE; | |
909 | * | |
910 | * int32_t function() { | |
911 | * if(!didInit) { | |
912 | * U_STRING_INIT(ustringVar1, "Quick-Fox 2", 11); | |
913 | * U_STRING_INIT(ustringVar2, "jumps 5%", 8); | |
914 | * didInit=TRUE; | |
915 | * } | |
916 | * return u_strcmp(ustringVar1, ustringVar2); | |
917 | * } | |
918 | * </pre> | |
919 | * @stable ICU 2.0 | |
920 | */ | |
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) | |
929 | #else | |
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) | |
933 | #endif | |
934 | ||
935 | /** | |
936 | * Unescape a string of characters and write the resulting | |
937 | * Unicode characters to the destination buffer. The following escape | |
938 | * sequences are recognized: | |
939 | * | |
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 | |
946 | * | |
947 | * as well as the standard ANSI C escapes: | |
948 | * | |
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 | |
952 | * | |
953 | * Anything else following a backslash is generically escaped. For | |
954 | * example, "[a\\-z]" returns "[a-z]". | |
955 | * | |
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. | |
959 | * | |
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(). | |
963 | * | |
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. | |
967 | * | |
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. | |
977 | * @see u_unescapeAt | |
978 | * @see UnicodeString#unescape() | |
979 | * @see UnicodeString#unescapeAt() | |
980 | * @stable ICU 2.0 | |
981 | */ | |
982 | U_STABLE int32_t U_EXPORT2 | |
983 | u_unescape(const char *src, | |
984 | UChar *dest, int32_t destCapacity); | |
985 | ||
986 | U_CDECL_BEGIN | |
987 | /** | |
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(). | |
991 | * | |
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 | |
995 | * offset | |
996 | * @see u_unescapeAt | |
997 | * @stable ICU 2.0 | |
998 | */ | |
999 | typedef UChar (U_CALLCONV *UNESCAPE_CHAR_AT)(int32_t offset, void *context); | |
1000 | U_CDECL_END | |
1001 | ||
1002 | /** | |
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. | |
1008 | * | |
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. | |
1012 | * | |
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 | |
1018 | * is unchanged. | |
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 | |
1021 | * length-1. | |
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. | |
1025 | * @see u_unescape() | |
1026 | * @see UnicodeString#unescape() | |
1027 | * @see UnicodeString#unescapeAt() | |
1028 | * @stable ICU 2.0 | |
1029 | */ | |
1030 | U_STABLE UChar32 U_EXPORT2 | |
1031 | u_unescapeAt(UNESCAPE_CHAR_AT charAt, | |
1032 | int32_t *offset, | |
1033 | int32_t length, | |
1034 | void *context); | |
1035 | ||
1036 | /** | |
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. | |
1041 | * | |
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. | |
1054 | * @stable ICU 2.0 | |
1055 | */ | |
1056 | U_STABLE int32_t U_EXPORT2 | |
1057 | u_strToUpper(UChar *dest, int32_t destCapacity, | |
1058 | const UChar *src, int32_t srcLength, | |
1059 | const char *locale, | |
1060 | UErrorCode *pErrorCode); | |
1061 | ||
1062 | /** | |
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. | |
1067 | * | |
1068 | * @param dest A buffer for the result string. The result will be zero-terminated if | |
1069 | * the buffer is large enough. | |
1070 | * @param destCapacity The size of the buffer (number of UChars). If it is 0, then | |
1071 | * dest may be NULL and the function will only return the length of the result | |
1072 | * without writing any of the result string. | |
1073 | * @param src The original string | |
1074 | * @param srcLength The length of the original string. If -1, then src must be zero-terminated. | |
1075 | * @param locale The locale to consider, or "" for the root locale or NULL for the default locale. | |
1076 | * @param pErrorCode Must be a valid pointer to an error code value, | |
1077 | * which must not indicate a failure before the function call. | |
1078 | * @return The length of the result string. It may be greater than destCapacity. In that case, | |
1079 | * only some of the result was written to the destination buffer. | |
1080 | * @stable ICU 2.0 | |
1081 | */ | |
1082 | U_STABLE int32_t U_EXPORT2 | |
1083 | u_strToLower(UChar *dest, int32_t destCapacity, | |
1084 | const UChar *src, int32_t srcLength, | |
1085 | const char *locale, | |
1086 | UErrorCode *pErrorCode); | |
1087 | ||
1088 | #if !UCONFIG_NO_BREAK_ITERATION | |
1089 | ||
1090 | /** | |
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 | |
1095 | * all others. | |
1096 | * | |
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. | |
1103 | * | |
1104 | * This function uses only the first() and next() methods of the | |
1105 | * provided break iterator. | |
1106 | * | |
1107 | * The result may be longer or shorter than the original. | |
1108 | * The source string and the destination buffer are allowed to overlap. | |
1109 | * | |
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. | |
1126 | * @stable ICU 2.1 | |
1127 | */ | |
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, | |
1132 | const char *locale, | |
1133 | UErrorCode *pErrorCode); | |
1134 | ||
1135 | #endif | |
1136 | ||
1137 | /** | |
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. | |
1144 | * | |
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. | |
1157 | * @stable ICU 2.0 | |
1158 | */ | |
1159 | U_STABLE int32_t U_EXPORT2 | |
1160 | u_strFoldCase(UChar *dest, int32_t destCapacity, | |
1161 | const UChar *src, int32_t srcLength, | |
1162 | uint32_t options, | |
1163 | UErrorCode *pErrorCode); | |
1164 | ||
1165 | #if defined(U_WCHAR_IS_UTF16) || defined(U_WCHAR_IS_UTF32) || !UCONFIG_NO_CONVERSION | |
1166 | /** | |
1167 | * Converts a sequence of UChars to wchar_t units. | |
1168 | * | |
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. | |
1183 | * @stable ICU 2.0 | |
1184 | */ | |
1185 | U_STABLE wchar_t* U_EXPORT2 | |
1186 | u_strToWCS(wchar_t *dest, | |
1187 | int32_t destCapacity, | |
1188 | int32_t *pDestLength, | |
1189 | const UChar *src, | |
1190 | int32_t srcLength, | |
1191 | UErrorCode *pErrorCode); | |
1192 | /** | |
1193 | * Converts a sequence of wchar_t units to UChars | |
1194 | * | |
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. | |
1209 | * @stable ICU 2.0 | |
1210 | */ | |
1211 | U_STABLE UChar* U_EXPORT2 | |
1212 | u_strFromWCS(UChar *dest, | |
1213 | int32_t destCapacity, | |
1214 | int32_t *pDestLength, | |
1215 | const wchar_t *src, | |
1216 | int32_t srcLength, | |
1217 | UErrorCode *pErrorCode); | |
1218 | #endif /* defined(U_WCHAR_IS_UTF16) || defined(U_WCHAR_IS_UTF32) || !UCONFIG_NO_CONVERSION */ | |
1219 | ||
1220 | /** | |
1221 | * Converts a sequence of UChars (UTF-16) to UTF-8 bytes | |
1222 | * | |
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. | |
1237 | * @stable ICU 2.0 | |
1238 | * @see u_strToUTF8WithSub | |
1239 | * @see u_strFromUTF8 | |
1240 | */ | |
1241 | U_STABLE char* U_EXPORT2 | |
1242 | u_strToUTF8(char *dest, | |
1243 | int32_t destCapacity, | |
1244 | int32_t *pDestLength, | |
1245 | const UChar *src, | |
1246 | int32_t srcLength, | |
1247 | UErrorCode *pErrorCode); | |
1248 | ||
1249 | /** | |
1250 | * Converts a sequence of UTF-8 bytes to UChars (UTF-16). | |
1251 | * | |
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. | |
1266 | * @stable ICU 2.0 | |
1267 | * @see u_strFromUTF8WithSub | |
1268 | * @see u_strFromUTF8Lenient | |
1269 | */ | |
1270 | U_STABLE UChar* U_EXPORT2 | |
1271 | u_strFromUTF8(UChar *dest, | |
1272 | int32_t destCapacity, | |
1273 | int32_t *pDestLength, | |
1274 | const char *src, | |
1275 | int32_t srcLength, | |
1276 | UErrorCode *pErrorCode); | |
1277 | ||
1278 | /** | |
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(). | |
1283 | * | |
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. | |
1308 | * @see u_strToUTF8 | |
1309 | * @see u_strFromUTF8WithSub | |
1310 | * @draft ICU 3.6 | |
1311 | */ | |
1312 | U_DRAFT char* U_EXPORT2 | |
1313 | u_strToUTF8WithSub(char *dest, | |
1314 | int32_t destCapacity, | |
1315 | int32_t *pDestLength, | |
1316 | const UChar *src, | |
1317 | int32_t srcLength, | |
1318 | UChar32 subchar, int32_t *pNumSubstitutions, | |
1319 | UErrorCode *pErrorCode); | |
1320 | ||
1321 | /** | |
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(). | |
1326 | * | |
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 | |
1354 | * @draft ICU 3.6 | |
1355 | */ | |
1356 | U_DRAFT UChar* U_EXPORT2 | |
1357 | u_strFromUTF8WithSub(UChar *dest, | |
1358 | int32_t destCapacity, | |
1359 | int32_t *pDestLength, | |
1360 | const char *src, | |
1361 | int32_t srcLength, | |
1362 | UChar32 subchar, int32_t *pNumSubstitutions, | |
1363 | UErrorCode *pErrorCode); | |
1364 | ||
1365 | /** | |
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. | |
1371 | * | |
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 | |
1375 | * the destCapacity. | |
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. | |
1381 | * | |
1382 | * For further performance improvement, if srcLength is given (>=0), | |
1383 | * then it must be destCapacity>=srcLength. | |
1384 | * | |
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 | |
1410 | * @draft ICU 3.6 | |
1411 | */ | |
1412 | U_CAPI UChar * U_EXPORT2 | |
1413 | u_strFromUTF8Lenient(UChar *dest, | |
1414 | int32_t destCapacity, | |
1415 | int32_t *pDestLength, | |
1416 | const char *src, | |
1417 | int32_t srcLength, | |
1418 | UErrorCode *pErrorCode); | |
1419 | ||
1420 | /** | |
1421 | * Converts a sequence of UChars (UTF-16) to UTF32 units. | |
1422 | * | |
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. | |
1437 | * @stable ICU 2.0 | |
1438 | */ | |
1439 | U_STABLE UChar32* U_EXPORT2 | |
1440 | u_strToUTF32(UChar32 *dest, | |
1441 | int32_t destCapacity, | |
1442 | int32_t *pDestLength, | |
1443 | const UChar *src, | |
1444 | int32_t srcLength, | |
1445 | UErrorCode *pErrorCode); | |
1446 | ||
1447 | /** | |
1448 | * Converts a sequence of UTF32 units to UChars (UTF-16) | |
1449 | * | |
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. | |
1464 | * @stable ICU 2.0 | |
1465 | */ | |
1466 | U_STABLE UChar* U_EXPORT2 | |
1467 | u_strFromUTF32(UChar *dest, | |
1468 | int32_t destCapacity, | |
1469 | int32_t *pDestLength, | |
1470 | const UChar32 *src, | |
1471 | int32_t srcLength, | |
1472 | UErrorCode *pErrorCode); | |
1473 | ||
1474 | #endif |