| 1 | // © 2016 and later: Unicode, Inc. and others. |
| 2 | // License & terms of use: http://www.unicode.org/copyright.html |
| 3 | /* |
| 4 | ******************************************************************************* |
| 5 | * |
| 6 | * Copyright (C) 2005-2012, International Business Machines |
| 7 | * Corporation and others. All Rights Reserved. |
| 8 | * |
| 9 | ******************************************************************************* |
| 10 | * file name: ucasemap.h |
| 11 | * encoding: UTF-8 |
| 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" |
| 25 | #include "unicode/localpointer.h" |
| 26 | #include "unicode/stringoptions.h" |
| 27 | #include "unicode/ustring.h" |
| 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 |
| 37 | * and ustring.h, except for ucasemap_toTitle(). |
| 38 | * |
| 39 | * ucasemap_utf8XYZ() functions operate directly on UTF-8 strings. |
| 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. |
| 45 | * @stable ICU 3.4 |
| 46 | */ |
| 47 | struct UCaseMap; |
| 48 | typedef struct UCaseMap UCaseMap; /**< C typedef for struct UCaseMap. @stable ICU 3.4 */ |
| 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 | * |
| 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 |
| 71 | */ |
| 72 | U_STABLE UCaseMap * U_EXPORT2 |
| 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. |
| 78 | * @stable ICU 3.4 |
| 79 | */ |
| 80 | U_STABLE void U_EXPORT2 |
| 81 | ucasemap_close(UCaseMap *csm); |
| 82 | |
| 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 | |
| 100 | #endif |
| 101 | |
| 102 | /** |
| 103 | * Get the locale ID that is used for language-dependent case mappings. |
| 104 | * @param csm UCaseMap service object. |
| 105 | * @return locale ID |
| 106 | * @stable ICU 3.4 |
| 107 | */ |
| 108 | U_STABLE const char * U_EXPORT2 |
| 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 |
| 115 | * @stable ICU 3.4 |
| 116 | */ |
| 117 | U_STABLE uint32_t U_EXPORT2 |
| 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 |
| 129 | * @stable ICU 3.4 |
| 130 | */ |
| 131 | U_STABLE void U_EXPORT2 |
| 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 |
| 143 | * @stable ICU 3.4 |
| 144 | */ |
| 145 | U_STABLE void U_EXPORT2 |
| 146 | ucasemap_setOptions(UCaseMap *csm, uint32_t options, UErrorCode *pErrorCode); |
| 147 | |
| 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 |
| 155 | * @stable ICU 3.8 |
| 156 | */ |
| 157 | U_STABLE const UBreakIterator * U_EXPORT2 |
| 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 |
| 178 | * @stable ICU 3.8 |
| 179 | */ |
| 180 | U_STABLE void U_EXPORT2 |
| 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 | * |
| 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 | * |
| 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. |
| 204 | * |
| 205 | * This function uses only the setText(), first() and next() methods of the |
| 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 | * |
| 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. |
| 225 | * |
| 226 | * @see u_strToTitle |
| 227 | * @stable ICU 3.8 |
| 228 | */ |
| 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); |
| 234 | |
| 235 | #endif // UCONFIG_NO_BREAK_ITERATION |
| 236 | |
| 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. |
| 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. |
| 256 | * |
| 257 | * @see u_strToLower |
| 258 | * @stable ICU 3.4 |
| 259 | */ |
| 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); |
| 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. |
| 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. |
| 285 | * |
| 286 | * @see u_strToUpper |
| 287 | * @stable ICU 3.4 |
| 288 | */ |
| 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); |
| 294 | |
| 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 | * |
| 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 | * |
| 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. |
| 314 | * |
| 315 | * This function uses only the setUText(), first(), next() and close() methods of the |
| 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 | * |
| 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. |
| 335 | * |
| 336 | * @see u_strToTitle |
| 337 | * @see U_TITLECASE_NO_LOWERCASE |
| 338 | * @see U_TITLECASE_NO_BREAK_ADJUSTMENT |
| 339 | * @stable ICU 3.8 |
| 340 | */ |
| 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); |
| 346 | |
| 347 | #endif |
| 348 | |
| 349 | /** |
| 350 | * Case-folds the characters in a UTF-8 string. |
| 351 | * |
| 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. |
| 355 | * |
| 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 |
| 377 | * @stable ICU 3.8 |
| 378 | */ |
| 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); |
| 384 | |
| 385 | #endif |
| 386 | |