// © 2016 and later: Unicode, Inc. and others. // License & terms of use: http://www.unicode.org/copyright.html /* ******************************************************************************* * * Copyright (C) 2004-2012, International Business Machines * Corporation and others. All Rights Reserved. * ******************************************************************************* * file name: ucase.h * encoding: UTF-8 * tab size: 8 (not used) * indentation:4 * * created on: 2004aug30 * created by: Markus W. Scherer * * Low-level Unicode character/string case mapping code. */ #ifndef __UCASE_H__ #define __UCASE_H__ #include "unicode/utypes.h" #include "unicode/uset.h" #include "putilimp.h" #include "uset_imp.h" #include "udataswp.h" #include "utrie2.h" #ifdef __cplusplus U_NAMESPACE_BEGIN class UnicodeString; U_NAMESPACE_END #endif /* library API -------------------------------------------------------------- */ U_CFUNC void U_EXPORT2 ucase_addPropertyStarts(const USetAdder *sa, UErrorCode *pErrorCode); /** * Requires non-NULL locale ID but otherwise does the equivalent of * checking for language codes as if uloc_getLanguage() were called: * Accepts both 2- and 3-letter codes and accepts case variants. */ U_CFUNC int32_t ucase_getCaseLocale(const char *locale); /* Casing locale types for ucase_getCaseLocale */ enum { … }; /** * Bit mask for getting just the options from a string compare options word * that are relevant for case-insensitive string comparison. * See stringoptions.h. Also include _STRNCMP_STYLE and U_COMPARE_CODE_POINT_ORDER. * @internal */ #define _STRCASECMP_OPTIONS_MASK … /** * Bit mask for getting just the options from a string compare options word * that are relevant for case folding (of a single string or code point). * * Currently only bit 0 for U_FOLD_CASE_EXCLUDE_SPECIAL_I. * It is conceivable that at some point we might use one more bit for using uppercase sharp s. * It is conceivable that at some point we might want the option to use only simple case foldings * when operating on strings. * * See stringoptions.h. * @internal */ #define _FOLD_CASE_OPTIONS_MASK … /* single-code point functions */ U_CAPI UChar32 U_EXPORT2 ucase_tolower(UChar32 c); U_CAPI UChar32 U_EXPORT2 ucase_toupper(UChar32 c); U_CAPI UChar32 U_EXPORT2 ucase_totitle(UChar32 c); U_CAPI UChar32 U_EXPORT2 ucase_fold(UChar32 c, uint32_t options); /** * Adds all simple case mappings and the full case folding for c to sa, * and also adds special case closure mappings. * c itself is not added. * For example, the mappings * - for s include long s * - for sharp s include ss * - for k include the Kelvin sign */ U_CFUNC void U_EXPORT2 ucase_addCaseClosure(UChar32 c, const USetAdder *sa); /** Case closure with only scf=Simple_Case_Folding. */ U_CFUNC void U_EXPORT2 ucase_addSimpleCaseClosure(UChar32 c, const USetAdder *sa); /** * Maps the string to single code points and adds the associated case closure * mappings. * The string is mapped to code points if it is their full case folding string. * In other words, this performs a reverse full case folding and then * adds the case closure items of the resulting code points. * If the string is found and its closure applied, then * the string itself is added as well as part of its code points' closure. * It must be length>=0. * * @return true if the string was found */ U_CFUNC UBool U_EXPORT2 ucase_addStringCaseClosure(const UChar *s, int32_t length, const USetAdder *sa); #ifdef __cplusplus U_NAMESPACE_BEGIN /** * Iterator over characters with more than one code point in the full default Case_Folding. */ class U_COMMON_API FullCaseFoldingIterator { … }; /** * Fast case mapping data for ASCII/Latin. * Linear arrays of delta bytes: 0=no mapping; EXC=exception. * Deltas must not cross the ASCII boundary, or else they cannot be easily used * in simple UTF-8 code. */ namespace LatinCase { /** Case mapping/folding data for code points up to U+017F. */ constexpr char16_t LIMIT = …; /** U+017F case-folds and uppercases crossing the ASCII boundary. */ constexpr char16_t LONG_S = …; /** Exception: Complex mapping, or too-large delta. */ constexpr int8_t EXC = …; /** Deltas for lowercasing for most locales, and default case folding. */ extern const int8_t TO_LOWER_NORMAL[LIMIT]; /** Deltas for lowercasing for tr/az/lt, and Turkic case folding. */ extern const int8_t TO_LOWER_TR_LT[LIMIT]; /** Deltas for uppercasing for most locales. */ extern const int8_t TO_UPPER_NORMAL[LIMIT]; /** Deltas for uppercasing for tr/az. */ extern const int8_t TO_UPPER_TR[LIMIT]; } // namespace LatinCase U_NAMESPACE_END #endif /** @return UCASE_NONE, UCASE_LOWER, UCASE_UPPER, UCASE_TITLE */ U_CAPI int32_t U_EXPORT2 ucase_getType(UChar32 c); /** @return like ucase_getType() but also sets UCASE_IGNORABLE if c is case-ignorable */ U_CAPI int32_t U_EXPORT2 ucase_getTypeOrIgnorable(UChar32 c); U_CAPI UBool U_EXPORT2 ucase_isSoftDotted(UChar32 c); U_CAPI UBool U_EXPORT2 ucase_isCaseSensitive(UChar32 c); /* string case mapping functions */ U_CDECL_BEGIN /** * Iterator function for string case mappings, which need to look at the * context (surrounding text) of a given character for conditional mappings. * * The iterator only needs to go backward or forward away from the * character in question. It does not use any indexes on this interface. * It does not support random access or an arbitrary change of * iteration direction. * * The code point being case-mapped itself is never returned by * this iterator. * * @param context A pointer to the iterator's working data. * @param dir If <0 then start iterating backward from the character; * if >0 then start iterating forward from the character; * if 0 then continue iterating in the current direction. * @return Next code point, or <0 when the iteration is done. */ UCaseContextIterator; /** * Sample struct which may be used by some implementations of * UCaseContextIterator. */ struct UCaseContext { … }; UCaseContext; U_CDECL_END #define UCASECONTEXT_INITIALIZER … enum { … }; /** * Get the full lowercase mapping for c. * * @param csp Case mapping properties. * @param c Character to be mapped. * @param iter Character iterator, used for context-sensitive mappings. * See UCaseContextIterator for details. * If iter==NULL then a context-independent result is returned. * @param context Pointer to be passed into iter. * @param pString If the mapping result is a string, then the pointer is * written to *pString. * @param caseLocale Case locale value from ucase_getCaseLocale(). * @return Output code point or string length, see UCASE_MAX_STRING_LENGTH. * * @see UCaseContextIterator * @see UCASE_MAX_STRING_LENGTH * @internal */ U_CAPI int32_t U_EXPORT2 ucase_toFullLower(UChar32 c, UCaseContextIterator *iter, void *context, const UChar **pString, int32_t caseLocale); U_CAPI int32_t U_EXPORT2 ucase_toFullUpper(UChar32 c, UCaseContextIterator *iter, void *context, const UChar **pString, int32_t caseLocale); U_CAPI int32_t U_EXPORT2 ucase_toFullTitle(UChar32 c, UCaseContextIterator *iter, void *context, const UChar **pString, int32_t caseLocale); U_CAPI int32_t U_EXPORT2 ucase_toFullFolding(UChar32 c, const UChar **pString, uint32_t options); U_CFUNC int32_t U_EXPORT2 ucase_hasBinaryProperty(UChar32 c, UProperty which); U_CDECL_BEGIN /** * @internal */ UCaseMapFull; U_CDECL_END /* for icuexportdata -------------------------------------------------------- */ struct UCaseProps { … }; U_CAPI const struct UCaseProps * U_EXPORT2 ucase_getSingleton(int32_t *pExceptionsLength, int32_t *pUnfoldLength); /* file definitions --------------------------------------------------------- */ #define UCASE_DATA_NAME … #define UCASE_DATA_TYPE … /* format "cAsE" */ #define UCASE_FMT_0 … #define UCASE_FMT_1 … #define UCASE_FMT_2 … #define UCASE_FMT_3 … /* indexes into indexes[] */ enum { … }; /* definitions for 16-bit case properties word ------------------------------ */ U_CFUNC const UTrie2 * U_EXPORT2 ucase_getTrie(void); /* 2-bit constants for types of cased characters */ #define UCASE_TYPE_MASK … enum { … }; #define UCASE_GET_TYPE(props) … #define UCASE_GET_TYPE_AND_IGNORABLE(props) … #define UCASE_IS_UPPER_OR_TITLE(props) … #define UCASE_IGNORABLE … #define UCASE_EXCEPTION … #define UCASE_SENSITIVE … #define UCASE_HAS_EXCEPTION(props) … #define UCASE_DOT_MASK … enum { … }; /* no exception: bits 15..7 are a 9-bit signed case mapping delta */ #define UCASE_DELTA_SHIFT … #define UCASE_DELTA_MASK … #define UCASE_MAX_DELTA … #define UCASE_MIN_DELTA … #if U_SIGNED_RIGHT_SHIFT_IS_ARITHMETIC #define UCASE_GET_DELTA(props) … #else #define UCASE_GET_DELTA … #endif /* exception: bits 15..4 are an unsigned 12-bit index into the exceptions array */ #define UCASE_EXC_SHIFT … #define UCASE_EXC_MASK … #define UCASE_MAX_EXCEPTIONS … /* definitions for 16-bit main exceptions word ------------------------------ */ /* first 8 bits indicate values in optional slots */ enum { … }; /* each slot is 2 uint16_t instead of 1 */ #define UCASE_EXC_DOUBLE_SLOTS … enum { … }; /* UCASE_EXC_DOT_MASK=UCASE_DOT_MASK<<UCASE_EXC_DOT_SHIFT */ #define UCASE_EXC_DOT_SHIFT … /* normally stored in the main word, but pushed out for larger exception indexes */ #define UCASE_EXC_DOT_MASK … enum { … }; /* complex/conditional mappings */ #define UCASE_EXC_CONDITIONAL_SPECIAL … #define UCASE_EXC_CONDITIONAL_FOLD … /* definitions for lengths word for full case mappings */ #define UCASE_FULL_LOWER … #define UCASE_FULL_FOLDING … #define UCASE_FULL_UPPER … #define UCASE_FULL_TITLE … /* maximum lengths */ #define UCASE_FULL_MAPPINGS_MAX_LENGTH … #define UCASE_CLOSURE_MAX_LENGTH … /* constants for reverse case folding ("unfold") data */ enum { … }; #endif