2
*******************************************************************************
4
* Copyright (C) 2004-2010, 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 const UCaseProps * U_EXPORT2
35
ucase_getSingleton(void);
37
U_CAPI int32_t U_EXPORT2
38
ucase_swap(const UDataSwapper *ds,
39
const void *inData, int32_t length, void *outData,
40
UErrorCode *pErrorCode);
42
U_CFUNC void U_EXPORT2
43
ucase_addPropertyStarts(const UCaseProps *csp, const USetAdder *sa, UErrorCode *pErrorCode);
46
* Requires non-NULL locale ID but otherwise does the equivalent of
47
* checking for language codes as if uloc_getLanguage() were called:
48
* Accepts both 2- and 3-letter codes and accepts case variants.
51
ucase_getCaseLocale(const char *locale, int32_t *locCache);
53
/* Casing locale types for ucase_getCaseLocale */
63
* Bit mask for getting just the options from a string compare options word
64
* that are relevant for case-insensitive string comparison.
65
* See uchar.h. Also include _STRNCMP_STYLE and U_COMPARE_CODE_POINT_ORDER.
68
#define _STRCASECMP_OPTIONS_MASK 0xffff
71
* Bit mask for getting just the options from a string compare options word
72
* that are relevant for case folding (of a single string or code point).
76
#define _FOLD_CASE_OPTIONS_MASK 0xff
78
/* single-code point functions */
80
U_CAPI UChar32 U_EXPORT2
81
ucase_tolower(const UCaseProps *csp, UChar32 c);
83
U_CAPI UChar32 U_EXPORT2
84
ucase_toupper(const UCaseProps *csp, UChar32 c);
86
U_CAPI UChar32 U_EXPORT2
87
ucase_totitle(const UCaseProps *csp, UChar32 c);
89
U_CAPI UChar32 U_EXPORT2
90
ucase_fold(const UCaseProps *csp, UChar32 c, uint32_t options);
93
* Adds all simple case mappings and the full case folding for c to sa,
94
* and also adds special case closure mappings.
95
* c itself is not added.
96
* For example, the mappings
97
* - for s include long s
98
* - for sharp s include ss
99
* - for k include the Kelvin sign
101
U_CFUNC void U_EXPORT2
102
ucase_addCaseClosure(const UCaseProps *csp, UChar32 c, const USetAdder *sa);
105
* Maps the string to single code points and adds the associated case closure
107
* The string is mapped to code points if it is their full case folding string.
108
* In other words, this performs a reverse full case folding and then
109
* adds the case closure items of the resulting code points.
110
* If the string is found and its closure applied, then
111
* the string itself is added as well as part of its code points' closure.
112
* It must be length>=0.
114
* @return TRUE if the string was found
116
U_CFUNC UBool U_EXPORT2
117
ucase_addStringCaseClosure(const UCaseProps *csp, const UChar *s, int32_t length, const USetAdder *sa);
119
/** @return UCASE_NONE, UCASE_LOWER, UCASE_UPPER, UCASE_TITLE */
120
U_CAPI int32_t U_EXPORT2
121
ucase_getType(const UCaseProps *csp, UChar32 c);
123
/** @return same as ucase_getType(), or <0 if c is case-ignorable */
124
U_CAPI int32_t U_EXPORT2
125
ucase_getTypeOrIgnorable(const UCaseProps *csp, UChar32 c);
127
U_CAPI UBool U_EXPORT2
128
ucase_isSoftDotted(const UCaseProps *csp, UChar32 c);
130
U_CAPI UBool U_EXPORT2
131
ucase_isCaseSensitive(const UCaseProps *csp, UChar32 c);
133
/* string case mapping functions */
136
* Iterator function for string case mappings, which need to look at the
137
* context (surrounding text) of a given character for conditional mappings.
139
* The iterator only needs to go backward or forward away from the
140
* character in question. It does not use any indexes on this interface.
141
* It does not support random access or an arbitrary change of
142
* iteration direction.
144
* The code point being case-mapped itself is never returned by
147
* @param context A pointer to the iterator's working data.
148
* @param dir If <0 then start iterating backward from the character;
149
* if >0 then start iterating forward from the character;
150
* if 0 then continue iterating in the current direction.
151
* @return Next code point, or <0 when the iteration is done.
153
typedef UChar32 U_CALLCONV
154
UCaseContextIterator(void *context, int8_t dir);
157
* Sample struct which may be used by some implementations of
158
* UCaseContextIterator.
160
struct UCaseContext {
162
int32_t start, index, limit;
163
int32_t cpStart, cpLimit;
167
typedef struct UCaseContext UCaseContext;
171
* For string case mappings, a single character (a code point) is mapped
172
* either to itself (in which case in-place mapping functions do nothing),
173
* or to another single code point, or to a string.
174
* Aside from the string contents, these are indicated with a single int32_t
177
* Mapping to self: Negative values (~self instead of -self to support U+0000)
179
* Mapping to another code point: Positive values >UCASE_MAX_STRING_LENGTH
181
* Mapping to a string: The string length (0..UCASE_MAX_STRING_LENGTH) is
182
* returned. Note that the string result may indeed have zero length.
184
UCASE_MAX_STRING_LENGTH=0x1f
188
* Get the full lowercase mapping for c.
190
* @param csp Case mapping properties.
191
* @param c Character to be mapped.
192
* @param iter Character iterator, used for context-sensitive mappings.
193
* See UCaseContextIterator for details.
194
* If iter==NULL then a context-independent result is returned.
195
* @param context Pointer to be passed into iter.
196
* @param pString If the mapping result is a string, then the pointer is
197
* written to *pString.
198
* @param locale Locale ID for locale-dependent mappings.
199
* @param locCache Initialize to 0; may be used to cache the result of parsing
200
* the locale ID for subsequent calls.
202
* @return Output code point or string length, see UCASE_MAX_STRING_LENGTH.
204
* @see UCaseContextIterator
205
* @see UCASE_MAX_STRING_LENGTH
208
U_CAPI int32_t U_EXPORT2
209
ucase_toFullLower(const UCaseProps *csp, UChar32 c,
210
UCaseContextIterator *iter, void *context,
211
const UChar **pString,
212
const char *locale, int32_t *locCache);
214
U_CAPI int32_t U_EXPORT2
215
ucase_toFullUpper(const UCaseProps *csp, UChar32 c,
216
UCaseContextIterator *iter, void *context,
217
const UChar **pString,
218
const char *locale, int32_t *locCache);
220
U_CAPI int32_t U_EXPORT2
221
ucase_toFullTitle(const UCaseProps *csp, UChar32 c,
222
UCaseContextIterator *iter, void *context,
223
const UChar **pString,
224
const char *locale, int32_t *locCache);
226
U_CAPI int32_t U_EXPORT2
227
ucase_toFullFolding(const UCaseProps *csp, UChar32 c,
228
const UChar **pString,
231
U_CFUNC int32_t U_EXPORT2
232
ucase_hasBinaryProperty(UChar32 c, UProperty which);
240
typedef int32_t U_CALLCONV
241
UCaseMapFull(const UCaseProps *csp, UChar32 c,
242
UCaseContextIterator *iter, void *context,
243
const UChar **pString,
244
const char *locale, int32_t *locCache);
248
/* file definitions --------------------------------------------------------- */
250
#define UCASE_DATA_NAME "ucase"
251
#define UCASE_DATA_TYPE "icu"
254
#define UCASE_FMT_0 0x63
255
#define UCASE_FMT_1 0x41
256
#define UCASE_FMT_2 0x53
257
#define UCASE_FMT_3 0x45
259
/* indexes into indexes[] */
265
UCASE_IX_UNFOLD_LENGTH,
267
UCASE_IX_MAX_FULL_LENGTH=15,
271
/* definitions for 16-bit case properties word ------------------------------ */
273
/* 2-bit constants for types of cased characters */
274
#define UCASE_TYPE_MASK 3
282
#define UCASE_GET_TYPE(props) ((props)&UCASE_TYPE_MASK)
284
#define UCASE_SENSITIVE 4
285
#define UCASE_EXCEPTION 8
287
#define UCASE_DOT_MASK 0x30
289
UCASE_NO_DOT=0, /* normal characters with cc=0 */
290
UCASE_SOFT_DOTTED=0x10, /* soft-dotted characters with cc=0 */
291
UCASE_ABOVE=0x20, /* "above" accents with cc=230 */
292
UCASE_OTHER_ACCENT=0x30 /* other accent character (0<cc!=230) */
295
/* no exception: bits 15..6 are a 10-bit signed case mapping delta */
296
#define UCASE_DELTA_SHIFT 6
297
#define UCASE_DELTA_MASK 0xffc0
298
#define UCASE_MAX_DELTA 0x1ff
299
#define UCASE_MIN_DELTA (-UCASE_MAX_DELTA-1)
301
#define UCASE_GET_DELTA(props) ((int16_t)(props)>>UCASE_DELTA_SHIFT)
303
/* case-ignorable uses one of the delta bits, see gencase/store.c */
304
#define UCASE_CASE_IGNORABLE 0x40
306
/* exception: bits 15..4 are an unsigned 12-bit index into the exceptions array */
307
#define UCASE_EXC_SHIFT 4
308
#define UCASE_EXC_MASK 0xfff0
309
#define UCASE_MAX_EXCEPTIONS 0x1000
311
/* definitions for 16-bit main exceptions word ------------------------------ */
313
/* first 8 bits indicate values in optional slots */
319
UCASE_EXC_4, /* reserved */
320
UCASE_EXC_5, /* reserved */
322
UCASE_EXC_FULL_MAPPINGS,
323
UCASE_EXC_ALL_SLOTS /* one past the last slot */
326
/* each slot is 2 uint16_t instead of 1 */
327
#define UCASE_EXC_DOUBLE_SLOTS 0x100
329
/* reserved: exception bits 10..9 */
331
#define UCASE_EXC_CASE_IGNORABLE 0x800
333
/* UCASE_EXC_DOT_MASK=UCASE_DOT_MASK<<UCASE_EXC_DOT_SHIFT */
334
#define UCASE_EXC_DOT_SHIFT 8
336
/* normally stored in the main word, but pushed out for larger exception indexes */
337
#define UCASE_EXC_DOT_MASK 0x3000
340
UCASE_EXC_SOFT_DOTTED=0x1000,
341
UCASE_EXC_ABOVE=0x2000, /* "above" accents with cc=230 */
342
UCASE_EXC_OTHER_ACCENT=0x3000 /* other character (0<cc!=230) */
345
/* complex/conditional mappings */
346
#define UCASE_EXC_CONDITIONAL_SPECIAL 0x4000
347
#define UCASE_EXC_CONDITIONAL_FOLD 0x8000
349
/* definitions for lengths word for full case mappings */
350
#define UCASE_FULL_LOWER 0xf
351
#define UCASE_FULL_FOLDING 0xf0
352
#define UCASE_FULL_UPPER 0xf00
353
#define UCASE_FULL_TITLE 0xf000
355
/* maximum lengths */
356
#define UCASE_FULL_MAPPINGS_MAX_LENGTH (4*0xf)
357
#define UCASE_CLOSURE_MAX_LENGTH 0xf
359
/* constants for reverse case folding ("unfold") data */
362
UCASE_UNFOLD_ROW_WIDTH,
363
UCASE_UNFOLD_STRING_WIDTH