jpayne@69: // © 2016 and later: Unicode, Inc. and others. jpayne@69: // License & terms of use: http://www.unicode.org/copyright.html jpayne@69: /* jpayne@69: ******************************************************************************* jpayne@69: * jpayne@69: * Copyright (C) 2005-2012, International Business Machines jpayne@69: * Corporation and others. All Rights Reserved. jpayne@69: * jpayne@69: ******************************************************************************* jpayne@69: * file name: ucasemap.h jpayne@69: * encoding: UTF-8 jpayne@69: * tab size: 8 (not used) jpayne@69: * indentation:4 jpayne@69: * jpayne@69: * created on: 2005may06 jpayne@69: * created by: Markus W. Scherer jpayne@69: * jpayne@69: * Case mapping service object and functions using it. jpayne@69: */ jpayne@69: jpayne@69: #ifndef __UCASEMAP_H__ jpayne@69: #define __UCASEMAP_H__ jpayne@69: jpayne@69: #include "unicode/utypes.h" jpayne@69: #include "unicode/localpointer.h" jpayne@69: #include "unicode/stringoptions.h" jpayne@69: #include "unicode/ustring.h" jpayne@69: jpayne@69: /** jpayne@69: * \file jpayne@69: * \brief C API: Unicode case mapping functions using a UCaseMap service object. jpayne@69: * jpayne@69: * The service object takes care of memory allocations, data loading, and setup jpayne@69: * for the attributes, as usual. jpayne@69: * jpayne@69: * Currently, the functionality provided here does not overlap with uchar.h jpayne@69: * and ustring.h, except for ucasemap_toTitle(). jpayne@69: * jpayne@69: * ucasemap_utf8XYZ() functions operate directly on UTF-8 strings. jpayne@69: */ jpayne@69: jpayne@69: /** jpayne@69: * UCaseMap is an opaque service object for newer ICU case mapping functions. jpayne@69: * Older functions did not use a service object. jpayne@69: * @stable ICU 3.4 jpayne@69: */ jpayne@69: struct UCaseMap; jpayne@69: typedef struct UCaseMap UCaseMap; /**< C typedef for struct UCaseMap. @stable ICU 3.4 */ jpayne@69: jpayne@69: /** jpayne@69: * Open a UCaseMap service object for a locale and a set of options. jpayne@69: * The locale ID and options are preprocessed so that functions using the jpayne@69: * service object need not process them in each call. jpayne@69: * jpayne@69: * @param locale ICU locale ID, used for language-dependent jpayne@69: * upper-/lower-/title-casing according to the Unicode standard. jpayne@69: * Usual semantics: ""=root, NULL=default locale, etc. jpayne@69: * @param options Options bit set, used for case folding and string comparisons. jpayne@69: * Same flags as for u_foldCase(), u_strFoldCase(), jpayne@69: * u_strCaseCompare(), etc. jpayne@69: * Use 0 or U_FOLD_CASE_DEFAULT for default behavior. jpayne@69: * @param pErrorCode Must be a valid pointer to an error code value, jpayne@69: * which must not indicate a failure before the function call. jpayne@69: * @return Pointer to a UCaseMap service object, if successful. jpayne@69: * jpayne@69: * @see U_FOLD_CASE_DEFAULT jpayne@69: * @see U_FOLD_CASE_EXCLUDE_SPECIAL_I jpayne@69: * @see U_TITLECASE_NO_LOWERCASE jpayne@69: * @see U_TITLECASE_NO_BREAK_ADJUSTMENT jpayne@69: * @stable ICU 3.4 jpayne@69: */ jpayne@69: U_STABLE UCaseMap * U_EXPORT2 jpayne@69: ucasemap_open(const char *locale, uint32_t options, UErrorCode *pErrorCode); jpayne@69: jpayne@69: /** jpayne@69: * Close a UCaseMap service object. jpayne@69: * @param csm Object to be closed. jpayne@69: * @stable ICU 3.4 jpayne@69: */ jpayne@69: U_STABLE void U_EXPORT2 jpayne@69: ucasemap_close(UCaseMap *csm); jpayne@69: jpayne@69: #if U_SHOW_CPLUSPLUS_API jpayne@69: jpayne@69: U_NAMESPACE_BEGIN jpayne@69: jpayne@69: /** jpayne@69: * \class LocalUCaseMapPointer jpayne@69: * "Smart pointer" class, closes a UCaseMap via ucasemap_close(). jpayne@69: * For most methods see the LocalPointerBase base class. jpayne@69: * jpayne@69: * @see LocalPointerBase jpayne@69: * @see LocalPointer jpayne@69: * @stable ICU 4.4 jpayne@69: */ jpayne@69: U_DEFINE_LOCAL_OPEN_POINTER(LocalUCaseMapPointer, UCaseMap, ucasemap_close); jpayne@69: jpayne@69: U_NAMESPACE_END jpayne@69: jpayne@69: #endif jpayne@69: jpayne@69: /** jpayne@69: * Get the locale ID that is used for language-dependent case mappings. jpayne@69: * @param csm UCaseMap service object. jpayne@69: * @return locale ID jpayne@69: * @stable ICU 3.4 jpayne@69: */ jpayne@69: U_STABLE const char * U_EXPORT2 jpayne@69: ucasemap_getLocale(const UCaseMap *csm); jpayne@69: jpayne@69: /** jpayne@69: * Get the options bit set that is used for case folding and string comparisons. jpayne@69: * @param csm UCaseMap service object. jpayne@69: * @return options bit set jpayne@69: * @stable ICU 3.4 jpayne@69: */ jpayne@69: U_STABLE uint32_t U_EXPORT2 jpayne@69: ucasemap_getOptions(const UCaseMap *csm); jpayne@69: jpayne@69: /** jpayne@69: * Set the locale ID that is used for language-dependent case mappings. jpayne@69: * jpayne@69: * @param csm UCaseMap service object. jpayne@69: * @param locale Locale ID, see ucasemap_open(). jpayne@69: * @param pErrorCode Must be a valid pointer to an error code value, jpayne@69: * which must not indicate a failure before the function call. jpayne@69: * jpayne@69: * @see ucasemap_open jpayne@69: * @stable ICU 3.4 jpayne@69: */ jpayne@69: U_STABLE void U_EXPORT2 jpayne@69: ucasemap_setLocale(UCaseMap *csm, const char *locale, UErrorCode *pErrorCode); jpayne@69: jpayne@69: /** jpayne@69: * Set the options bit set that is used for case folding and string comparisons. jpayne@69: * jpayne@69: * @param csm UCaseMap service object. jpayne@69: * @param options Options bit set, see ucasemap_open(). jpayne@69: * @param pErrorCode Must be a valid pointer to an error code value, jpayne@69: * which must not indicate a failure before the function call. jpayne@69: * jpayne@69: * @see ucasemap_open jpayne@69: * @stable ICU 3.4 jpayne@69: */ jpayne@69: U_STABLE void U_EXPORT2 jpayne@69: ucasemap_setOptions(UCaseMap *csm, uint32_t options, UErrorCode *pErrorCode); jpayne@69: jpayne@69: #if !UCONFIG_NO_BREAK_ITERATION jpayne@69: jpayne@69: /** jpayne@69: * Get the break iterator that is used for titlecasing. jpayne@69: * Do not modify the returned break iterator. jpayne@69: * @param csm UCaseMap service object. jpayne@69: * @return titlecasing break iterator jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: U_STABLE const UBreakIterator * U_EXPORT2 jpayne@69: ucasemap_getBreakIterator(const UCaseMap *csm); jpayne@69: jpayne@69: /** jpayne@69: * Set the break iterator that is used for titlecasing. jpayne@69: * The UCaseMap service object releases a previously set break iterator jpayne@69: * and "adopts" this new one, taking ownership of it. jpayne@69: * It will be released in a subsequent call to ucasemap_setBreakIterator() jpayne@69: * or ucasemap_close(). jpayne@69: * jpayne@69: * Break iterator operations are not thread-safe. Therefore, titlecasing jpayne@69: * functions use non-const UCaseMap objects. It is not possible to titlecase jpayne@69: * strings concurrently using the same UCaseMap. jpayne@69: * jpayne@69: * @param csm UCaseMap service object. jpayne@69: * @param iterToAdopt Break iterator to be adopted for titlecasing. jpayne@69: * @param pErrorCode Must be a valid pointer to an error code value, jpayne@69: * which must not indicate a failure before the function call. jpayne@69: * jpayne@69: * @see ucasemap_toTitle jpayne@69: * @see ucasemap_utf8ToTitle jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: U_STABLE void U_EXPORT2 jpayne@69: ucasemap_setBreakIterator(UCaseMap *csm, UBreakIterator *iterToAdopt, UErrorCode *pErrorCode); jpayne@69: jpayne@69: /** jpayne@69: * Titlecase a UTF-16 string. This function is almost a duplicate of u_strToTitle(), jpayne@69: * except that it takes ucasemap_setOptions() into account and has performance jpayne@69: * advantages from being able to use a UCaseMap object for multiple case mapping jpayne@69: * operations, saving setup time. jpayne@69: * jpayne@69: * Casing is locale-dependent and context-sensitive. jpayne@69: * Titlecasing uses a break iterator to find the first characters of words jpayne@69: * that are to be titlecased. It titlecases those characters and lowercases jpayne@69: * all others. (This can be modified with ucasemap_setOptions().) jpayne@69: * jpayne@69: * Note: This function takes a non-const UCaseMap pointer because it will jpayne@69: * open a default break iterator if no break iterator was set yet, jpayne@69: * and effectively call ucasemap_setBreakIterator(); jpayne@69: * also because the break iterator is stateful and will be modified during jpayne@69: * the iteration. jpayne@69: * jpayne@69: * The titlecase break iterator can be provided to customize for arbitrary jpayne@69: * styles, using rules and dictionaries beyond the standard iterators. jpayne@69: * The standard titlecase iterator for the root locale implements the jpayne@69: * algorithm of Unicode TR 21. jpayne@69: * jpayne@69: * This function uses only the setText(), first() and next() methods of the jpayne@69: * provided break iterator. jpayne@69: * jpayne@69: * The result may be longer or shorter than the original. jpayne@69: * The source string and the destination buffer must not overlap. jpayne@69: * jpayne@69: * @param csm UCaseMap service object. This pointer is non-const! jpayne@69: * See the note above for details. jpayne@69: * @param dest A buffer for the result string. The result will be NUL-terminated if jpayne@69: * the buffer is large enough. jpayne@69: * The contents is undefined in case of failure. jpayne@69: * @param destCapacity The size of the buffer (number of UChars). If it is 0, then jpayne@69: * dest may be NULL and the function will only return the length of the result jpayne@69: * without writing any of the result string. jpayne@69: * @param src The original string. jpayne@69: * @param srcLength The length of the original string. If -1, then src must be NUL-terminated. jpayne@69: * @param pErrorCode Must be a valid pointer to an error code value, jpayne@69: * which must not indicate a failure before the function call. jpayne@69: * @return The length of the result string, if successful - or in case of a buffer overflow, jpayne@69: * in which case it will be greater than destCapacity. jpayne@69: * jpayne@69: * @see u_strToTitle jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: U_STABLE int32_t U_EXPORT2 jpayne@69: ucasemap_toTitle(UCaseMap *csm, jpayne@69: UChar *dest, int32_t destCapacity, jpayne@69: const UChar *src, int32_t srcLength, jpayne@69: UErrorCode *pErrorCode); jpayne@69: jpayne@69: #endif // UCONFIG_NO_BREAK_ITERATION jpayne@69: jpayne@69: /** jpayne@69: * Lowercase the characters in a UTF-8 string. jpayne@69: * Casing is locale-dependent and context-sensitive. jpayne@69: * The result may be longer or shorter than the original. jpayne@69: * The source string and the destination buffer must not overlap. jpayne@69: * jpayne@69: * @param csm UCaseMap service object. jpayne@69: * @param dest A buffer for the result string. The result will be NUL-terminated if jpayne@69: * the buffer is large enough. jpayne@69: * The contents is undefined in case of failure. jpayne@69: * @param destCapacity The size of the buffer (number of bytes). If it is 0, then jpayne@69: * dest may be NULL and the function will only return the length of the result jpayne@69: * without writing any of the result string. jpayne@69: * @param src The original string. jpayne@69: * @param srcLength The length of the original string. If -1, then src must be NUL-terminated. jpayne@69: * @param pErrorCode Must be a valid pointer to an error code value, jpayne@69: * which must not indicate a failure before the function call. jpayne@69: * @return The length of the result string, if successful - or in case of a buffer overflow, jpayne@69: * in which case it will be greater than destCapacity. jpayne@69: * jpayne@69: * @see u_strToLower jpayne@69: * @stable ICU 3.4 jpayne@69: */ jpayne@69: U_STABLE int32_t U_EXPORT2 jpayne@69: ucasemap_utf8ToLower(const UCaseMap *csm, jpayne@69: char *dest, int32_t destCapacity, jpayne@69: const char *src, int32_t srcLength, jpayne@69: UErrorCode *pErrorCode); jpayne@69: jpayne@69: /** jpayne@69: * Uppercase the characters in a UTF-8 string. jpayne@69: * Casing is locale-dependent and context-sensitive. jpayne@69: * The result may be longer or shorter than the original. jpayne@69: * The source string and the destination buffer must not overlap. jpayne@69: * jpayne@69: * @param csm UCaseMap service object. jpayne@69: * @param dest A buffer for the result string. The result will be NUL-terminated if jpayne@69: * the buffer is large enough. jpayne@69: * The contents is undefined in case of failure. jpayne@69: * @param destCapacity The size of the buffer (number of bytes). If it is 0, then jpayne@69: * dest may be NULL and the function will only return the length of the result jpayne@69: * without writing any of the result string. jpayne@69: * @param src The original string. jpayne@69: * @param srcLength The length of the original string. If -1, then src must be NUL-terminated. jpayne@69: * @param pErrorCode Must be a valid pointer to an error code value, jpayne@69: * which must not indicate a failure before the function call. jpayne@69: * @return The length of the result string, if successful - or in case of a buffer overflow, jpayne@69: * in which case it will be greater than destCapacity. jpayne@69: * jpayne@69: * @see u_strToUpper jpayne@69: * @stable ICU 3.4 jpayne@69: */ jpayne@69: U_STABLE int32_t U_EXPORT2 jpayne@69: ucasemap_utf8ToUpper(const UCaseMap *csm, jpayne@69: char *dest, int32_t destCapacity, jpayne@69: const char *src, int32_t srcLength, jpayne@69: UErrorCode *pErrorCode); jpayne@69: jpayne@69: #if !UCONFIG_NO_BREAK_ITERATION jpayne@69: jpayne@69: /** jpayne@69: * Titlecase a UTF-8 string. jpayne@69: * Casing is locale-dependent and context-sensitive. jpayne@69: * Titlecasing uses a break iterator to find the first characters of words jpayne@69: * that are to be titlecased. It titlecases those characters and lowercases jpayne@69: * all others. (This can be modified with ucasemap_setOptions().) jpayne@69: * jpayne@69: * Note: This function takes a non-const UCaseMap pointer because it will jpayne@69: * open a default break iterator if no break iterator was set yet, jpayne@69: * and effectively call ucasemap_setBreakIterator(); jpayne@69: * also because the break iterator is stateful and will be modified during jpayne@69: * the iteration. jpayne@69: * jpayne@69: * The titlecase break iterator can be provided to customize for arbitrary jpayne@69: * styles, using rules and dictionaries beyond the standard iterators. jpayne@69: * The standard titlecase iterator for the root locale implements the jpayne@69: * algorithm of Unicode TR 21. jpayne@69: * jpayne@69: * This function uses only the setUText(), first(), next() and close() methods of the jpayne@69: * provided break iterator. jpayne@69: * jpayne@69: * The result may be longer or shorter than the original. jpayne@69: * The source string and the destination buffer must not overlap. jpayne@69: * jpayne@69: * @param csm UCaseMap service object. This pointer is non-const! jpayne@69: * See the note above for details. jpayne@69: * @param dest A buffer for the result string. The result will be NUL-terminated if jpayne@69: * the buffer is large enough. jpayne@69: * The contents is undefined in case of failure. jpayne@69: * @param destCapacity The size of the buffer (number of bytes). If it is 0, then jpayne@69: * dest may be NULL and the function will only return the length of the result jpayne@69: * without writing any of the result string. jpayne@69: * @param src The original string. jpayne@69: * @param srcLength The length of the original string. If -1, then src must be NUL-terminated. jpayne@69: * @param pErrorCode Must be a valid pointer to an error code value, jpayne@69: * which must not indicate a failure before the function call. jpayne@69: * @return The length of the result string, if successful - or in case of a buffer overflow, jpayne@69: * in which case it will be greater than destCapacity. jpayne@69: * jpayne@69: * @see u_strToTitle jpayne@69: * @see U_TITLECASE_NO_LOWERCASE jpayne@69: * @see U_TITLECASE_NO_BREAK_ADJUSTMENT jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: U_STABLE int32_t U_EXPORT2 jpayne@69: ucasemap_utf8ToTitle(UCaseMap *csm, jpayne@69: char *dest, int32_t destCapacity, jpayne@69: const char *src, int32_t srcLength, jpayne@69: UErrorCode *pErrorCode); jpayne@69: jpayne@69: #endif jpayne@69: jpayne@69: /** jpayne@69: * Case-folds the characters in a UTF-8 string. jpayne@69: * jpayne@69: * Case-folding is locale-independent and not context-sensitive, jpayne@69: * but there is an option for whether to include or exclude mappings for dotted I jpayne@69: * and dotless i that are marked with 'T' in CaseFolding.txt. jpayne@69: * jpayne@69: * The result may be longer or shorter than the original. jpayne@69: * The source string and the destination buffer must not overlap. jpayne@69: * jpayne@69: * @param csm UCaseMap service object. jpayne@69: * @param dest A buffer for the result string. The result will be NUL-terminated if jpayne@69: * the buffer is large enough. jpayne@69: * The contents is undefined in case of failure. jpayne@69: * @param destCapacity The size of the buffer (number of bytes). If it is 0, then jpayne@69: * dest may be NULL and the function will only return the length of the result jpayne@69: * without writing any of the result string. jpayne@69: * @param src The original string. jpayne@69: * @param srcLength The length of the original string. If -1, then src must be NUL-terminated. jpayne@69: * @param pErrorCode Must be a valid pointer to an error code value, jpayne@69: * which must not indicate a failure before the function call. jpayne@69: * @return The length of the result string, if successful - or in case of a buffer overflow, jpayne@69: * in which case it will be greater than destCapacity. jpayne@69: * jpayne@69: * @see u_strFoldCase jpayne@69: * @see ucasemap_setOptions jpayne@69: * @see U_FOLD_CASE_DEFAULT jpayne@69: * @see U_FOLD_CASE_EXCLUDE_SPECIAL_I jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: U_STABLE int32_t U_EXPORT2 jpayne@69: ucasemap_utf8FoldCase(const UCaseMap *csm, jpayne@69: char *dest, int32_t destCapacity, jpayne@69: const char *src, int32_t srcLength, jpayne@69: UErrorCode *pErrorCode); jpayne@69: jpayne@69: #endif