2 *******************************************************************************
4 * Copyright (C) 2004, International Business Machines
5 * Corporation and others. All Rights Reserved.
7 *******************************************************************************
10 * tab size: 8 (not used)
13 * created on: 2004aug30
14 * created by: Markus W. Scherer
16 * Low-level Unicode character/string case mapping code.
22 #include "unicode/utypes.h"
23 #include "unicode/uset.h"
29 /* library API -------------------------------------------------------------- */
32 typedef struct UCaseProps UCaseProps
;
34 U_CAPI UCaseProps
* U_EXPORT2
35 ucase_open(UErrorCode
*pErrorCode
);
37 U_CAPI UCaseProps
* U_EXPORT2
38 ucase_openBinary(const uint8_t *bin
, int32_t length
, UErrorCode
*pErrorCode
);
41 ucase_close(UCaseProps
*csp
);
44 U_CAPI UCaseProps
* U_EXPORT2
45 ucase_getSingleton(UErrorCode
*pErrorCode
);
48 U_CAPI
int32_t U_EXPORT2
49 ucase_swap(const UDataSwapper
*ds
,
50 const void *inData
, int32_t length
, void *outData
,
51 UErrorCode
*pErrorCode
);
54 ucase_addPropertyStarts(const UCaseProps
*csp
, USetAdder
*sa
, UErrorCode
*pErrorCode
);
57 * Bit mask for getting just the options from a string compare options word
58 * that are relevant for case-insensitive string comparison.
59 * See uchar.h. Also include _STRNCMP_STYLE and U_COMPARE_CODE_POINT_ORDER.
62 #define _STRCASECMP_OPTIONS_MASK 0xffff
65 * Bit mask for getting just the options from a string compare options word
66 * that are relevant for case folding (of a single string or code point).
70 #define _FOLD_CASE_OPTIONS_MASK 0xff
72 /* single-code point functions */
74 U_CAPI UChar32 U_EXPORT2
75 ucase_tolower(const UCaseProps
*csp
, UChar32 c
);
77 U_CAPI UChar32 U_EXPORT2
78 ucase_toupper(const UCaseProps
*csp
, UChar32 c
);
80 U_CAPI UChar32 U_EXPORT2
81 ucase_totitle(const UCaseProps
*csp
, UChar32 c
);
83 U_CAPI UChar32 U_EXPORT2
84 ucase_fold(UCaseProps
*csp
, UChar32 c
, uint32_t options
);
86 /** @return UCASE_NONE, UCASE_LOWER, UCASE_UPPER, UCASE_TITLE */
87 U_CAPI
int32_t U_EXPORT2
88 ucase_getType(const UCaseProps
*csp
, UChar32 c
);
90 /** @return same as ucase_getType(), or <0 if c is case-ignorable */
91 U_CAPI
int32_t U_EXPORT2
92 ucase_getTypeOrIgnorable(const UCaseProps
*csp
, UChar32 c
);
94 U_CAPI UBool U_EXPORT2
95 ucase_isSoftDotted(const UCaseProps
*csp
, UChar32 c
);
97 U_CAPI UBool U_EXPORT2
98 ucase_isCaseSensitive(const UCaseProps
*csp
, UChar32 c
);
100 /* string case mapping functions */
103 * Iterator function for string case mappings, which need to look at the
104 * context (surrounding text) of a given character for conditional mappings.
106 * The iterator only needs to go backward or forward away from the
107 * character in question. It does not use any indexes on this interface.
108 * It does not support random access or an arbitrary change of
109 * iteration direction.
111 * The direction parameter either starts
113 * @param context A pointer to the iterator's working data.
114 * @param dir If <0 then start iterating backward from the character;
115 * if >0 then start iterating forward from the character;
116 * if 0 then continue iterating in the current direction.
117 * @return Next code point, or <0 when the iteration is done.
119 typedef UChar32 U_CALLCONV
120 UCaseContextIterator(void *context
, int8_t dir
);
123 * Sample struct which may be used by some implementations of
124 * UCaseContextIterator.
126 struct UCaseContext
{
128 int32_t start
, index
, limit
;
129 int32_t cpStart
, cpLimit
;
133 typedef struct UCaseContext UCaseContext
;
137 * For string case mappings, a single character (a code point) is mapped
138 * either to itself (in which case in-place mapping functions do nothing),
139 * or to another single code point, or to a string.
140 * Aside from the string contents, these are indicated with a single int32_t
143 * Mapping to self: Negative values (~self instead of -self to support U+0000)
145 * Mapping to another code point: Positive values >UCASE_MAX_STRING_LENGTH
147 * Mapping to a string: The string length (0..UCASE_MAX_STRING_LENGTH) is
148 * returned. Note that the string result may indeed have zero length.
150 UCASE_MAX_STRING_LENGTH
=0x1f
154 * Get the full lowercase mapping for c.
156 * @param csp Case mapping properties.
157 * @param c Character to be mapped.
158 * @param iter Character iterator, used for context-sensitive mappings.
159 * See UCaseContextIterator for details.
160 * If iter==NULL then a context-independent result is returned.
161 * @param context Pointer to be passed into iter.
162 * @param pString If the mapping result is a string, then the pointer is
163 * written to *pString.
164 * @param locale Locale ID for locale-dependent mappings.
165 * @param locCache Initialize to 0; may be used to cache the result of parsing
166 * the locale ID for subsequent calls.
168 * @return Output code point or string length, see UCASE_MAX_STRING_LENGTH.
170 * @see UCaseContextIterator
171 * @see UCASE_MAX_STRING_LENGTH
174 U_CAPI
int32_t U_EXPORT2
175 ucase_toFullLower(const UCaseProps
*csp
, UChar32 c
,
176 UCaseContextIterator
*iter
, void *context
,
177 const UChar
**pString
,
178 const char *locale
, int32_t *locCache
);
180 U_CAPI
int32_t U_EXPORT2
181 ucase_toFullUpper(const UCaseProps
*csp
, UChar32 c
,
182 UCaseContextIterator
*iter
, void *context
,
183 const UChar
**pString
,
184 const char *locale
, int32_t *locCache
);
186 U_CAPI
int32_t U_EXPORT2
187 ucase_toFullTitle(const UCaseProps
*csp
, UChar32 c
,
188 UCaseContextIterator
*iter
, void *context
,
189 const UChar
**pString
,
190 const char *locale
, int32_t *locCache
);
192 U_CAPI
int32_t U_EXPORT2
193 ucase_toFullFolding(const UCaseProps
*csp
, UChar32 c
,
194 const UChar
**pString
,
197 /* file definitions --------------------------------------------------------- */
199 #define UCASE_DATA_NAME "ucase"
200 #define UCASE_DATA_TYPE "icu"
203 #define UCASE_FMT_0 0x63
204 #define UCASE_FMT_1 0x41
205 #define UCASE_FMT_2 0x53
206 #define UCASE_FMT_3 0x45
208 /* indexes into indexes[] */
215 UCASE_IX_MAX_FULL_LENGTH
=15,
219 /* definitions for 16-bit case properties word ------------------------------ */
221 /* 2-bit constants for types of cased characters */
222 #define UCASE_TYPE_MASK 3
230 #define UCASE_SENSITIVE 4
231 #define UCASE_EXCEPTION 8
233 #define UCASE_DOT_MASK 0x30
235 UCASE_NO_DOT
=0, /* normal characters with cc=0 */
236 UCASE_SOFT_DOTTED
=0x10, /* soft-dotted characters with cc=0 */
237 UCASE_ABOVE
=0x20, /* "above" accents with cc=230 */
238 UCASE_OTHER_ACCENT
=0x30 /* other accent character (0<cc!=230) */
241 /* no exception: bits 15..6 are a 10-bit signed case mapping delta */
242 #define UCASE_DELTA_SHIFT 6
243 #define UCASE_DELTA_MASK 0xffc0
244 #define UCASE_MAX_DELTA 0x1ff
245 #define UCASE_MIN_DELTA (-UCASE_MAX_DELTA-1)
247 #define UCASE_GET_DELTA(props) ((int16_t)(props)>>UCASE_DELTA_SHIFT)
249 /* case-ignorable uses one of the delta bits, see gencase/store.c */
250 #define UCASE_CASE_IGNORABLE 0x40
252 /* exception: bits 15..4 are an unsigned 12-bit index into the exceptions array */
253 #define UCASE_EXC_SHIFT 4
254 #define UCASE_EXC_MASK 0xfff0
255 #define UCASE_MAX_EXCEPTIONS 0x1000
257 /* definitions for 16-bit main exceptions word ------------------------------ */
259 /* first 8 bits indicate values in optional slots */
265 UCASE_EXC_4
, /* reserved */
266 UCASE_EXC_5
, /* reserved */
267 UCASE_EXC_6
, /* reserved */
268 UCASE_EXC_FULL_MAPPINGS
,
269 UCASE_EXC_ALL_SLOTS
/* one past the last slot */
272 /* each slot is 2 uint16_t instead of 1 */
273 #define UCASE_EXC_DOUBLE_SLOTS 0x100
275 /* reserved: exception bits 11..9 */
277 /* UCASE_EXC_DOT_MASK=UCASE_DOT_MASK<<UCASE_EXC_DOT_SHIFT */
278 #define UCASE_EXC_DOT_SHIFT 8
280 /* normally stored in the main word, but pushed out for larger exception indexes */
281 #define UCASE_EXC_DOT_MASK 0x3000
284 UCASE_EXC_SOFT_DOTTED
=0x1000,
285 UCASE_EXC_ABOVE
=0x2000, /* "above" accents with cc=230 */
286 UCASE_EXC_OTHER_ACCENT
=0x3000 /* other character (0<cc!=230) */
289 /* complex/conditional mappings */
290 #define UCASE_EXC_CONDITIONAL_SPECIAL 0x4000
291 #define UCASE_EXC_CONDITIONAL_FOLD 0x8000
293 /* definitions for lengths word for full case mappings */
294 #define UCASE_FULL_LOWER 0xf
295 #define UCASE_FULL_FOLDING 0xf0
296 #define UCASE_FULL_UPPER 0xf00
297 #define UCASE_FULL_TITLE 0xf000