2 *******************************************************************************
4 * Copyright (C) 2004-2008, 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
const UCaseProps
* U_EXPORT2
45 ucase_getSingleton(UErrorCode
*pErrorCode
);
47 #define UCASE_HARDCODE_DATA 1
49 #if !UCASE_HARDCODE_DATA
51 * Get a singleton dummy object, one that works with no real data.
52 * This can be used when the real data is not available.
53 * Using the dummy can reduce checks for available data after an initial failure.
55 U_CAPI
const UCaseProps
* U_EXPORT2
56 ucase_getDummy(UErrorCode
*pErrorCode
);
60 U_CAPI
int32_t U_EXPORT2
61 ucase_swap(const UDataSwapper
*ds
,
62 const void *inData
, int32_t length
, void *outData
,
63 UErrorCode
*pErrorCode
);
65 U_CFUNC
void U_EXPORT2
66 ucase_addPropertyStarts(const UCaseProps
*csp
, const USetAdder
*sa
, UErrorCode
*pErrorCode
);
69 * Requires non-NULL locale ID but otherwise does the equivalent of
70 * checking for language codes as if uloc_getLanguage() were called:
71 * Accepts both 2- and 3-letter codes and accepts case variants.
74 ucase_getCaseLocale(const char *locale
, int32_t *locCache
);
76 /* Casing locale types for ucase_getCaseLocale */
86 * Bit mask for getting just the options from a string compare options word
87 * that are relevant for case-insensitive string comparison.
88 * See uchar.h. Also include _STRNCMP_STYLE and U_COMPARE_CODE_POINT_ORDER.
91 #define _STRCASECMP_OPTIONS_MASK 0xffff
94 * Bit mask for getting just the options from a string compare options word
95 * that are relevant for case folding (of a single string or code point).
99 #define _FOLD_CASE_OPTIONS_MASK 0xff
101 /* single-code point functions */
103 U_CAPI UChar32 U_EXPORT2
104 ucase_tolower(const UCaseProps
*csp
, UChar32 c
);
106 U_CAPI UChar32 U_EXPORT2
107 ucase_toupper(const UCaseProps
*csp
, UChar32 c
);
109 U_CAPI UChar32 U_EXPORT2
110 ucase_totitle(const UCaseProps
*csp
, UChar32 c
);
112 U_CAPI UChar32 U_EXPORT2
113 ucase_fold(const UCaseProps
*csp
, UChar32 c
, uint32_t options
);
116 * Adds all simple case mappings and the full case folding for c to sa,
117 * and also adds special case closure mappings.
118 * c itself is not added.
119 * For example, the mappings
120 * - for s include long s
121 * - for sharp s include ss
122 * - for k include the Kelvin sign
124 U_CFUNC
void U_EXPORT2
125 ucase_addCaseClosure(const UCaseProps
*csp
, UChar32 c
, const USetAdder
*sa
);
128 * Maps the string to single code points and adds the associated case closure
130 * The string is mapped to code points if it is their full case folding string.
131 * In other words, this performs a reverse full case folding and then
132 * adds the case closure items of the resulting code points.
133 * If the string is found and its closure applied, then
134 * the string itself is added as well as part of its code points' closure.
135 * It must be length>=0.
137 * @return TRUE if the string was found
139 U_CFUNC UBool U_EXPORT2
140 ucase_addStringCaseClosure(const UCaseProps
*csp
, const UChar
*s
, int32_t length
, const USetAdder
*sa
);
142 /** @return UCASE_NONE, UCASE_LOWER, UCASE_UPPER, UCASE_TITLE */
143 U_CAPI
int32_t U_EXPORT2
144 ucase_getType(const UCaseProps
*csp
, UChar32 c
);
146 /** @return same as ucase_getType(), or <0 if c is case-ignorable */
147 U_CAPI
int32_t U_EXPORT2
148 ucase_getTypeOrIgnorable(const UCaseProps
*csp
, UChar32 c
);
150 U_CAPI UBool U_EXPORT2
151 ucase_isSoftDotted(const UCaseProps
*csp
, UChar32 c
);
153 U_CAPI UBool U_EXPORT2
154 ucase_isCaseSensitive(const UCaseProps
*csp
, UChar32 c
);
156 /* string case mapping functions */
159 * Iterator function for string case mappings, which need to look at the
160 * context (surrounding text) of a given character for conditional mappings.
162 * The iterator only needs to go backward or forward away from the
163 * character in question. It does not use any indexes on this interface.
164 * It does not support random access or an arbitrary change of
165 * iteration direction.
167 * The code point being case-mapped itself is never returned by
170 * @param context A pointer to the iterator's working data.
171 * @param dir If <0 then start iterating backward from the character;
172 * if >0 then start iterating forward from the character;
173 * if 0 then continue iterating in the current direction.
174 * @return Next code point, or <0 when the iteration is done.
176 typedef UChar32 U_CALLCONV
177 UCaseContextIterator(void *context
, int8_t dir
);
180 * Sample struct which may be used by some implementations of
181 * UCaseContextIterator.
183 struct UCaseContext
{
185 int32_t start
, index
, limit
;
186 int32_t cpStart
, cpLimit
;
190 typedef struct UCaseContext UCaseContext
;
194 * For string case mappings, a single character (a code point) is mapped
195 * either to itself (in which case in-place mapping functions do nothing),
196 * or to another single code point, or to a string.
197 * Aside from the string contents, these are indicated with a single int32_t
200 * Mapping to self: Negative values (~self instead of -self to support U+0000)
202 * Mapping to another code point: Positive values >UCASE_MAX_STRING_LENGTH
204 * Mapping to a string: The string length (0..UCASE_MAX_STRING_LENGTH) is
205 * returned. Note that the string result may indeed have zero length.
207 UCASE_MAX_STRING_LENGTH
=0x1f
211 * Get the full lowercase mapping for c.
213 * @param csp Case mapping properties.
214 * @param c Character to be mapped.
215 * @param iter Character iterator, used for context-sensitive mappings.
216 * See UCaseContextIterator for details.
217 * If iter==NULL then a context-independent result is returned.
218 * @param context Pointer to be passed into iter.
219 * @param pString If the mapping result is a string, then the pointer is
220 * written to *pString.
221 * @param locale Locale ID for locale-dependent mappings.
222 * @param locCache Initialize to 0; may be used to cache the result of parsing
223 * the locale ID for subsequent calls.
225 * @return Output code point or string length, see UCASE_MAX_STRING_LENGTH.
227 * @see UCaseContextIterator
228 * @see UCASE_MAX_STRING_LENGTH
231 U_CAPI
int32_t U_EXPORT2
232 ucase_toFullLower(const UCaseProps
*csp
, UChar32 c
,
233 UCaseContextIterator
*iter
, void *context
,
234 const UChar
**pString
,
235 const char *locale
, int32_t *locCache
);
237 U_CAPI
int32_t U_EXPORT2
238 ucase_toFullUpper(const UCaseProps
*csp
, UChar32 c
,
239 UCaseContextIterator
*iter
, void *context
,
240 const UChar
**pString
,
241 const char *locale
, int32_t *locCache
);
243 U_CAPI
int32_t U_EXPORT2
244 ucase_toFullTitle(const UCaseProps
*csp
, UChar32 c
,
245 UCaseContextIterator
*iter
, void *context
,
246 const UChar
**pString
,
247 const char *locale
, int32_t *locCache
);
249 U_CAPI
int32_t U_EXPORT2
250 ucase_toFullFolding(const UCaseProps
*csp
, UChar32 c
,
251 const UChar
**pString
,
254 U_CFUNC
int32_t U_EXPORT2
255 ucase_hasBinaryProperty(UChar32 c
, UProperty which
);
263 typedef int32_t U_CALLCONV
264 UCaseMapFull(const UCaseProps
*csp
, UChar32 c
,
265 UCaseContextIterator
*iter
, void *context
,
266 const UChar
**pString
,
267 const char *locale
, int32_t *locCache
);
271 /* file definitions --------------------------------------------------------- */
273 #define UCASE_DATA_NAME "ucase"
274 #define UCASE_DATA_TYPE "icu"
277 #define UCASE_FMT_0 0x63
278 #define UCASE_FMT_1 0x41
279 #define UCASE_FMT_2 0x53
280 #define UCASE_FMT_3 0x45
282 /* indexes into indexes[] */
288 UCASE_IX_UNFOLD_LENGTH
,
290 UCASE_IX_MAX_FULL_LENGTH
=15,
294 /* definitions for 16-bit case properties word ------------------------------ */
296 /* 2-bit constants for types of cased characters */
297 #define UCASE_TYPE_MASK 3
305 #define UCASE_GET_TYPE(props) ((props)&UCASE_TYPE_MASK)
307 #define UCASE_SENSITIVE 4
308 #define UCASE_EXCEPTION 8
310 #define UCASE_DOT_MASK 0x30
312 UCASE_NO_DOT
=0, /* normal characters with cc=0 */
313 UCASE_SOFT_DOTTED
=0x10, /* soft-dotted characters with cc=0 */
314 UCASE_ABOVE
=0x20, /* "above" accents with cc=230 */
315 UCASE_OTHER_ACCENT
=0x30 /* other accent character (0<cc!=230) */
318 /* no exception: bits 15..6 are a 10-bit signed case mapping delta */
319 #define UCASE_DELTA_SHIFT 6
320 #define UCASE_DELTA_MASK 0xffc0
321 #define UCASE_MAX_DELTA 0x1ff
322 #define UCASE_MIN_DELTA (-UCASE_MAX_DELTA-1)
324 #define UCASE_GET_DELTA(props) ((int16_t)(props)>>UCASE_DELTA_SHIFT)
326 /* case-ignorable uses one of the delta bits, see gencase/store.c */
327 #define UCASE_CASE_IGNORABLE 0x40
329 /* exception: bits 15..4 are an unsigned 12-bit index into the exceptions array */
330 #define UCASE_EXC_SHIFT 4
331 #define UCASE_EXC_MASK 0xfff0
332 #define UCASE_MAX_EXCEPTIONS 0x1000
334 /* definitions for 16-bit main exceptions word ------------------------------ */
336 /* first 8 bits indicate values in optional slots */
342 UCASE_EXC_4
, /* reserved */
343 UCASE_EXC_5
, /* reserved */
345 UCASE_EXC_FULL_MAPPINGS
,
346 UCASE_EXC_ALL_SLOTS
/* one past the last slot */
349 /* each slot is 2 uint16_t instead of 1 */
350 #define UCASE_EXC_DOUBLE_SLOTS 0x100
352 /* reserved: exception bits 11..9 */
354 /* UCASE_EXC_DOT_MASK=UCASE_DOT_MASK<<UCASE_EXC_DOT_SHIFT */
355 #define UCASE_EXC_DOT_SHIFT 8
357 /* normally stored in the main word, but pushed out for larger exception indexes */
358 #define UCASE_EXC_DOT_MASK 0x3000
361 UCASE_EXC_SOFT_DOTTED
=0x1000,
362 UCASE_EXC_ABOVE
=0x2000, /* "above" accents with cc=230 */
363 UCASE_EXC_OTHER_ACCENT
=0x3000 /* other character (0<cc!=230) */
366 /* complex/conditional mappings */
367 #define UCASE_EXC_CONDITIONAL_SPECIAL 0x4000
368 #define UCASE_EXC_CONDITIONAL_FOLD 0x8000
370 /* definitions for lengths word for full case mappings */
371 #define UCASE_FULL_LOWER 0xf
372 #define UCASE_FULL_FOLDING 0xf0
373 #define UCASE_FULL_UPPER 0xf00
374 #define UCASE_FULL_TITLE 0xf000
376 /* maximum lengths */
377 #define UCASE_FULL_MAPPINGS_MAX_LENGTH (4*0xf)
378 #define UCASE_CLOSURE_MAX_LENGTH 0xf
380 /* constants for reverse case folding ("unfold") data */
383 UCASE_UNFOLD_ROW_WIDTH
,
384 UCASE_UNFOLD_STRING_WIDTH