Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/unicode/ucasemap.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // © 2016 and later: Unicode, Inc. and others.
0002 // License & terms of use: http://www.unicode.org/copyright.html
0003 /*
0004 *******************************************************************************
0005 *
0006 *   Copyright (C) 2005-2012, International Business Machines
0007 *   Corporation and others.  All Rights Reserved.
0008 *
0009 *******************************************************************************
0010 *   file name:  ucasemap.h
0011 *   encoding:   UTF-8
0012 *   tab size:   8 (not used)
0013 *   indentation:4
0014 *
0015 *   created on: 2005may06
0016 *   created by: Markus W. Scherer
0017 *
0018 *   Case mapping service object and functions using it.
0019 */
0020 
0021 #ifndef __UCASEMAP_H__
0022 #define __UCASEMAP_H__
0023 
0024 #include "unicode/utypes.h"
0025 #include "unicode/stringoptions.h"
0026 #include "unicode/ustring.h"
0027 
0028 #if U_SHOW_CPLUSPLUS_API
0029 #include "unicode/localpointer.h"
0030 #endif   // U_SHOW_CPLUSPLUS_API
0031 
0032 /**
0033  * \file
0034  * \brief C API: Unicode case mapping functions using a UCaseMap service object.
0035  *
0036  * The service object takes care of memory allocations, data loading, and setup
0037  * for the attributes, as usual.
0038  *
0039  * Currently, the functionality provided here does not overlap with uchar.h
0040  * and ustring.h, except for ucasemap_toTitle().
0041  *
0042  * ucasemap_utf8XYZ() functions operate directly on UTF-8 strings.
0043  */
0044 
0045 /**
0046  * UCaseMap is an opaque service object for newer ICU case mapping functions.
0047  * Older functions did not use a service object.
0048  * @stable ICU 3.4
0049  */
0050 struct UCaseMap;
0051 typedef struct UCaseMap UCaseMap; /**< C typedef for struct UCaseMap. @stable ICU 3.4 */
0052 
0053 /**
0054  * Open a UCaseMap service object for a locale and a set of options.
0055  * The locale ID and options are preprocessed so that functions using the
0056  * service object need not process them in each call.
0057  *
0058  * @param locale ICU locale ID, used for language-dependent
0059  *               upper-/lower-/title-casing according to the Unicode standard.
0060  *               Usual semantics: ""=root, NULL=default locale, etc.
0061  * @param options Options bit set, used for case folding and string comparisons.
0062  *                Same flags as for u_foldCase(), u_strFoldCase(),
0063  *                u_strCaseCompare(), etc.
0064  *                Use 0 or U_FOLD_CASE_DEFAULT for default behavior.
0065  * @param pErrorCode Must be a valid pointer to an error code value,
0066  *                   which must not indicate a failure before the function call.
0067  * @return Pointer to a UCaseMap service object, if successful.
0068  *
0069  * @see U_FOLD_CASE_DEFAULT
0070  * @see U_FOLD_CASE_EXCLUDE_SPECIAL_I
0071  * @see U_TITLECASE_NO_LOWERCASE
0072  * @see U_TITLECASE_NO_BREAK_ADJUSTMENT
0073  * @stable ICU 3.4
0074  */
0075 U_CAPI UCaseMap * U_EXPORT2
0076 ucasemap_open(const char *locale, uint32_t options, UErrorCode *pErrorCode);
0077 
0078 /**
0079  * Close a UCaseMap service object.
0080  * @param csm Object to be closed.
0081  * @stable ICU 3.4
0082  */
0083 U_CAPI void U_EXPORT2
0084 ucasemap_close(UCaseMap *csm);
0085 
0086 #if U_SHOW_CPLUSPLUS_API
0087 
0088 U_NAMESPACE_BEGIN
0089 
0090 /**
0091  * \class LocalUCaseMapPointer
0092  * "Smart pointer" class, closes a UCaseMap via ucasemap_close().
0093  * For most methods see the LocalPointerBase base class.
0094  *
0095  * @see LocalPointerBase
0096  * @see LocalPointer
0097  * @stable ICU 4.4
0098  */
0099 U_DEFINE_LOCAL_OPEN_POINTER(LocalUCaseMapPointer, UCaseMap, ucasemap_close);
0100 
0101 U_NAMESPACE_END
0102 
0103 #endif
0104 
0105 /**
0106  * Get the locale ID that is used for language-dependent case mappings.
0107  * @param csm UCaseMap service object.
0108  * @return locale ID
0109  * @stable ICU 3.4
0110  */
0111 U_CAPI const char * U_EXPORT2
0112 ucasemap_getLocale(const UCaseMap *csm);
0113 
0114 /**
0115  * Get the options bit set that is used for case folding and string comparisons.
0116  * @param csm UCaseMap service object.
0117  * @return options bit set
0118  * @stable ICU 3.4
0119  */
0120 U_CAPI uint32_t U_EXPORT2
0121 ucasemap_getOptions(const UCaseMap *csm);
0122 
0123 /**
0124  * Set the locale ID that is used for language-dependent case mappings.
0125  *
0126  * @param csm UCaseMap service object.
0127  * @param locale Locale ID, see ucasemap_open().
0128  * @param pErrorCode Must be a valid pointer to an error code value,
0129  *                   which must not indicate a failure before the function call.
0130  *
0131  * @see ucasemap_open
0132  * @stable ICU 3.4
0133  */
0134 U_CAPI void U_EXPORT2
0135 ucasemap_setLocale(UCaseMap *csm, const char *locale, UErrorCode *pErrorCode);
0136 
0137 /**
0138  * Set the options bit set that is used for case folding and string comparisons.
0139  *
0140  * @param csm UCaseMap service object.
0141  * @param options Options bit set, see ucasemap_open().
0142  * @param pErrorCode Must be a valid pointer to an error code value,
0143  *                   which must not indicate a failure before the function call.
0144  *
0145  * @see ucasemap_open
0146  * @stable ICU 3.4
0147  */
0148 U_CAPI void U_EXPORT2
0149 ucasemap_setOptions(UCaseMap *csm, uint32_t options, UErrorCode *pErrorCode);
0150 
0151 #if !UCONFIG_NO_BREAK_ITERATION
0152 
0153 /**
0154  * Get the break iterator that is used for titlecasing.
0155  * Do not modify the returned break iterator.
0156  * @param csm UCaseMap service object.
0157  * @return titlecasing break iterator
0158  * @stable ICU 3.8
0159  */
0160 U_CAPI const UBreakIterator * U_EXPORT2
0161 ucasemap_getBreakIterator(const UCaseMap *csm);
0162 
0163 /**
0164  * Set the break iterator that is used for titlecasing.
0165  * The UCaseMap service object releases a previously set break iterator
0166  * and "adopts" this new one, taking ownership of it.
0167  * It will be released in a subsequent call to ucasemap_setBreakIterator()
0168  * or ucasemap_close().
0169  *
0170  * Break iterator operations are not thread-safe. Therefore, titlecasing
0171  * functions use non-const UCaseMap objects. It is not possible to titlecase
0172  * strings concurrently using the same UCaseMap.
0173  *
0174  * @param csm UCaseMap service object.
0175  * @param iterToAdopt Break iterator to be adopted for titlecasing.
0176  * @param pErrorCode Must be a valid pointer to an error code value,
0177  *                   which must not indicate a failure before the function call.
0178  *
0179  * @see ucasemap_toTitle
0180  * @see ucasemap_utf8ToTitle
0181  * @stable ICU 3.8
0182  */
0183 U_CAPI void U_EXPORT2
0184 ucasemap_setBreakIterator(UCaseMap *csm, UBreakIterator *iterToAdopt, UErrorCode *pErrorCode);
0185 
0186 /**
0187  * Titlecase a UTF-16 string. This function is almost a duplicate of u_strToTitle(),
0188  * except that it takes ucasemap_setOptions() into account and has performance
0189  * advantages from being able to use a UCaseMap object for multiple case mapping
0190  * operations, saving setup time.
0191  *
0192  * Casing is locale-dependent and context-sensitive.
0193  * Titlecasing uses a break iterator to find the first characters of words
0194  * that are to be titlecased. It titlecases those characters and lowercases
0195  * all others. (This can be modified with ucasemap_setOptions().)
0196  *
0197  * Note: This function takes a non-const UCaseMap pointer because it will
0198  * open a default break iterator if no break iterator was set yet,
0199  * and effectively call ucasemap_setBreakIterator();
0200  * also because the break iterator is stateful and will be modified during
0201  * the iteration.
0202  *
0203  * The titlecase break iterator can be provided to customize for arbitrary
0204  * styles, using rules and dictionaries beyond the standard iterators.
0205  * The standard titlecase iterator for the root locale implements the
0206  * algorithm of Unicode TR 21.
0207  *
0208  * This function uses only the setText(), first() and next() methods of the
0209  * provided break iterator.
0210  *
0211  * The result may be longer or shorter than the original.
0212  * The source string and the destination buffer must not overlap.
0213  *
0214  * @param csm       UCaseMap service object. This pointer is non-const!
0215  *                  See the note above for details.
0216  * @param dest      A buffer for the result string. The result will be NUL-terminated if
0217  *                  the buffer is large enough.
0218  *                  The contents is undefined in case of failure.
0219  * @param destCapacity The size of the buffer (number of UChars). If it is 0, then
0220  *                  dest may be NULL and the function will only return the length of the result
0221  *                  without writing any of the result string.
0222  * @param src       The original string.
0223  * @param srcLength The length of the original string. If -1, then src must be NUL-terminated.
0224  * @param pErrorCode Must be a valid pointer to an error code value,
0225  *                  which must not indicate a failure before the function call.
0226  * @return The length of the result string, if successful - or in case of a buffer overflow,
0227  *         in which case it will be greater than destCapacity.
0228  *
0229  * @see u_strToTitle
0230  * @stable ICU 3.8
0231  */
0232 U_CAPI int32_t U_EXPORT2
0233 ucasemap_toTitle(UCaseMap *csm,
0234                  UChar *dest, int32_t destCapacity,
0235                  const UChar *src, int32_t srcLength,
0236                  UErrorCode *pErrorCode);
0237 
0238 #endif  // UCONFIG_NO_BREAK_ITERATION
0239 
0240 /**
0241  * Lowercase the characters in a UTF-8 string.
0242  * Casing is locale-dependent and context-sensitive.
0243  * The result may be longer or shorter than the original.
0244  * The source string and the destination buffer must not overlap.
0245  *
0246  * @param csm       UCaseMap service object.
0247  * @param dest      A buffer for the result string. The result will be NUL-terminated if
0248  *                  the buffer is large enough.
0249  *                  The contents is undefined in case of failure.
0250  * @param destCapacity The size of the buffer (number of bytes). If it is 0, then
0251  *                  dest may be NULL and the function will only return the length of the result
0252  *                  without writing any of the result string.
0253  * @param src       The original string.
0254  * @param srcLength The length of the original string. If -1, then src must be NUL-terminated.
0255  * @param pErrorCode Must be a valid pointer to an error code value,
0256  *                  which must not indicate a failure before the function call.
0257  * @return The length of the result string, if successful - or in case of a buffer overflow,
0258  *         in which case it will be greater than destCapacity.
0259  *
0260  * @see u_strToLower
0261  * @stable ICU 3.4
0262  */
0263 U_CAPI int32_t U_EXPORT2
0264 ucasemap_utf8ToLower(const UCaseMap *csm,
0265                      char *dest, int32_t destCapacity,
0266                      const char *src, int32_t srcLength,
0267                      UErrorCode *pErrorCode);
0268 
0269 /**
0270  * Uppercase the characters in a UTF-8 string.
0271  * Casing is locale-dependent and context-sensitive.
0272  * The result may be longer or shorter than the original.
0273  * The source string and the destination buffer must not overlap.
0274  *
0275  * @param csm       UCaseMap service object.
0276  * @param dest      A buffer for the result string. The result will be NUL-terminated if
0277  *                  the buffer is large enough.
0278  *                  The contents is undefined in case of failure.
0279  * @param destCapacity The size of the buffer (number of bytes). If it is 0, then
0280  *                  dest may be NULL and the function will only return the length of the result
0281  *                  without writing any of the result string.
0282  * @param src       The original string.
0283  * @param srcLength The length of the original string. If -1, then src must be NUL-terminated.
0284  * @param pErrorCode Must be a valid pointer to an error code value,
0285  *                  which must not indicate a failure before the function call.
0286  * @return The length of the result string, if successful - or in case of a buffer overflow,
0287  *         in which case it will be greater than destCapacity.
0288  *
0289  * @see u_strToUpper
0290  * @stable ICU 3.4
0291  */
0292 U_CAPI int32_t U_EXPORT2
0293 ucasemap_utf8ToUpper(const UCaseMap *csm,
0294                      char *dest, int32_t destCapacity,
0295                      const char *src, int32_t srcLength,
0296                      UErrorCode *pErrorCode);
0297 
0298 #if !UCONFIG_NO_BREAK_ITERATION
0299 
0300 /**
0301  * Titlecase a UTF-8 string.
0302  * Casing is locale-dependent and context-sensitive.
0303  * Titlecasing uses a break iterator to find the first characters of words
0304  * that are to be titlecased. It titlecases those characters and lowercases
0305  * all others. (This can be modified with ucasemap_setOptions().)
0306  *
0307  * Note: This function takes a non-const UCaseMap pointer because it will
0308  * open a default break iterator if no break iterator was set yet,
0309  * and effectively call ucasemap_setBreakIterator();
0310  * also because the break iterator is stateful and will be modified during
0311  * the iteration.
0312  *
0313  * The titlecase break iterator can be provided to customize for arbitrary
0314  * styles, using rules and dictionaries beyond the standard iterators.
0315  * The standard titlecase iterator for the root locale implements the
0316  * algorithm of Unicode TR 21.
0317  *
0318  * This function uses only the setUText(), first(), next() and close() methods of the
0319  * provided break iterator.
0320  *
0321  * The result may be longer or shorter than the original.
0322  * The source string and the destination buffer must not overlap.
0323  *
0324  * @param csm       UCaseMap service object. This pointer is non-const!
0325  *                  See the note above for details.
0326  * @param dest      A buffer for the result string. The result will be NUL-terminated if
0327  *                  the buffer is large enough.
0328  *                  The contents is undefined in case of failure.
0329  * @param destCapacity The size of the buffer (number of bytes). If it is 0, then
0330  *                  dest may be NULL and the function will only return the length of the result
0331  *                  without writing any of the result string.
0332  * @param src       The original string.
0333  * @param srcLength The length of the original string. If -1, then src must be NUL-terminated.
0334  * @param pErrorCode Must be a valid pointer to an error code value,
0335  *                  which must not indicate a failure before the function call.
0336  * @return The length of the result string, if successful - or in case of a buffer overflow,
0337  *         in which case it will be greater than destCapacity.
0338  *
0339  * @see u_strToTitle
0340  * @see U_TITLECASE_NO_LOWERCASE
0341  * @see U_TITLECASE_NO_BREAK_ADJUSTMENT
0342  * @stable ICU 3.8
0343  */
0344 U_CAPI int32_t U_EXPORT2
0345 ucasemap_utf8ToTitle(UCaseMap *csm,
0346                     char *dest, int32_t destCapacity,
0347                     const char *src, int32_t srcLength,
0348                     UErrorCode *pErrorCode);
0349 
0350 #endif
0351 
0352 /**
0353  * Case-folds the characters in a UTF-8 string.
0354  *
0355  * Case-folding is locale-independent and not context-sensitive,
0356  * but there is an option for whether to include or exclude mappings for dotted I
0357  * and dotless i that are marked with 'T' in CaseFolding.txt.
0358  *
0359  * The result may be longer or shorter than the original.
0360  * The source string and the destination buffer must not overlap.
0361  *
0362  * @param csm       UCaseMap service object.
0363  * @param dest      A buffer for the result string. The result will be NUL-terminated if
0364  *                  the buffer is large enough.
0365  *                  The contents is undefined in case of failure.
0366  * @param destCapacity The size of the buffer (number of bytes). If it is 0, then
0367  *                  dest may be NULL and the function will only return the length of the result
0368  *                  without writing any of the result string.
0369  * @param src       The original string.
0370  * @param srcLength The length of the original string. If -1, then src must be NUL-terminated.
0371  * @param pErrorCode Must be a valid pointer to an error code value,
0372  *                  which must not indicate a failure before the function call.
0373  * @return The length of the result string, if successful - or in case of a buffer overflow,
0374  *         in which case it will be greater than destCapacity.
0375  *
0376  * @see u_strFoldCase
0377  * @see ucasemap_setOptions
0378  * @see U_FOLD_CASE_DEFAULT
0379  * @see U_FOLD_CASE_EXCLUDE_SPECIAL_I
0380  * @stable ICU 3.8
0381  */
0382 U_CAPI int32_t U_EXPORT2
0383 ucasemap_utf8FoldCase(const UCaseMap *csm,
0384                       char *dest, int32_t destCapacity,
0385                       const char *src, int32_t srcLength,
0386                       UErrorCode *pErrorCode);
0387 
0388 #endif