]> git.saurik.com Git - apple/icu.git/blame - icuSources/common/ucase.h
ICU-8.11.2.tar.gz
[apple/icu.git] / icuSources / common / ucase.h
CommitLineData
374ca955
A
1/*
2*******************************************************************************
3*
73c04bcf 4* Copyright (C) 2004-2006, International Business Machines
374ca955
A
5* Corporation and others. All Rights Reserved.
6*
7*******************************************************************************
8* file name: ucase.h
9* encoding: US-ASCII
10* tab size: 8 (not used)
11* indentation:4
12*
13* created on: 2004aug30
14* created by: Markus W. Scherer
15*
16* Low-level Unicode character/string case mapping code.
17*/
18
19#ifndef __UCASE_H__
20#define __UCASE_H__
21
22#include "unicode/utypes.h"
23#include "unicode/uset.h"
24#include "uset_imp.h"
25#include "udataswp.h"
26
27U_CDECL_BEGIN
28
29/* library API -------------------------------------------------------------- */
30
31struct UCaseProps;
32typedef struct UCaseProps UCaseProps;
33
34U_CAPI UCaseProps * U_EXPORT2
35ucase_open(UErrorCode *pErrorCode);
36
37U_CAPI UCaseProps * U_EXPORT2
38ucase_openBinary(const uint8_t *bin, int32_t length, UErrorCode *pErrorCode);
39
40U_CAPI void U_EXPORT2
41ucase_close(UCaseProps *csp);
42
43
73c04bcf 44U_CAPI const UCaseProps * U_EXPORT2
374ca955
A
45ucase_getSingleton(UErrorCode *pErrorCode);
46
73c04bcf
A
47/**
48 * Get a singleton dummy object, one that works with no real data.
49 * This can be used when the real data is not available.
50 * Using the dummy can reduce checks for available data after an initial failure.
51 */
52U_CAPI const UCaseProps * U_EXPORT2
53ucase_getDummy(UErrorCode *pErrorCode);
54
374ca955
A
55
56U_CAPI int32_t U_EXPORT2
57ucase_swap(const UDataSwapper *ds,
58 const void *inData, int32_t length, void *outData,
59 UErrorCode *pErrorCode);
60
61U_CAPI void U_EXPORT2
73c04bcf
A
62ucase_addPropertyStarts(const UCaseProps *csp, const USetAdder *sa, UErrorCode *pErrorCode);
63
64/**
65 * Requires non-NULL locale ID but otherwise does the equivalent of
66 * checking for language codes as if uloc_getLanguage() were called:
67 * Accepts both 2- and 3-letter codes and accepts case variants.
68 */
69U_CFUNC int32_t
70ucase_getCaseLocale(const char *locale, int32_t *locCache);
374ca955
A
71
72/**
73 * Bit mask for getting just the options from a string compare options word
74 * that are relevant for case-insensitive string comparison.
75 * See uchar.h. Also include _STRNCMP_STYLE and U_COMPARE_CODE_POINT_ORDER.
76 * @internal
77 */
78#define _STRCASECMP_OPTIONS_MASK 0xffff
79
80/**
81 * Bit mask for getting just the options from a string compare options word
82 * that are relevant for case folding (of a single string or code point).
83 * See uchar.h.
84 * @internal
85 */
86#define _FOLD_CASE_OPTIONS_MASK 0xff
87
88/* single-code point functions */
89
90U_CAPI UChar32 U_EXPORT2
91ucase_tolower(const UCaseProps *csp, UChar32 c);
92
93U_CAPI UChar32 U_EXPORT2
94ucase_toupper(const UCaseProps *csp, UChar32 c);
95
96U_CAPI UChar32 U_EXPORT2
97ucase_totitle(const UCaseProps *csp, UChar32 c);
98
99U_CAPI UChar32 U_EXPORT2
73c04bcf
A
100ucase_fold(const UCaseProps *csp, UChar32 c, uint32_t options);
101
102/**
103 * Adds all simple case mappings and the full case folding for c to sa,
104 * and also adds special case closure mappings.
105 * c itself is not added.
106 * For example, the mappings
107 * - for s include long s
108 * - for sharp s include ss
109 * - for k include the Kelvin sign
110 */
111U_CAPI void U_EXPORT2
112ucase_addCaseClosure(const UCaseProps *csp, UChar32 c, const USetAdder *sa);
113
114/**
115 * Maps the string to single code points and adds the associated case closure
116 * mappings.
117 * The string is mapped to code points if it is their full case folding string.
118 * In other words, this performs a reverse full case folding and then
119 * adds the case closure items of the resulting code points.
120 * If the string is found and its closure applied, then
121 * the string itself is added as well as part of its code points' closure.
122 * It must be length>=0.
123 *
124 * @return TRUE if the string was found
125 */
126U_CAPI UBool U_EXPORT2
127ucase_addStringCaseClosure(const UCaseProps *csp, const UChar *s, int32_t length, const USetAdder *sa);
374ca955
A
128
129/** @return UCASE_NONE, UCASE_LOWER, UCASE_UPPER, UCASE_TITLE */
130U_CAPI int32_t U_EXPORT2
131ucase_getType(const UCaseProps *csp, UChar32 c);
132
133/** @return same as ucase_getType(), or <0 if c is case-ignorable */
134U_CAPI int32_t U_EXPORT2
135ucase_getTypeOrIgnorable(const UCaseProps *csp, UChar32 c);
136
137U_CAPI UBool U_EXPORT2
138ucase_isSoftDotted(const UCaseProps *csp, UChar32 c);
139
140U_CAPI UBool U_EXPORT2
141ucase_isCaseSensitive(const UCaseProps *csp, UChar32 c);
142
143/* string case mapping functions */
144
145/**
146 * Iterator function for string case mappings, which need to look at the
147 * context (surrounding text) of a given character for conditional mappings.
148 *
149 * The iterator only needs to go backward or forward away from the
150 * character in question. It does not use any indexes on this interface.
151 * It does not support random access or an arbitrary change of
152 * iteration direction.
153 *
73c04bcf
A
154 * The code point being case-mapped itself is never returned by
155 * this iterator.
374ca955
A
156 *
157 * @param context A pointer to the iterator's working data.
158 * @param dir If <0 then start iterating backward from the character;
159 * if >0 then start iterating forward from the character;
160 * if 0 then continue iterating in the current direction.
161 * @return Next code point, or <0 when the iteration is done.
162 */
163typedef UChar32 U_CALLCONV
164UCaseContextIterator(void *context, int8_t dir);
165
166/**
167 * Sample struct which may be used by some implementations of
168 * UCaseContextIterator.
169 */
170struct UCaseContext {
171 void *p;
172 int32_t start, index, limit;
173 int32_t cpStart, cpLimit;
174 int8_t dir;
175 int8_t b1, b2, b3;
176};
177typedef struct UCaseContext UCaseContext;
178
179enum {
180 /**
181 * For string case mappings, a single character (a code point) is mapped
182 * either to itself (in which case in-place mapping functions do nothing),
183 * or to another single code point, or to a string.
184 * Aside from the string contents, these are indicated with a single int32_t
185 * value as follows:
186 *
187 * Mapping to self: Negative values (~self instead of -self to support U+0000)
188 *
189 * Mapping to another code point: Positive values >UCASE_MAX_STRING_LENGTH
190 *
191 * Mapping to a string: The string length (0..UCASE_MAX_STRING_LENGTH) is
192 * returned. Note that the string result may indeed have zero length.
193 */
194 UCASE_MAX_STRING_LENGTH=0x1f
195};
196
197/**
198 * Get the full lowercase mapping for c.
199 *
200 * @param csp Case mapping properties.
201 * @param c Character to be mapped.
202 * @param iter Character iterator, used for context-sensitive mappings.
203 * See UCaseContextIterator for details.
204 * If iter==NULL then a context-independent result is returned.
205 * @param context Pointer to be passed into iter.
206 * @param pString If the mapping result is a string, then the pointer is
207 * written to *pString.
208 * @param locale Locale ID for locale-dependent mappings.
209 * @param locCache Initialize to 0; may be used to cache the result of parsing
210 * the locale ID for subsequent calls.
211 * Can be NULL.
212 * @return Output code point or string length, see UCASE_MAX_STRING_LENGTH.
213 *
214 * @see UCaseContextIterator
215 * @see UCASE_MAX_STRING_LENGTH
216 * @internal
217 */
218U_CAPI int32_t U_EXPORT2
219ucase_toFullLower(const UCaseProps *csp, UChar32 c,
220 UCaseContextIterator *iter, void *context,
221 const UChar **pString,
222 const char *locale, int32_t *locCache);
223
224U_CAPI int32_t U_EXPORT2
225ucase_toFullUpper(const UCaseProps *csp, UChar32 c,
226 UCaseContextIterator *iter, void *context,
227 const UChar **pString,
228 const char *locale, int32_t *locCache);
229
230U_CAPI int32_t U_EXPORT2
231ucase_toFullTitle(const UCaseProps *csp, UChar32 c,
232 UCaseContextIterator *iter, void *context,
233 const UChar **pString,
234 const char *locale, int32_t *locCache);
235
236U_CAPI int32_t U_EXPORT2
237ucase_toFullFolding(const UCaseProps *csp, UChar32 c,
238 const UChar **pString,
239 uint32_t options);
240
73c04bcf
A
241U_CFUNC int32_t U_EXPORT2
242ucase_hasBinaryProperty(UChar32 c, UProperty which);
243
374ca955
A
244/* file definitions --------------------------------------------------------- */
245
246#define UCASE_DATA_NAME "ucase"
247#define UCASE_DATA_TYPE "icu"
248
249/* format "cAsE" */
250#define UCASE_FMT_0 0x63
251#define UCASE_FMT_1 0x41
252#define UCASE_FMT_2 0x53
253#define UCASE_FMT_3 0x45
254
255/* indexes into indexes[] */
256enum {
257 UCASE_IX_INDEX_TOP,
258 UCASE_IX_LENGTH,
259 UCASE_IX_TRIE_SIZE,
260 UCASE_IX_EXC_LENGTH,
73c04bcf 261 UCASE_IX_UNFOLD_LENGTH,
374ca955
A
262
263 UCASE_IX_MAX_FULL_LENGTH=15,
264 UCASE_IX_TOP=16
265};
266
267/* definitions for 16-bit case properties word ------------------------------ */
268
269/* 2-bit constants for types of cased characters */
270#define UCASE_TYPE_MASK 3
271enum {
272 UCASE_NONE,
273 UCASE_LOWER,
274 UCASE_UPPER,
275 UCASE_TITLE
276};
277
73c04bcf
A
278#define UCASE_GET_TYPE(props) ((props)&UCASE_TYPE_MASK)
279
374ca955
A
280#define UCASE_SENSITIVE 4
281#define UCASE_EXCEPTION 8
282
283#define UCASE_DOT_MASK 0x30
284enum {
285 UCASE_NO_DOT=0, /* normal characters with cc=0 */
286 UCASE_SOFT_DOTTED=0x10, /* soft-dotted characters with cc=0 */
287 UCASE_ABOVE=0x20, /* "above" accents with cc=230 */
288 UCASE_OTHER_ACCENT=0x30 /* other accent character (0<cc!=230) */
289};
290
291/* no exception: bits 15..6 are a 10-bit signed case mapping delta */
292#define UCASE_DELTA_SHIFT 6
293#define UCASE_DELTA_MASK 0xffc0
294#define UCASE_MAX_DELTA 0x1ff
295#define UCASE_MIN_DELTA (-UCASE_MAX_DELTA-1)
296
297#define UCASE_GET_DELTA(props) ((int16_t)(props)>>UCASE_DELTA_SHIFT)
298
299/* case-ignorable uses one of the delta bits, see gencase/store.c */
300#define UCASE_CASE_IGNORABLE 0x40
301
302/* exception: bits 15..4 are an unsigned 12-bit index into the exceptions array */
303#define UCASE_EXC_SHIFT 4
304#define UCASE_EXC_MASK 0xfff0
305#define UCASE_MAX_EXCEPTIONS 0x1000
306
307/* definitions for 16-bit main exceptions word ------------------------------ */
308
309/* first 8 bits indicate values in optional slots */
310enum {
311 UCASE_EXC_LOWER,
312 UCASE_EXC_FOLD,
313 UCASE_EXC_UPPER,
314 UCASE_EXC_TITLE,
315 UCASE_EXC_4, /* reserved */
316 UCASE_EXC_5, /* reserved */
73c04bcf 317 UCASE_EXC_CLOSURE,
374ca955
A
318 UCASE_EXC_FULL_MAPPINGS,
319 UCASE_EXC_ALL_SLOTS /* one past the last slot */
320};
321
322/* each slot is 2 uint16_t instead of 1 */
323#define UCASE_EXC_DOUBLE_SLOTS 0x100
324
325/* reserved: exception bits 11..9 */
326
327/* UCASE_EXC_DOT_MASK=UCASE_DOT_MASK<<UCASE_EXC_DOT_SHIFT */
328#define UCASE_EXC_DOT_SHIFT 8
329
330/* normally stored in the main word, but pushed out for larger exception indexes */
331#define UCASE_EXC_DOT_MASK 0x3000
332enum {
333 UCASE_EXC_NO_DOT=0,
334 UCASE_EXC_SOFT_DOTTED=0x1000,
335 UCASE_EXC_ABOVE=0x2000, /* "above" accents with cc=230 */
336 UCASE_EXC_OTHER_ACCENT=0x3000 /* other character (0<cc!=230) */
337};
338
339/* complex/conditional mappings */
340#define UCASE_EXC_CONDITIONAL_SPECIAL 0x4000
341#define UCASE_EXC_CONDITIONAL_FOLD 0x8000
342
343/* definitions for lengths word for full case mappings */
344#define UCASE_FULL_LOWER 0xf
345#define UCASE_FULL_FOLDING 0xf0
346#define UCASE_FULL_UPPER 0xf00
347#define UCASE_FULL_TITLE 0xf000
348
73c04bcf
A
349/* maximum lengths */
350#define UCASE_FULL_MAPPINGS_MAX_LENGTH (4*0xf)
351#define UCASE_CLOSURE_MAX_LENGTH 0xf
352
353/* constants for reverse case folding ("unfold") data */
354enum {
355 UCASE_UNFOLD_ROWS,
356 UCASE_UNFOLD_ROW_WIDTH,
357 UCASE_UNFOLD_STRING_WIDTH
358};
359
374ca955
A
360U_CDECL_END
361
362#endif