~ubuntu-branches/ubuntu/gutsy/icu/gutsy-updates

« back to all changes in this revision

Viewing changes to source/common/unicode/ustring.h

  • Committer: Package Import Robot
  • Author(s): Jay Berkenbilt
  • Date: 2005-11-19 11:29:31 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20051119112931-vcizkrp10tli4enw
Tags: 3.4-3
Explicitly build with g++ 3.4.  The current ICU fails its test suite
with 4.0 but not with 3.4.  Future versions should work properly with
4.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
**********************************************************************
3
 
*   Copyright (C) 1998-2001, 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
 
#include "unicode/utypes.h"
19
 
 
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;
24
 
#endif
25
 
 
26
 
/**
27
 
 * \file
28
 
 * \brief C API: Unicode string handling functions
29
 
 *
30
 
 * These C API functions provide Unicode string handling.
31
 
 *
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
35
 
 * (see u_strtok_r()).
36
 
 *
37
 
 * Other functions provide more Unicode-specific functionality like locale-specific
38
 
 * upper/lower-casing and string comparison in code point order.
39
 
 *
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
45
 
 * in 1996.)
46
 
 *
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.)
55
 
 *
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).
61
 
 */
62
 
 
63
 
/**
64
 
 * Determine the length of an array of UChar.
65
 
 *
66
 
 * @param s The array of UChars, NULL (U+0000) terminated.
67
 
 * @return The number of UChars in <TT>chars</TT>, minus the terminator.
68
 
 * @stable
69
 
 */
70
 
U_CAPI int32_t U_EXPORT2
71
 
u_strlen(const UChar *s);
72
 
 
73
 
/**
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.
77
 
 *
78
 
 * This functions is basically the inverse of the UTF_FWD_N() macro (see utf.h).
79
 
 *
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.
84
 
 * @draft ICU 2.0
85
 
 */
86
 
U_CAPI int32_t U_EXPORT2
87
 
u_countChar32(const UChar *s, int32_t length);
88
 
 
89
 
/**
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>.
93
 
 *
94
 
 * @param dst The destination string.
95
 
 * @param src The source string.
96
 
 * @return A pointer to <TT>dst</TT>.
97
 
 * @stable
98
 
 */
99
 
U_CAPI UChar* U_EXPORT2
100
 
u_strcat(UChar     *dst, 
101
 
    const UChar     *src);
102
 
 
103
 
/**
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.
107
 
 *
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>.
112
 
 * @stable
113
 
 */
114
 
U_CAPI UChar* U_EXPORT2
115
 
u_strncat(UChar     *dst, 
116
 
     const UChar     *src, 
117
 
     int32_t     n);
118
 
 
119
 
/**
120
 
 * Find the first occurrence of a specified character in a ustring.
121
 
 *
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>.
126
 
 * @stable
127
 
 */
128
 
U_CAPI UChar*  U_EXPORT2
129
 
u_strchr(const UChar     *s, 
130
 
    UChar     c);
131
 
 
132
 
/**
133
 
 * Find the first occurrence of a substring in a string.
134
 
 *
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>.
139
 
 * @stable
140
 
 */
141
 
U_CAPI UChar * U_EXPORT2
142
 
u_strstr(const UChar *s, const UChar *substring);
143
 
 
144
 
/**
145
 
 * Find the first occurence of a specified code point in a string.
146
 
 *
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.
159
 
 *
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.
166
 
 * @stable
167
 
 */
168
 
U_CAPI UChar * U_EXPORT2
169
 
u_strchr32(const UChar *s, UChar32 c);
170
 
 
171
 
/**
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.
175
 
 *
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.
178
 
 * @stable
179
 
 */
180
 
U_CAPI UChar * U_EXPORT2
181
 
u_strpbrk(const UChar *string, const UChar *matchSet);
182
 
 
183
 
/**
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.
187
 
 *
188
 
 * @see u_strspn
189
 
 * @stable
190
 
 */
191
 
U_CAPI int32_t U_EXPORT2
192
 
u_strcspn(const UChar *string, const UChar *matchSet);
193
 
 
194
 
/**
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.
198
 
 *
199
 
 * @see u_strcspn
200
 
 * @stable
201
 
 */
202
 
U_CAPI int32_t U_EXPORT2
203
 
u_strspn(const UChar *string, const UChar *matchSet);
204
 
 
205
 
/**
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.
216
 
 *
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. The saveState
223
 
 *              parameter should the address of a local variable of type
224
 
 *              UChar *. (i.e. defined "Uhar *myLocalSaveState" and use
225
 
 *              &myLocalSaveState for this parameter).
226
 
 * @return A pointer to the next token found in src, or NULL
227
 
 *         when there are no more tokens.
228
 
 * @stable
229
 
 */
230
 
U_CAPI UChar * U_EXPORT2
231
 
u_strtok_r(UChar    *src, 
232
 
     const UChar    *delim,
233
 
           UChar   **saveState);
234
 
 
235
 
/**
236
 
 * Compare two Unicode strings for bitwise equality (code unit order).
237
 
 *
238
 
 * @param s1 A string to compare.
239
 
 * @param s2 A string to compare.
240
 
 * @return 0 if <TT>s1</TT> and <TT>s2</TT> are bitwise equal; a negative
241
 
 * value if <TT>s1</TT> is bitwise less than <TT>s2,/TT>; a positive
242
 
 * value if <TT>s1</TT> is bitwise greater than <TT>s2,/TT>.
243
 
 * @stable
244
 
 */
245
 
U_CAPI int32_t  U_EXPORT2
246
 
u_strcmp(const UChar     *s1, 
247
 
    const UChar     *s2);
248
 
 
249
 
/**
250
 
 * Compare two Unicode strings in code point order.
251
 
 * This is different in UTF-16 from u_strcmp() if supplementary characters are present:
252
 
 * In UTF-16, supplementary characters (with code points U+10000 and above) are
253
 
 * stored with pairs of surrogate code units. These have values from 0xd800 to
254
 
 * 0xdfff, which means that they compare as less than some other BMP characters
255
 
 * like U+feff. This function compares Unicode strings in code point order.
256
 
 * If eihter of the UTF-16 strings is malformed (i.e., it contains unpaired
257
 
 * surrogates), then the result is not defined.
258
 
 *
259
 
 * @param s1 A string to compare.
260
 
 * @param s2 A string to compare.
261
 
 * @return a negative/zero/positive integer corresponding to whether
262
 
 * the first string is less than/equal to/greater than the second one
263
 
 * in code point order
264
 
 * @draft ICU 1.8
265
 
 */
266
 
U_CAPI int32_t U_EXPORT2
267
 
u_strcmpCodePointOrder(const UChar *s1, const UChar *s2);
268
 
 
269
 
/**
270
 
 * Compare two ustrings for bitwise equality. 
271
 
 * Compares at most <TT>n</TT> characters.
272
 
 *
273
 
 * @param s1 A string to compare.
274
 
 * @param s2 A string to compare.
275
 
 * @param n The maximum number of characters to compare.
276
 
 * @return 0 if <TT>s1</TT> and <TT>s2</TT> are bitwise equal; a negative
277
 
 * value if <TT>s1</TT> is bitwise less than <TT>s2,/TT>; a positive
278
 
 * value if <TT>s1</TT> is bitwise greater than <TT>s2,/TT>.
279
 
 * @stable
280
 
 */
281
 
U_CAPI int32_t U_EXPORT2
282
 
u_strncmp(const UChar     *ucs1, 
283
 
     const UChar     *ucs2, 
284
 
     int32_t     n);
285
 
 
286
 
/**
287
 
 * Compare two Unicode strings in code point order.
288
 
 * This is different in UTF-16 from u_strncmp() if supplementary characters are present.
289
 
 * For details, see u_strcmpCodePointOrder().
290
 
 *
291
 
 * @param s1 A string to compare.
292
 
 * @param s2 A string to compare.
293
 
 * @param n The maximum number of characters to compare.
294
 
 * @return a negative/zero/positive integer corresponding to whether
295
 
 * the first string is less than/equal to/greater than the second one
296
 
 * in code point order
297
 
 * @draft ICU 1.8
298
 
 */
299
 
U_CAPI int32_t U_EXPORT2
300
 
u_strncmpCodePointOrder(const UChar *s1, const UChar *s2, int32_t n);
301
 
 
302
 
/**
303
 
 * Compare two strings case-insensitively using full case folding.
304
 
 * This is equivalent to u_strcmp(u_strFoldCase(s1, options), u_strFoldCase(s2, options)).
305
 
 *
306
 
 * @param s1 A string to compare.
307
 
 * @param s2 A string to compare.
308
 
 * @param options Either U_FOLD_CASE_DEFAULT or U_FOLD_CASE_EXCLUDE_SPECIAL_I
309
 
 * @return A negative, zero, or positive integer indicating the comparison result.
310
 
 * @draft ICU 1.8
311
 
 */
312
 
U_CAPI int32_t U_EXPORT2
313
 
u_strcasecmp(const UChar *s1, const UChar *s2, uint32_t options);
314
 
 
315
 
/**
316
 
 * Compare two strings case-insensitively using full case folding.
317
 
 * This is equivalent to u_strcmp(u_strFoldCase(s1, at most n, options),
318
 
 * u_strFoldCase(s2, at most n, options)).
319
 
 *
320
 
 * @param s1 A string to compare.
321
 
 * @param s2 A string to compare.
322
 
 * @param n The maximum number of characters each string to case-fold and then compare.
323
 
 * @param options Either U_FOLD_CASE_DEFAULT or U_FOLD_CASE_EXCLUDE_SPECIAL_I
324
 
 * @return A negative, zero, or positive integer indicating the comparison result.
325
 
 * @draft ICU 1.8
326
 
 */
327
 
U_CAPI int32_t U_EXPORT2
328
 
u_strncasecmp(const UChar *s1, const UChar *s2, int32_t n, uint32_t options);
329
 
 
330
 
/**
331
 
 * Compare two strings case-insensitively using full case folding.
332
 
 * This is equivalent to u_strcmp(u_strFoldCase(s1, n, options),
333
 
 * u_strFoldCase(s2, n, options)).
334
 
 *
335
 
 * @param s1 A string to compare.
336
 
 * @param s2 A string to compare.
337
 
 * @param n The number of characters in each string to case-fold and then compare.
338
 
 * @param options Either U_FOLD_CASE_DEFAULT or U_FOLD_CASE_EXCLUDE_SPECIAL_I
339
 
 * @return A negative, zero, or positive integer indicating the comparison result.
340
 
 * @draft ICU 2.0
341
 
 */
342
 
U_CAPI int32_t U_EXPORT2
343
 
u_memcasecmp(const UChar *s1, const UChar *s2, int32_t length, uint32_t options);
344
 
 
345
 
/**
346
 
 * Copy a ustring. Adds a null terminator.
347
 
 *
348
 
 * @param dst The destination string.
349
 
 * @param src The source string.
350
 
 * @return A pointer to <TT>dst</TT>.
351
 
 * @stable
352
 
 */
353
 
U_CAPI UChar* U_EXPORT2
354
 
u_strcpy(UChar     *dst, 
355
 
    const UChar     *src);
356
 
 
357
 
/**
358
 
 * Copy a ustring.
359
 
 * Copies at most <TT>n</TT> characters.  The result will be null terminated
360
 
 * if the length of <TT>src</TT> is less than <TT>n</TT>.
361
 
 *
362
 
 * @param dst The destination string.
363
 
 * @param src The source string.
364
 
 * @param n The maximum number of characters to copy.
365
 
 * @return A pointer to <TT>dst</TT>.
366
 
 * @stable
367
 
 */
368
 
U_CAPI UChar* U_EXPORT2
369
 
u_strncpy(UChar     *dst, 
370
 
     const UChar     *src, 
371
 
     int32_t     n);
372
 
 
373
 
/**
374
 
 * Copy a byte string encoded in the default codepage to a ustring.
375
 
 * Adds a null terminator.
376
 
 * Performs a host byte to UChar conversion
377
 
 *
378
 
 * @param dst The destination string.
379
 
 * @param src The source string.
380
 
 * @return A pointer to <TT>dst</TT>.
381
 
 * @stable
382
 
 */
383
 
U_CAPI UChar* U_EXPORT2 u_uastrcpy(UChar *dst,
384
 
               const char *src );
385
 
 
386
 
/**
387
 
 * Copy a byte string encoded in the default codepage to a ustring.
388
 
 * Copies at most <TT>n</TT> characters.  The result will be null terminated
389
 
 * if the length of <TT>src</TT> is less than <TT>n</TT>.
390
 
 * Performs a host byte to UChar conversion
391
 
 *
392
 
 * @param dst The destination string.
393
 
 * @param src The source string.
394
 
 * @param n The maximum number of characters to copy.
395
 
 * @return A pointer to <TT>dst</TT>.
396
 
 * @stable
397
 
 */
398
 
U_CAPI UChar* U_EXPORT2 u_uastrncpy(UChar *dst,
399
 
            const char *src,
400
 
            int32_t n);
401
 
 
402
 
/**
403
 
 * Copy ustring to a byte string encoded in the default codepage.
404
 
 * Adds a null terminator.
405
 
 * Performs a UChar to host byte conversion
406
 
 *
407
 
 * @param dst The destination string.
408
 
 * @param src The source string.
409
 
 * @return A pointer to <TT>dst</TT>.
410
 
 * @stable
411
 
 */
412
 
U_CAPI char* U_EXPORT2 u_austrcpy(char *dst,
413
 
            const UChar *src );
414
 
 
415
 
/**
416
 
 * Copy ustring to a byte string encoded in the default codepage.
417
 
 * Copies at most <TT>n</TT> characters.  The result will be null terminated
418
 
 * if the length of <TT>src</TT> is less than <TT>n</TT>.
419
 
 * Performs a UChar to host byte conversion
420
 
 *
421
 
 * @param dst The destination string.
422
 
 * @param src The source string.
423
 
 * @param n The maximum number of characters to copy.
424
 
 * @return A pointer to <TT>dst</TT>.
425
 
 * @stable
426
 
 */
427
 
U_CAPI char* U_EXPORT2 u_austrncpy(char *dst,
428
 
            const UChar *src,
429
 
            int32_t n );
430
 
 
431
 
/**
432
 
 * Synonym for memcpy(), but with UChars only.
433
 
 * @stable
434
 
 */
435
 
U_CAPI UChar* U_EXPORT2
436
 
u_memcpy(UChar *dest, const UChar *src, int32_t count);
437
 
 
438
 
/**
439
 
 * Synonym for memmove(), but with UChars only.
440
 
 * @stable
441
 
 */
442
 
U_CAPI UChar* U_EXPORT2
443
 
u_memmove(UChar *dest, const UChar *src, int32_t count);
444
 
 
445
 
/**
446
 
 * Initialize <TT>count</TT> characters of <TT>dest</TT> to <TT>c</TT>.
447
 
 *
448
 
 * @param dest The destination string.
449
 
 * @param c The character to initialize the string.
450
 
 * @param count The maximum number of characters to set.
451
 
 * @return A pointer to <TT>dest</TT>.
452
 
 * @stable
453
 
 */
454
 
U_CAPI UChar* U_EXPORT2
455
 
u_memset(UChar *dest, UChar c, int32_t count);
456
 
 
457
 
/**
458
 
 * Compare the first <TT>count</TT> UChars of each buffer.
459
 
 *
460
 
 * @param buf1 The first string to compare.
461
 
 * @param buf2 The second string to compare.
462
 
 * @param count The maximum number of UChars to compare.
463
 
 * @return When buf1 < buf2, a negative number is returned.
464
 
 *      When buf1 == buf2, 0 is returned.
465
 
 *      When buf1 > buf2, a positive number is returned.
466
 
 * @stable
467
 
 */
468
 
U_CAPI int32_t U_EXPORT2
469
 
u_memcmp(const UChar *buf1, const UChar *buf2, int32_t count);
470
 
 
471
 
/**
472
 
 * Compare two Unicode strings in code point order.
473
 
 * This is different in UTF-16 from u_memcmp() if supplementary characters are present.
474
 
 * For details, see u_strcmpCodePointOrder().
475
 
 *
476
 
 * @param s1 A string to compare.
477
 
 * @param s2 A string to compare.
478
 
 * @param n The maximum number of characters to compare.
479
 
 * @return a negative/zero/positive integer corresponding to whether
480
 
 * the first string is less than/equal to/greater than the second one
481
 
 * in code point order
482
 
 * @draft ICU 1.8
483
 
 */
484
 
U_CAPI int32_t U_EXPORT2
485
 
u_memcmpCodePointOrder(const UChar *s1, const UChar *s2, int32_t count);
486
 
 
487
 
/**
488
 
 * Search for a UChar within a Unicode string until <TT>count</TT>
489
 
 * is reached.
490
 
 *
491
 
 * @param src string to search in
492
 
 * @param ch character to find
493
 
 * @param count maximum number of UChars in <TT>src</TT>to search for
494
 
 *      <TT>ch</TT>.
495
 
 * @return A pointer within src, pointing to <TT>ch</TT>, or NULL if it
496
 
 *      was not found.
497
 
 * @stable
498
 
 */
499
 
U_CAPI UChar* U_EXPORT2
500
 
u_memchr(const UChar *src, UChar ch, int32_t count);
501
 
 
502
 
/**
503
 
 * Find the first occurence of a specified code point in a string.
504
 
 *
505
 
 * This function finds code points, which differs for BMP code points
506
 
 * from u_memchr() only for surrogates:
507
 
 * While u_memchr() finds any surrogate code units in a string,
508
 
 * u_memchr32() finds only unmatched surrogate code points,
509
 
 * i.e., only those that do not combine with an adjacent surrogate
510
 
 * to form a supplementary code point.
511
 
 * For example, in a string "\ud800\udc00" u_memchr()
512
 
 * will find code units U+d800 at 0 and U+dc00 at 1,
513
 
 * but u_memchr32() will find neither because they
514
 
 * combine to the code point U+10000.
515
 
 * Either function will find U+d800 in "a\ud800b".
516
 
 * This behavior ensures that UTF_GET_CHAR(u_memchr32(c))==c.
517
 
 *
518
 
 * @param src string to search in
519
 
 * @param ch character to find
520
 
 * @param count maximum number of UChars in <TT>src</TT>to search for
521
 
 *      <TT>ch</TT>.
522
 
 * @return A pointer within src, pointing to <TT>ch</TT>, or NULL if it
523
 
 *      was not found.
524
 
 * @stable
525
 
 */
526
 
U_CAPI UChar* U_EXPORT2
527
 
u_memchr32(const UChar *src, UChar32 ch, int32_t count);
528
 
 
529
 
/**
530
 
 * Unicode String literals in C.
531
 
 * We need one macro to declare a variable for the string
532
 
 * and to statically preinitialize it if possible,
533
 
 * and a second macro to dynamically intialize such a string variable if necessary.
534
 
 *
535
 
 * The macros are defined for maximum performance.
536
 
 * They work only for strings that contain "invariant characters", i.e.,
537
 
 * only latin letters, digits, and some punctuation.
538
 
 * See utypes.h for details.
539
 
 *
540
 
 * A pair of macros for a single string must be used with the same
541
 
 * parameters.
542
 
 * The string parameter must be a C string literal.
543
 
 * The length of the string, not including the terminating
544
 
 * <code>NUL</code>, must be specified as a constant.
545
 
 * The U_STRING_DECL macro should be invoked exactly once for one
546
 
 * such string variable before it is used.
547
 
 *
548
 
 * Usage:
549
 
 * <pre>
550
 
 * &#32;   U_STRING_DECL(ustringVar1, "Quick-Fox 2", 11);
551
 
 * &#32;   U_STRING_DECL(ustringVar2, "jumps 5%", 8);
552
 
 * &#32;   static UBool didInit=FALSE;
553
 
 * &#32;
554
 
 * &#32;   int32_t function() {
555
 
 * &#32;       if(!didInit) {
556
 
 * &#32;           U_STRING_INIT(ustringVar1, "Quick-Fox 2", 11);
557
 
 * &#32;           U_STRING_INIT(ustringVar2, "jumps 5%", 8);
558
 
 * &#32;           didInit=TRUE;
559
 
 * &#32;       }
560
 
 * &#32;       return u_strcmp(ustringVar1, ustringVar2);
561
 
 * &#32;   }
562
 
 * </pre>
563
 
 * @stable
564
 
 */
565
 
#if U_SIZEOF_WCHAR_T==U_SIZEOF_UCHAR && U_CHARSET_FAMILY==U_ASCII_FAMILY
566
 
#   define U_STRING_DECL(var, cs, length) static const wchar_t var[(length)+1]={ L ## cs }
567
 
#   define U_STRING_INIT(var, cs, length)
568
 
#elif U_SIZEOF_UCHAR==1 && U_CHARSET_FAMILY==U_ASCII_FAMILY
569
 
#   define U_STRING_DECL(var, cs, length) static const UChar var[(length)+1]={ (const UChar *)cs }
570
 
#   define U_STRING_INIT(var, cs, length)
571
 
#else
572
 
#   define U_STRING_DECL(var, cs, length) static UChar var[(length)+1]
573
 
#   define U_STRING_INIT(var, cs, length) u_charsToUChars(cs, var, length+1)
574
 
#endif
575
 
 
576
 
/**
577
 
 * Unescape a string of characters and write the resulting
578
 
 * Unicode characters to the destination buffer.  The following escape
579
 
 * sequences are recognized:
580
 
 *
581
 
 * \uhhhh       4 hex digits; h in [0-9A-Fa-f]
582
 
 * \Uhhhhhhhh   8 hex digits
583
 
 * \xhh         1-2 hex digits
584
 
 * \ooo         1-3 octal digits; o in [0-7]
585
 
 *
586
 
 * as well as the standard ANSI C escapes:
587
 
 *
588
 
 * \a => U+0007, \b => U+0008, \t => U+0009, \n => U+000A,
589
 
 * \v => U+000B, \f => U+000C, \r => U+000D,
590
 
 * \" => U+0022, \' => U+0027, \? => U+003F, \\ => U+005C
591
 
 *
592
 
 * Anything else following a backslash is generically escaped.  For
593
 
 * example, "[a\-z]" returns "[a-z]".
594
 
 *
595
 
 * If an escape sequence is ill-formed, this method returns an empty
596
 
 * string.  An example of an ill-formed sequence is "\u" followed by
597
 
 * fewer than 4 hex digits.
598
 
 *
599
 
 * The above characters are recognized in the compiler's codepage,
600
 
 * that is, they are coded as 'u', '\\', etc.  Characters that are
601
 
 * not parts of escape sequences are converted using u_charsToUChars().
602
 
 *
603
 
 * This function is similar to UnicodeString::unescape() but not
604
 
 * identical to it.  The latter takes a source UnicodeString, so it
605
 
 * does escape recognition but no conversion.
606
 
 *
607
 
 * @param src a zero-terminated string of invariant characters
608
 
 * @param dest pointer to buffer to receive converted and unescaped
609
 
 * text and, if there is room, a zero terminator.  May be NULL for
610
 
 * preflighting, in which case no UChars will be written, but the
611
 
 * return value will still be valid.  On error, an empty string is
612
 
 * stored here (if possible).
613
 
 * @param destCapacity the number of UChars that may be written at
614
 
 * dest.  Ignored if dest == NULL.
615
 
 * @return the capacity required to fully convert all of the source
616
 
 * text, including the zero terminator, or 0 on error.
617
 
 * @see u_unescapeAt
618
 
 * @see UnicodeString#unescape()
619
 
 * @see UnicodeString#unescapeAt()
620
 
 * @stable
621
 
 */
622
 
U_CAPI int32_t U_EXPORT2
623
 
u_unescape(const char *src,
624
 
           UChar *dest, int32_t destCapacity);
625
 
 
626
 
/**
627
 
 * Callback function for u_unescapeAt() that returns a character of
628
 
 * the source text given an offset and a context pointer.  The context
629
 
 * pointer will be whatever is passed into u_unescapeAt().
630
 
 *
631
 
 * @see u_unescapeAt
632
 
 * @stable
633
 
 */
634
 
U_CDECL_BEGIN
635
 
typedef UChar (*UNESCAPE_CHAR_AT)(int32_t offset, void *context);
636
 
U_CDECL_END
637
 
 
638
 
/**
639
 
 * Unescape a single sequence. The character at offset-1 is assumed
640
 
 * (without checking) to be a backslash.  This method takes a callback
641
 
 * pointer to a function that returns the UChar at a given offset.  By
642
 
 * varying this callback, ICU functions are able to unescape char*
643
 
 * strings, UnicodeString objects, and UFILE pointers.
644
 
 *
645
 
 * If offset is out of range, or if the escape sequence is ill-formed,
646
 
 * (UChar32)0xFFFFFFFF is returned.  See documentation of u_unescape()
647
 
 * for a list of recognized sequences.
648
 
 *
649
 
 * @param charAt callback function that returns a UChar of the source
650
 
 * text given an offset and a context pointer.
651
 
 * @param offset pointer to the offset that will be passed to charAt.
652
 
 * The offset value will be updated upon return to point after the
653
 
 * last parsed character of the escape sequence.  On error the offset
654
 
 * is unchanged.
655
 
 * @param length the number of characters in the source text.  The
656
 
 * last character of the source text is considered to be at offset
657
 
 * length-1.
658
 
 * @param context an opaque pointer passed directly into charAt.
659
 
 * @return the character represented by the escape sequence at
660
 
 * offset, or (UChar32)0xFFFFFFFF on error.
661
 
 * @see u_unescape()
662
 
 * @see UnicodeString#unescape()
663
 
 * @see UnicodeString#unescapeAt()
664
 
 * @stable
665
 
 */
666
 
U_CAPI UChar32 U_EXPORT2
667
 
u_unescapeAt(UNESCAPE_CHAR_AT charAt,
668
 
             int32_t *offset,
669
 
             int32_t length,
670
 
             void *context);
671
 
 
672
 
/**
673
 
 * Uppercase the characters in a string.
674
 
 * Casing is locale-dependent and context-sensitive.
675
 
 * The result may be longer or shorter than the original.
676
 
 * The source string and the destination buffer are allowed to overlap.
677
 
 *
678
 
 * @param dest      A buffer for the result string. The result will be zero-terminated if
679
 
 *                  the buffer is large enough.
680
 
 * @param destCapacity The size of the buffer (number of UChars). If it is 0, then
681
 
 *                  dest may be NULL and the function will only return the length of the result
682
 
 *                  without writing any of the result string.
683
 
 * @param src       The original string
684
 
 * @param srcLength The length of the original string. If -1, then src must be zero-terminated.
685
 
 * @param locale    The locale to consider, or "" for the root locale or NULL for the default locale.
686
 
 * @param pErrorCode Must be a valid pointer to an error code value,
687
 
 *                  which must not indicate a failure before the function call.
688
 
 * @return The length of the result string. It may be greater than destCapacity. In that case,
689
 
 *         only some of the result was written to the destination buffer.
690
 
 * @draft ICU 1.8
691
 
 */
692
 
U_CAPI int32_t U_EXPORT2
693
 
u_strToUpper(UChar *dest, int32_t destCapacity,
694
 
             const UChar *src, int32_t srcLength,
695
 
             const char *locale,
696
 
             UErrorCode *pErrorCode);
697
 
 
698
 
/**
699
 
 * Lowercase the characters in a string.
700
 
 * Casing is locale-dependent and context-sensitive.
701
 
 * The result may be longer or shorter than the original.
702
 
 * The source string and the destination buffer are allowed to overlap.
703
 
 *
704
 
 * @param dest      A buffer for the result string. The result will be zero-terminated if
705
 
 *                  the buffer is large enough.
706
 
 * @param destCapacity The size of the buffer (number of UChars). If it is 0, then
707
 
 *                  dest may be NULL and the function will only return the length of the result
708
 
 *                  without writing any of the result string.
709
 
 * @param src       The original string
710
 
 * @param srcLength The length of the original string. If -1, then src must be zero-terminated.
711
 
 * @param locale    The locale to consider, or "" for the root locale or NULL for the default locale.
712
 
 * @param pErrorCode Must be a valid pointer to an error code value,
713
 
 *                  which must not indicate a failure before the function call.
714
 
 * @return The length of the result string. It may be greater than destCapacity. In that case,
715
 
 *         only some of the result was written to the destination buffer.
716
 
 * @draft ICU 1.8
717
 
 */
718
 
U_CAPI int32_t U_EXPORT2
719
 
u_strToLower(UChar *dest, int32_t destCapacity,
720
 
             const UChar *src, int32_t srcLength,
721
 
             const char *locale,
722
 
             UErrorCode *pErrorCode);
723
 
 
724
 
/**
725
 
 * Titlecase a string.
726
 
 * Casing is locale-dependent and context-sensitive.
727
 
 * Titlecasing uses a break iterator to find the first characters of words
728
 
 * that are to be titlecased. It titlecases those characters and lowercases
729
 
 * all others.
730
 
 *
731
 
 * The titlecase break iterator can be provided to customize for arbitrary
732
 
 * styles, using rules and dictionaries beyond the standard iterators.
733
 
 * It may be more efficient to always provide an iterator to avoid
734
 
 * opening and closing one for each string.
735
 
 * The standard titlecase iterator for the root locale implements the
736
 
 * algorithm of Unicode TR 21.
737
 
 *
738
 
 * This function uses only the first() and next() methods of the
739
 
 * provided break iterator.
740
 
 *
741
 
 * The result may be longer or shorter than the original.
742
 
 * The source string and the destination buffer are allowed to overlap.
743
 
 *
744
 
 * @param dest      A buffer for the result string. The result will be zero-terminated if
745
 
 *                  the buffer is large enough.
746
 
 * @param destCapacity The size of the buffer (number of UChars). If it is 0, then
747
 
 *                  dest may be NULL and the function will only return the length of the result
748
 
 *                  without writing any of the result string.
749
 
 * @param src       The original string
750
 
 * @param srcLength The length of the original string. If -1, then src must be zero-terminated.
751
 
 * @param titleIter A break iterator to find the first characters of words
752
 
 *                  that are to be titlecased.
753
 
 *                  If none is provided (NULL), then a standard titlecase
754
 
 *                  break iterator is opened.
755
 
 * @param locale    The locale to consider, or "" for the root locale or NULL for the default locale.
756
 
 * @param pErrorCode Must be a valid pointer to an error code value,
757
 
 *                  which must not indicate a failure before the function call.
758
 
 * @return The length of the result string. It may be greater than destCapacity. In that case,
759
 
 *         only some of the result was written to the destination buffer.
760
 
 * @draft ICU 2.1
761
 
 */
762
 
U_CAPI int32_t U_EXPORT2
763
 
u_strToTitle(UChar *dest, int32_t destCapacity,
764
 
             const UChar *src, int32_t srcLength,
765
 
             UBreakIterator *titleIter,
766
 
             const char *locale,
767
 
             UErrorCode *pErrorCode);
768
 
 
769
 
/**
770
 
 * Case-fold the characters in a string.
771
 
 * Case-folding is locale-independent and not context-sensitive,
772
 
 * but there is an option for whether to include or exclude mappings for dotted I
773
 
 * and dotless i that are marked with 'I' in CaseFolding.txt.
774
 
 * The result may be longer or shorter than the original.
775
 
 * The source string and the destination buffer are allowed to overlap.
776
 
 *
777
 
 * @param dest      A buffer for the result string. The result will be zero-terminated if
778
 
 *                  the buffer is large enough.
779
 
 * @param destCapacity The size of the buffer (number of UChars). If it is 0, then
780
 
 *                  dest may be NULL and the function will only return the length of the result
781
 
 *                  without writing any of the result string.
782
 
 * @param src       The original string
783
 
 * @param srcLength The length of the original string. If -1, then src must be zero-terminated.
784
 
 * @param options   Either U_FOLD_CASE_DEFAULT or U_FOLD_CASE_EXCLUDE_SPECIAL_I
785
 
 * @param pErrorCode Must be a valid pointer to an error code value,
786
 
 *                  which must not indicate a failure before the function call.
787
 
 * @return The length of the result string. It may be greater than destCapacity. In that case,
788
 
 *         only some of the result was written to the destination buffer.
789
 
 * @draft ICU 1.8
790
 
 */
791
 
U_CAPI int32_t U_EXPORT2
792
 
u_strFoldCase(UChar *dest, int32_t destCapacity,
793
 
              const UChar *src, int32_t srcLength,
794
 
              uint32_t options,
795
 
              UErrorCode *pErrorCode);
796
 
 
797
 
/**
798
 
 * Converts a sequence of UChars to wchar_t units.
799
 
 *
800
 
 * @param dest          A buffer for the result string. The result will be zero-terminated if
801
 
 *                      the buffer is large enough.
802
 
 * @param destCapacity  The size of the buffer (number of UChars). If it is 0, then
803
 
 *                      dest may be NULL and the function will only return the length of the 
804
 
 *                      result without writing any of the result string (pre-flighting).
805
 
 * @param pDestLength   A pointer to receive the number of units written to the destination. If 
806
 
 *                      pDestLength!=NULL then *pDestLength is always set to the 
807
 
 *                      number of output units corresponding to the transformation of 
808
 
 *                      all the input units, even in case of a buffer overflow.
809
 
 * @param src           The original source string
810
 
 * @param srcLength     The length of the original string. If -1, then src must be zero-terminated.
811
 
 * @param pErrorCode    Must be a valid pointer to an error code value,
812
 
 *                      which must not indicate a failure before the function call.
813
 
 * @return The pointer to destination buffer.
814
 
 * @draft ICU 2.0
815
 
 */
816
 
U_CAPI wchar_t* U_EXPORT2
817
 
u_strToWCS(wchar_t *dest, 
818
 
           int32_t destCapacity,
819
 
           int32_t *pDestLength,
820
 
           const UChar *src, 
821
 
           int32_t srcLength,
822
 
           UErrorCode *pErrorCode);
823
 
/**
824
 
 * Converts a sequence of wchar_t units to UChars
825
 
 *
826
 
 * @param dest          A buffer for the result string. The result will be zero-terminated if
827
 
 *                      the buffer is large enough.
828
 
 * @param destCapacity  The size of the buffer (number of UChars). If it is 0, then
829
 
 *                      dest may be NULL and the function will only return the length of the 
830
 
 *                      result without writing any of the result string (pre-flighting).
831
 
 * @param pDestLength   A pointer to receive the number of units written to the destination. If 
832
 
 *                      pDestLength!=NULL then *pDestLength is always set to the 
833
 
 *                      number of output units corresponding to the transformation of 
834
 
 *                      all the input units, even in case of a buffer overflow.
835
 
 * @param src           The original source string
836
 
 * @param srcLength     The length of the original string. If -1, then src must be zero-terminated.
837
 
 * @param pErrorCode    Must be a valid pointer to an error code value,
838
 
 *                      which must not indicate a failure before the function call.
839
 
 * @return The pointer to destination buffer.
840
 
 * @draft ICU 2.0
841
 
 */
842
 
U_CAPI UChar* U_EXPORT2
843
 
u_strFromWCS(UChar   *dest,
844
 
             int32_t destCapacity, 
845
 
             int32_t *pDestLength,
846
 
             const wchar_t *src,
847
 
             int32_t srcLength,
848
 
             UErrorCode *pErrorCode);
849
 
/**
850
 
 * Converts a sequence of UChars (UTF-16) to UTF-8 bytes
851
 
 *
852
 
 * @param dest          A buffer for the result string. The result will be zero-terminated if
853
 
 *                      the buffer is large enough.
854
 
 * @param destCapacity  The size of the buffer (number of UChars). If it is 0, then
855
 
 *                      dest may be NULL and the function will only return the length of the 
856
 
 *                      result without writing any of the result string (pre-flighting).
857
 
 * @param pDestLength   A pointer to receive the number of units written to the destination. If 
858
 
 *                      pDestLength!=NULL then *pDestLength is always set to the 
859
 
 *                      number of output units corresponding to the transformation of 
860
 
 *                      all the input units, even in case of a buffer overflow.
861
 
 * @param src           The original source string
862
 
 * @param srcLength     The length of the original string. If -1, then src must be zero-terminated.
863
 
 * @param pErrorCode    Must be a valid pointer to an error code value,
864
 
 *                      which must not indicate a failure before the function call.
865
 
 * @return The pointer to destination buffer.
866
 
 * @draft ICU 2.0
867
 
 */
868
 
U_CAPI char* U_EXPORT2 
869
 
u_strToUTF8(char *dest,           
870
 
            int32_t destCapacity,
871
 
            int32_t *pDestLength,
872
 
            const UChar *src, 
873
 
            int32_t srcLength,
874
 
            UErrorCode *pErrorCode);
875
 
 
876
 
/**
877
 
 * Converts a sequence of UTF-8 bytes to UChars (UTF-16).
878
 
 *
879
 
 * @param dest          A buffer for the result string. The result will be zero-terminated if
880
 
 *                      the buffer is large enough.
881
 
 * @param destCapacity  The size of the buffer (number of UChars). If it is 0, then
882
 
 *                      dest may be NULL and the function will only return the length of the 
883
 
 *                      result without writing any of the result string (pre-flighting).
884
 
 * @param pDestLength   A pointer to receive the number of units written to the destination. If 
885
 
 *                      pDestLength!=NULL then *pDestLength is always set to the 
886
 
 *                      number of output units corresponding to the transformation of 
887
 
 *                      all the input units, even in case of a buffer overflow.
888
 
 * @param src           The original source string
889
 
 * @param srcLength     The length of the original string. If -1, then src must be zero-terminated.
890
 
 * @param pErrorCode    Must be a valid pointer to an error code value,
891
 
 *                      which must not indicate a failure before the function call.
892
 
 * @return The pointer to destination buffer.
893
 
 * @draft ICU 2.0
894
 
 */
895
 
U_CAPI UChar* U_EXPORT2
896
 
u_strFromUTF8(UChar *dest,             
897
 
              int32_t destCapacity,
898
 
              int32_t *pDestLength,
899
 
              const char *src, 
900
 
              int32_t srcLength,
901
 
              UErrorCode *pErrorCode);
902
 
 
903
 
/**
904
 
 * Converts a sequence of UTF32 units to UChars
905
 
 *
906
 
 * @param dest          A buffer for the result string. The result will be zero-terminated if
907
 
 *                      the buffer is large enough.
908
 
 * @param destCapacity  The size of the buffer (number of UChars). If it is 0, then
909
 
 *                      dest may be NULL and the function will only return the length of the 
910
 
 *                      result without writing any of the result string (pre-flighting).
911
 
 * @param pDestLength   A pointer to receive the number of units written to the destination. If 
912
 
 *                      pDestLength!=NULL then *pDestLength is always set to the 
913
 
 *                      number of output units corresponding to the transformation of 
914
 
 *                      all the input units, even in case of a buffer overflow.
915
 
 * @param src           The original source string
916
 
 * @param srcLength     The length of the original string. If -1, then src must be zero-terminated.
917
 
 * @param pErrorCode    Must be a valid pointer to an error code value,
918
 
 *                      which must not indicate a failure before the function call.
919
 
 * @return The pointer to destination buffer.
920
 
 * @draft ICU 2.0
921
 
 */
922
 
U_CAPI UChar32* U_EXPORT2 
923
 
u_strToUTF32(UChar32 *dest, 
924
 
             int32_t  destCapacity,
925
 
             int32_t  *pDestLength,
926
 
             const UChar *src, 
927
 
             int32_t  srcLength,
928
 
             UErrorCode *pErrorCode);
929
 
 
930
 
/**
931
 
 * Converts a sequence of UChars to UTF32 units.
932
 
 *
933
 
 * @param dest          A buffer for the result string. The result will be zero-terminated if
934
 
 *                      the buffer is large enough.
935
 
 * @param destCapacity  The size of the buffer (number of UChars). If it is 0, then
936
 
 *                      dest may be NULL and the function will only return the length of the 
937
 
 *                      result without writing any of the result string (pre-flighting).
938
 
 * @param pDestLength   A pointer to receive the number of units written to the destination. If 
939
 
 *                      pDestLength!=NULL then *pDestLength is always set to the 
940
 
 *                      number of output units corresponding to the transformation of 
941
 
 *                      all the input units, even in case of a buffer overflow.
942
 
 * @param src           The original source string
943
 
 * @param srcLength     The length of the original string. If -1, then src must be zero-terminated.
944
 
 * @param pErrorCode    Must be a valid pointer to an error code value,
945
 
 *                      which must not indicate a failure before the function call.
946
 
 * @return The pointer to destination buffer.
947
 
 * @draft ICU 2.0
948
 
 */
949
 
U_CAPI UChar* U_EXPORT2 
950
 
u_strFromUTF32(UChar   *dest,
951
 
               int32_t destCapacity, 
952
 
               int32_t *pDestLength,
953
 
               const UChar32 *src,
954
 
               int32_t srcLength,
955
 
               UErrorCode *pErrorCode);
956
 
 
957
 
#endif