]>
Commit | Line | Data |
---|---|---|
f3c0d7a5 A |
1 | // © 2016 and later: Unicode, Inc. and others. |
2 | // License & terms of use: http://www.unicode.org/copyright.html | |
73c04bcf A |
3 | /* |
4 | ******************************************************************************* | |
5 | * | |
51004dcb | 6 | * Copyright (C) 2005-2012, International Business Machines |
73c04bcf A |
7 | * Corporation and others. All Rights Reserved. |
8 | * | |
9 | ******************************************************************************* | |
10 | * file name: ucasemap.h | |
f3c0d7a5 | 11 | * encoding: UTF-8 |
73c04bcf A |
12 | * tab size: 8 (not used) |
13 | * indentation:4 | |
14 | * | |
15 | * created on: 2005may06 | |
16 | * created by: Markus W. Scherer | |
17 | * | |
18 | * Case mapping service object and functions using it. | |
19 | */ | |
20 | ||
21 | #ifndef __UCASEMAP_H__ | |
22 | #define __UCASEMAP_H__ | |
23 | ||
24 | #include "unicode/utypes.h" | |
729e4ab9 | 25 | #include "unicode/localpointer.h" |
0f5d89e8 | 26 | #include "unicode/stringoptions.h" |
f3c0d7a5 | 27 | #include "unicode/ustring.h" |
73c04bcf A |
28 | |
29 | /** | |
30 | * \file | |
31 | * \brief C API: Unicode case mapping functions using a UCaseMap service object. | |
32 | * | |
33 | * The service object takes care of memory allocations, data loading, and setup | |
34 | * for the attributes, as usual. | |
35 | * | |
36 | * Currently, the functionality provided here does not overlap with uchar.h | |
46f4442e | 37 | * and ustring.h, except for ucasemap_toTitle(). |
73c04bcf | 38 | * |
46f4442e | 39 | * ucasemap_utf8XYZ() functions operate directly on UTF-8 strings. |
73c04bcf A |
40 | */ |
41 | ||
42 | /** | |
43 | * UCaseMap is an opaque service object for newer ICU case mapping functions. | |
44 | * Older functions did not use a service object. | |
46f4442e | 45 | * @stable ICU 3.4 |
73c04bcf A |
46 | */ |
47 | struct UCaseMap; | |
46f4442e | 48 | typedef struct UCaseMap UCaseMap; /**< C typedef for struct UCaseMap. @stable ICU 3.4 */ |
73c04bcf A |
49 | |
50 | /** | |
51 | * Open a UCaseMap service object for a locale and a set of options. | |
52 | * The locale ID and options are preprocessed so that functions using the | |
53 | * service object need not process them in each call. | |
54 | * | |
55 | * @param locale ICU locale ID, used for language-dependent | |
56 | * upper-/lower-/title-casing according to the Unicode standard. | |
57 | * Usual semantics: ""=root, NULL=default locale, etc. | |
58 | * @param options Options bit set, used for case folding and string comparisons. | |
59 | * Same flags as for u_foldCase(), u_strFoldCase(), | |
60 | * u_strCaseCompare(), etc. | |
61 | * Use 0 or U_FOLD_CASE_DEFAULT for default behavior. | |
62 | * @param pErrorCode Must be a valid pointer to an error code value, | |
63 | * which must not indicate a failure before the function call. | |
64 | * @return Pointer to a UCaseMap service object, if successful. | |
65 | * | |
46f4442e A |
66 | * @see U_FOLD_CASE_DEFAULT |
67 | * @see U_FOLD_CASE_EXCLUDE_SPECIAL_I | |
68 | * @see U_TITLECASE_NO_LOWERCASE | |
69 | * @see U_TITLECASE_NO_BREAK_ADJUSTMENT | |
70 | * @stable ICU 3.4 | |
73c04bcf | 71 | */ |
46f4442e | 72 | U_STABLE UCaseMap * U_EXPORT2 |
73c04bcf A |
73 | ucasemap_open(const char *locale, uint32_t options, UErrorCode *pErrorCode); |
74 | ||
75 | /** | |
76 | * Close a UCaseMap service object. | |
77 | * @param csm Object to be closed. | |
46f4442e | 78 | * @stable ICU 3.4 |
73c04bcf | 79 | */ |
46f4442e | 80 | U_STABLE void U_EXPORT2 |
73c04bcf A |
81 | ucasemap_close(UCaseMap *csm); |
82 | ||
729e4ab9 A |
83 | #if U_SHOW_CPLUSPLUS_API |
84 | ||
85 | U_NAMESPACE_BEGIN | |
86 | ||
87 | /** | |
88 | * \class LocalUCaseMapPointer | |
89 | * "Smart pointer" class, closes a UCaseMap via ucasemap_close(). | |
90 | * For most methods see the LocalPointerBase base class. | |
91 | * | |
92 | * @see LocalPointerBase | |
93 | * @see LocalPointer | |
94 | * @stable ICU 4.4 | |
95 | */ | |
96 | U_DEFINE_LOCAL_OPEN_POINTER(LocalUCaseMapPointer, UCaseMap, ucasemap_close); | |
97 | ||
98 | U_NAMESPACE_END | |
99 | ||
f3c0d7a5 | 100 | #endif // U_SHOW_CPLUSPLUS_API |
729e4ab9 | 101 | |
73c04bcf A |
102 | /** |
103 | * Get the locale ID that is used for language-dependent case mappings. | |
104 | * @param csm UCaseMap service object. | |
105 | * @return locale ID | |
46f4442e | 106 | * @stable ICU 3.4 |
73c04bcf | 107 | */ |
46f4442e | 108 | U_STABLE const char * U_EXPORT2 |
73c04bcf A |
109 | ucasemap_getLocale(const UCaseMap *csm); |
110 | ||
111 | /** | |
112 | * Get the options bit set that is used for case folding and string comparisons. | |
113 | * @param csm UCaseMap service object. | |
114 | * @return options bit set | |
46f4442e | 115 | * @stable ICU 3.4 |
73c04bcf | 116 | */ |
46f4442e | 117 | U_STABLE uint32_t U_EXPORT2 |
73c04bcf A |
118 | ucasemap_getOptions(const UCaseMap *csm); |
119 | ||
120 | /** | |
121 | * Set the locale ID that is used for language-dependent case mappings. | |
122 | * | |
123 | * @param csm UCaseMap service object. | |
124 | * @param locale Locale ID, see ucasemap_open(). | |
125 | * @param pErrorCode Must be a valid pointer to an error code value, | |
126 | * which must not indicate a failure before the function call. | |
127 | * | |
128 | * @see ucasemap_open | |
46f4442e | 129 | * @stable ICU 3.4 |
73c04bcf | 130 | */ |
46f4442e | 131 | U_STABLE void U_EXPORT2 |
73c04bcf A |
132 | ucasemap_setLocale(UCaseMap *csm, const char *locale, UErrorCode *pErrorCode); |
133 | ||
134 | /** | |
135 | * Set the options bit set that is used for case folding and string comparisons. | |
136 | * | |
137 | * @param csm UCaseMap service object. | |
138 | * @param options Options bit set, see ucasemap_open(). | |
139 | * @param pErrorCode Must be a valid pointer to an error code value, | |
140 | * which must not indicate a failure before the function call. | |
141 | * | |
142 | * @see ucasemap_open | |
46f4442e | 143 | * @stable ICU 3.4 |
73c04bcf | 144 | */ |
46f4442e | 145 | U_STABLE void U_EXPORT2 |
73c04bcf A |
146 | ucasemap_setOptions(UCaseMap *csm, uint32_t options, UErrorCode *pErrorCode); |
147 | ||
46f4442e A |
148 | #if !UCONFIG_NO_BREAK_ITERATION |
149 | ||
150 | /** | |
151 | * Get the break iterator that is used for titlecasing. | |
152 | * Do not modify the returned break iterator. | |
153 | * @param csm UCaseMap service object. | |
154 | * @return titlecasing break iterator | |
729e4ab9 | 155 | * @stable ICU 3.8 |
46f4442e | 156 | */ |
729e4ab9 | 157 | U_STABLE const UBreakIterator * U_EXPORT2 |
46f4442e A |
158 | ucasemap_getBreakIterator(const UCaseMap *csm); |
159 | ||
160 | /** | |
161 | * Set the break iterator that is used for titlecasing. | |
162 | * The UCaseMap service object releases a previously set break iterator | |
163 | * and "adopts" this new one, taking ownership of it. | |
164 | * It will be released in a subsequent call to ucasemap_setBreakIterator() | |
165 | * or ucasemap_close(). | |
166 | * | |
167 | * Break iterator operations are not thread-safe. Therefore, titlecasing | |
168 | * functions use non-const UCaseMap objects. It is not possible to titlecase | |
169 | * strings concurrently using the same UCaseMap. | |
170 | * | |
171 | * @param csm UCaseMap service object. | |
172 | * @param iterToAdopt Break iterator to be adopted for titlecasing. | |
173 | * @param pErrorCode Must be a valid pointer to an error code value, | |
174 | * which must not indicate a failure before the function call. | |
175 | * | |
176 | * @see ucasemap_toTitle | |
177 | * @see ucasemap_utf8ToTitle | |
729e4ab9 | 178 | * @stable ICU 3.8 |
46f4442e | 179 | */ |
729e4ab9 | 180 | U_STABLE void U_EXPORT2 |
46f4442e A |
181 | ucasemap_setBreakIterator(UCaseMap *csm, UBreakIterator *iterToAdopt, UErrorCode *pErrorCode); |
182 | ||
183 | /** | |
184 | * Titlecase a UTF-16 string. This function is almost a duplicate of u_strToTitle(), | |
185 | * except that it takes ucasemap_setOptions() into account and has performance | |
186 | * advantages from being able to use a UCaseMap object for multiple case mapping | |
187 | * operations, saving setup time. | |
188 | * | |
189 | * Casing is locale-dependent and context-sensitive. | |
190 | * Titlecasing uses a break iterator to find the first characters of words | |
191 | * that are to be titlecased. It titlecases those characters and lowercases | |
192 | * all others. (This can be modified with ucasemap_setOptions().) | |
193 | * | |
729e4ab9 A |
194 | * Note: This function takes a non-const UCaseMap pointer because it will |
195 | * open a default break iterator if no break iterator was set yet, | |
196 | * and effectively call ucasemap_setBreakIterator(); | |
197 | * also because the break iterator is stateful and will be modified during | |
198 | * the iteration. | |
199 | * | |
46f4442e A |
200 | * The titlecase break iterator can be provided to customize for arbitrary |
201 | * styles, using rules and dictionaries beyond the standard iterators. | |
46f4442e A |
202 | * The standard titlecase iterator for the root locale implements the |
203 | * algorithm of Unicode TR 21. | |
204 | * | |
0f5d89e8 | 205 | * This function uses only the setText(), first() and next() methods of the |
46f4442e A |
206 | * provided break iterator. |
207 | * | |
208 | * The result may be longer or shorter than the original. | |
209 | * The source string and the destination buffer must not overlap. | |
210 | * | |
729e4ab9 A |
211 | * @param csm UCaseMap service object. This pointer is non-const! |
212 | * See the note above for details. | |
46f4442e A |
213 | * @param dest A buffer for the result string. The result will be NUL-terminated if |
214 | * the buffer is large enough. | |
215 | * The contents is undefined in case of failure. | |
f3c0d7a5 | 216 | * @param destCapacity The size of the buffer (number of UChars). If it is 0, then |
46f4442e A |
217 | * dest may be NULL and the function will only return the length of the result |
218 | * without writing any of the result string. | |
219 | * @param src The original string. | |
220 | * @param srcLength The length of the original string. If -1, then src must be NUL-terminated. | |
221 | * @param pErrorCode Must be a valid pointer to an error code value, | |
222 | * which must not indicate a failure before the function call. | |
223 | * @return The length of the result string, if successful - or in case of a buffer overflow, | |
224 | * in which case it will be greater than destCapacity. | |
225 | * | |
226 | * @see u_strToTitle | |
729e4ab9 | 227 | * @stable ICU 3.8 |
46f4442e | 228 | */ |
729e4ab9 | 229 | U_STABLE int32_t U_EXPORT2 |
46f4442e A |
230 | ucasemap_toTitle(UCaseMap *csm, |
231 | UChar *dest, int32_t destCapacity, | |
232 | const UChar *src, int32_t srcLength, | |
233 | UErrorCode *pErrorCode); | |
234 | ||
f3c0d7a5 | 235 | #endif // UCONFIG_NO_BREAK_ITERATION |
46f4442e | 236 | |
73c04bcf A |
237 | /** |
238 | * Lowercase the characters in a UTF-8 string. | |
239 | * Casing is locale-dependent and context-sensitive. | |
240 | * The result may be longer or shorter than the original. | |
241 | * The source string and the destination buffer must not overlap. | |
242 | * | |
243 | * @param csm UCaseMap service object. | |
244 | * @param dest A buffer for the result string. The result will be NUL-terminated if | |
245 | * the buffer is large enough. | |
246 | * The contents is undefined in case of failure. | |
247 | * @param destCapacity The size of the buffer (number of bytes). If it is 0, then | |
248 | * dest may be NULL and the function will only return the length of the result | |
249 | * without writing any of the result string. | |
46f4442e | 250 | * @param src The original string. |
73c04bcf A |
251 | * @param srcLength The length of the original string. If -1, then src must be NUL-terminated. |
252 | * @param pErrorCode Must be a valid pointer to an error code value, | |
253 | * which must not indicate a failure before the function call. | |
254 | * @return The length of the result string, if successful - or in case of a buffer overflow, | |
255 | * in which case it will be greater than destCapacity. | |
256 | * | |
257 | * @see u_strToLower | |
46f4442e | 258 | * @stable ICU 3.4 |
73c04bcf | 259 | */ |
46f4442e | 260 | U_STABLE int32_t U_EXPORT2 |
73c04bcf A |
261 | ucasemap_utf8ToLower(const UCaseMap *csm, |
262 | char *dest, int32_t destCapacity, | |
263 | const char *src, int32_t srcLength, | |
264 | UErrorCode *pErrorCode); | |
265 | ||
266 | /** | |
267 | * Uppercase the characters in a UTF-8 string. | |
268 | * Casing is locale-dependent and context-sensitive. | |
269 | * The result may be longer or shorter than the original. | |
270 | * The source string and the destination buffer must not overlap. | |
271 | * | |
272 | * @param csm UCaseMap service object. | |
273 | * @param dest A buffer for the result string. The result will be NUL-terminated if | |
274 | * the buffer is large enough. | |
275 | * The contents is undefined in case of failure. | |
276 | * @param destCapacity The size of the buffer (number of bytes). If it is 0, then | |
277 | * dest may be NULL and the function will only return the length of the result | |
278 | * without writing any of the result string. | |
46f4442e | 279 | * @param src The original string. |
73c04bcf A |
280 | * @param srcLength The length of the original string. If -1, then src must be NUL-terminated. |
281 | * @param pErrorCode Must be a valid pointer to an error code value, | |
282 | * which must not indicate a failure before the function call. | |
283 | * @return The length of the result string, if successful - or in case of a buffer overflow, | |
284 | * in which case it will be greater than destCapacity. | |
285 | * | |
286 | * @see u_strToUpper | |
46f4442e | 287 | * @stable ICU 3.4 |
73c04bcf | 288 | */ |
46f4442e | 289 | U_STABLE int32_t U_EXPORT2 |
73c04bcf A |
290 | ucasemap_utf8ToUpper(const UCaseMap *csm, |
291 | char *dest, int32_t destCapacity, | |
292 | const char *src, int32_t srcLength, | |
293 | UErrorCode *pErrorCode); | |
294 | ||
46f4442e A |
295 | #if !UCONFIG_NO_BREAK_ITERATION |
296 | ||
297 | /** | |
298 | * Titlecase a UTF-8 string. | |
299 | * Casing is locale-dependent and context-sensitive. | |
300 | * Titlecasing uses a break iterator to find the first characters of words | |
301 | * that are to be titlecased. It titlecases those characters and lowercases | |
302 | * all others. (This can be modified with ucasemap_setOptions().) | |
303 | * | |
729e4ab9 A |
304 | * Note: This function takes a non-const UCaseMap pointer because it will |
305 | * open a default break iterator if no break iterator was set yet, | |
306 | * and effectively call ucasemap_setBreakIterator(); | |
307 | * also because the break iterator is stateful and will be modified during | |
308 | * the iteration. | |
309 | * | |
46f4442e A |
310 | * The titlecase break iterator can be provided to customize for arbitrary |
311 | * styles, using rules and dictionaries beyond the standard iterators. | |
46f4442e A |
312 | * The standard titlecase iterator for the root locale implements the |
313 | * algorithm of Unicode TR 21. | |
314 | * | |
729e4ab9 | 315 | * This function uses only the setUText(), first(), next() and close() methods of the |
46f4442e A |
316 | * provided break iterator. |
317 | * | |
318 | * The result may be longer or shorter than the original. | |
319 | * The source string and the destination buffer must not overlap. | |
320 | * | |
729e4ab9 A |
321 | * @param csm UCaseMap service object. This pointer is non-const! |
322 | * See the note above for details. | |
46f4442e A |
323 | * @param dest A buffer for the result string. The result will be NUL-terminated if |
324 | * the buffer is large enough. | |
325 | * The contents is undefined in case of failure. | |
326 | * @param destCapacity The size of the buffer (number of bytes). If it is 0, then | |
327 | * dest may be NULL and the function will only return the length of the result | |
328 | * without writing any of the result string. | |
329 | * @param src The original string. | |
330 | * @param srcLength The length of the original string. If -1, then src must be NUL-terminated. | |
331 | * @param pErrorCode Must be a valid pointer to an error code value, | |
332 | * which must not indicate a failure before the function call. | |
333 | * @return The length of the result string, if successful - or in case of a buffer overflow, | |
334 | * in which case it will be greater than destCapacity. | |
335 | * | |
336 | * @see u_strToTitle | |
337 | * @see U_TITLECASE_NO_LOWERCASE | |
338 | * @see U_TITLECASE_NO_BREAK_ADJUSTMENT | |
729e4ab9 | 339 | * @stable ICU 3.8 |
46f4442e | 340 | */ |
729e4ab9 | 341 | U_STABLE int32_t U_EXPORT2 |
46f4442e A |
342 | ucasemap_utf8ToTitle(UCaseMap *csm, |
343 | char *dest, int32_t destCapacity, | |
344 | const char *src, int32_t srcLength, | |
345 | UErrorCode *pErrorCode); | |
346 | ||
347 | #endif | |
348 | ||
349 | /** | |
51004dcb A |
350 | * Case-folds the characters in a UTF-8 string. |
351 | * | |
46f4442e A |
352 | * Case-folding is locale-independent and not context-sensitive, |
353 | * but there is an option for whether to include or exclude mappings for dotted I | |
51004dcb A |
354 | * and dotless i that are marked with 'T' in CaseFolding.txt. |
355 | * | |
46f4442e A |
356 | * The result may be longer or shorter than the original. |
357 | * The source string and the destination buffer must not overlap. | |
358 | * | |
359 | * @param csm UCaseMap service object. | |
360 | * @param dest A buffer for the result string. The result will be NUL-terminated if | |
361 | * the buffer is large enough. | |
362 | * The contents is undefined in case of failure. | |
363 | * @param destCapacity The size of the buffer (number of bytes). If it is 0, then | |
364 | * dest may be NULL and the function will only return the length of the result | |
365 | * without writing any of the result string. | |
366 | * @param src The original string. | |
367 | * @param srcLength The length of the original string. If -1, then src must be NUL-terminated. | |
368 | * @param pErrorCode Must be a valid pointer to an error code value, | |
369 | * which must not indicate a failure before the function call. | |
370 | * @return The length of the result string, if successful - or in case of a buffer overflow, | |
371 | * in which case it will be greater than destCapacity. | |
372 | * | |
373 | * @see u_strFoldCase | |
374 | * @see ucasemap_setOptions | |
375 | * @see U_FOLD_CASE_DEFAULT | |
376 | * @see U_FOLD_CASE_EXCLUDE_SPECIAL_I | |
729e4ab9 | 377 | * @stable ICU 3.8 |
46f4442e | 378 | */ |
729e4ab9 | 379 | U_STABLE int32_t U_EXPORT2 |
46f4442e A |
380 | ucasemap_utf8FoldCase(const UCaseMap *csm, |
381 | char *dest, int32_t destCapacity, | |
382 | const char *src, int32_t srcLength, | |
383 | UErrorCode *pErrorCode); | |
384 | ||
73c04bcf | 385 | #endif |