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