]>
git.saurik.com Git - apple/icu.git/blob - icuSources/common/unicode/ucasemap.h
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 *******************************************************************************
6 * Copyright (C) 2005-2012, International Business Machines
7 * Corporation and others. All Rights Reserved.
9 *******************************************************************************
10 * file name: ucasemap.h
12 * tab size: 8 (not used)
15 * created on: 2005may06
16 * created by: Markus W. Scherer
18 * Case mapping service object and functions using it.
21 #ifndef __UCASEMAP_H__
22 #define __UCASEMAP_H__
24 #include "unicode/utypes.h"
25 #include "unicode/localpointer.h"
26 #include "unicode/stringoptions.h"
27 #include "unicode/ustring.h"
31 * \brief C API: Unicode case mapping functions using a UCaseMap service object.
33 * The service object takes care of memory allocations, data loading, and setup
34 * for the attributes, as usual.
36 * Currently, the functionality provided here does not overlap with uchar.h
37 * and ustring.h, except for ucasemap_toTitle().
39 * ucasemap_utf8XYZ() functions operate directly on UTF-8 strings.
43 * UCaseMap is an opaque service object for newer ICU case mapping functions.
44 * Older functions did not use a service object.
48 typedef struct UCaseMap UCaseMap
; /**< C typedef for struct UCaseMap. @stable ICU 3.4 */
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.
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.
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
72 U_STABLE UCaseMap
* U_EXPORT2
73 ucasemap_open(const char *locale
, uint32_t options
, UErrorCode
*pErrorCode
);
76 * Close a UCaseMap service object.
77 * @param csm Object to be closed.
80 U_STABLE
void U_EXPORT2
81 ucasemap_close(UCaseMap
*csm
);
83 #if U_SHOW_CPLUSPLUS_API
88 * \class LocalUCaseMapPointer
89 * "Smart pointer" class, closes a UCaseMap via ucasemap_close().
90 * For most methods see the LocalPointerBase base class.
92 * @see LocalPointerBase
96 U_DEFINE_LOCAL_OPEN_POINTER(LocalUCaseMapPointer
, UCaseMap
, ucasemap_close
);
100 #endif // U_SHOW_CPLUSPLUS_API
103 * Get the locale ID that is used for language-dependent case mappings.
104 * @param csm UCaseMap service object.
108 U_STABLE
const char * U_EXPORT2
109 ucasemap_getLocale(const UCaseMap
*csm
);
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
117 U_STABLE
uint32_t U_EXPORT2
118 ucasemap_getOptions(const UCaseMap
*csm
);
121 * Set the locale ID that is used for language-dependent case mappings.
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.
131 U_STABLE
void U_EXPORT2
132 ucasemap_setLocale(UCaseMap
*csm
, const char *locale
, UErrorCode
*pErrorCode
);
135 * Set the options bit set that is used for case folding and string comparisons.
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.
145 U_STABLE
void U_EXPORT2
146 ucasemap_setOptions(UCaseMap
*csm
, uint32_t options
, UErrorCode
*pErrorCode
);
148 #if !UCONFIG_NO_BREAK_ITERATION
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
157 U_STABLE
const UBreakIterator
* U_EXPORT2
158 ucasemap_getBreakIterator(const UCaseMap
*csm
);
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().
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.
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.
176 * @see ucasemap_toTitle
177 * @see ucasemap_utf8ToTitle
180 U_STABLE
void U_EXPORT2
181 ucasemap_setBreakIterator(UCaseMap
*csm
, UBreakIterator
*iterToAdopt
, UErrorCode
*pErrorCode
);
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.
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().)
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
200 * The titlecase break iterator can be provided to customize for arbitrary
201 * styles, using rules and dictionaries beyond the standard iterators.
202 * The standard titlecase iterator for the root locale implements the
203 * algorithm of Unicode TR 21.
205 * This function uses only the setText(), first() and next() methods of the
206 * provided break iterator.
208 * The result may be longer or shorter than the original.
209 * The source string and the destination buffer must not overlap.
211 * @param csm UCaseMap service object. This pointer is non-const!
212 * See the note above for details.
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.
216 * @param destCapacity The size of the buffer (number of UChars). If it is 0, then
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.
229 U_STABLE
int32_t U_EXPORT2
230 ucasemap_toTitle(UCaseMap
*csm
,
231 UChar
*dest
, int32_t destCapacity
,
232 const UChar
*src
, int32_t srcLength
,
233 UErrorCode
*pErrorCode
);
235 #endif // UCONFIG_NO_BREAK_ITERATION
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.
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.
250 * @param src The original string.
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.
260 U_STABLE
int32_t U_EXPORT2
261 ucasemap_utf8ToLower(const UCaseMap
*csm
,
262 char *dest
, int32_t destCapacity
,
263 const char *src
, int32_t srcLength
,
264 UErrorCode
*pErrorCode
);
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.
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.
279 * @param src The original string.
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.
289 U_STABLE
int32_t U_EXPORT2
290 ucasemap_utf8ToUpper(const UCaseMap
*csm
,
291 char *dest
, int32_t destCapacity
,
292 const char *src
, int32_t srcLength
,
293 UErrorCode
*pErrorCode
);
295 #if !UCONFIG_NO_BREAK_ITERATION
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().)
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
310 * The titlecase break iterator can be provided to customize for arbitrary
311 * styles, using rules and dictionaries beyond the standard iterators.
312 * The standard titlecase iterator for the root locale implements the
313 * algorithm of Unicode TR 21.
315 * This function uses only the setUText(), first(), next() and close() methods of the
316 * provided break iterator.
318 * The result may be longer or shorter than the original.
319 * The source string and the destination buffer must not overlap.
321 * @param csm UCaseMap service object. This pointer is non-const!
322 * See the note above for details.
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.
337 * @see U_TITLECASE_NO_LOWERCASE
338 * @see U_TITLECASE_NO_BREAK_ADJUSTMENT
341 U_STABLE
int32_t U_EXPORT2
342 ucasemap_utf8ToTitle(UCaseMap
*csm
,
343 char *dest
, int32_t destCapacity
,
344 const char *src
, int32_t srcLength
,
345 UErrorCode
*pErrorCode
);
350 * Case-folds the characters in a UTF-8 string.
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
354 * and dotless i that are marked with 'T' in CaseFolding.txt.
356 * The result may be longer or shorter than the original.
357 * The source string and the destination buffer must not overlap.
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.
374 * @see ucasemap_setOptions
375 * @see U_FOLD_CASE_DEFAULT
376 * @see U_FOLD_CASE_EXCLUDE_SPECIAL_I
379 U_STABLE
int32_t U_EXPORT2
380 ucasemap_utf8FoldCase(const UCaseMap
*csm
,
381 char *dest
, int32_t destCapacity
,
382 const char *src
, int32_t srcLength
,
383 UErrorCode
*pErrorCode
);