]> git.saurik.com Git - apple/icu.git/blob - icuSources/common/uprops.h
ICU-491.11.2.tar.gz
[apple/icu.git] / icuSources / common / uprops.h
1 /*
2 *******************************************************************************
3 *
4 * Copyright (C) 2002-2011, International Business Machines
5 * Corporation and others. All Rights Reserved.
6 *
7 *******************************************************************************
8 * file name: uprops.h
9 * encoding: US-ASCII
10 * tab size: 8 (not used)
11 * indentation:4
12 *
13 * created on: 2002feb24
14 * created by: Markus W. Scherer
15 *
16 * Constants for mostly non-core Unicode character properties
17 * stored in uprops.icu.
18 */
19
20 #ifndef __UPROPS_H__
21 #define __UPROPS_H__
22
23 #include "unicode/utypes.h"
24 #include "unicode/uset.h"
25 #include "uset_imp.h"
26 #include "udataswp.h"
27
28 /* indexes[] entries */
29 enum {
30 UPROPS_PROPS32_INDEX,
31 UPROPS_EXCEPTIONS_INDEX,
32 UPROPS_EXCEPTIONS_TOP_INDEX,
33
34 UPROPS_ADDITIONAL_TRIE_INDEX,
35 UPROPS_ADDITIONAL_VECTORS_INDEX,
36 UPROPS_ADDITIONAL_VECTORS_COLUMNS_INDEX,
37
38 UPROPS_SCRIPT_EXTENSIONS_INDEX,
39
40 UPROPS_RESERVED_INDEX_7,
41 UPROPS_RESERVED_INDEX_8,
42
43 /* size of the data file (number of 32-bit units after the header) */
44 UPROPS_DATA_TOP_INDEX,
45
46 /* maximum values for code values in vector word 0 */
47 UPROPS_MAX_VALUES_INDEX=10,
48 /* maximum values for code values in vector word 2 */
49 UPROPS_MAX_VALUES_2_INDEX,
50
51 UPROPS_INDEX_COUNT=16
52 };
53
54 /* definitions for the main properties words */
55 enum {
56 /* general category shift==0 0 (5 bits) */
57 /* reserved 5 (1 bit) */
58 UPROPS_NUMERIC_TYPE_VALUE_SHIFT=6 /* 6 (10 bits) */
59 };
60
61 #define GET_CATEGORY(props) ((props)&0x1f)
62 #define CAT_MASK(props) U_MASK(GET_CATEGORY(props))
63
64 #define GET_NUMERIC_TYPE_VALUE(props) ((props)>>UPROPS_NUMERIC_TYPE_VALUE_SHIFT)
65
66 /* constants for the storage form of numeric types and values */
67 enum {
68 UPROPS_NTV_NONE=0,
69 UPROPS_NTV_DECIMAL_START=1,
70 UPROPS_NTV_DIGIT_START=11,
71 UPROPS_NTV_NUMERIC_START=21,
72 UPROPS_NTV_FRACTION_START=0xb0,
73 UPROPS_NTV_LARGE_START=0x1e0,
74 UPROPS_NTV_RESERVED_START=0x300,
75
76 UPROPS_NTV_MAX_SMALL_INT=UPROPS_NTV_FRACTION_START-UPROPS_NTV_NUMERIC_START-1
77 };
78
79 #define UPROPS_NTV_GET_TYPE(ntv) \
80 ((ntv==UPROPS_NTV_NONE) ? U_NT_NONE : \
81 (ntv<UPROPS_NTV_DIGIT_START) ? U_NT_DECIMAL : \
82 (ntv<UPROPS_NTV_NUMERIC_START) ? U_NT_DIGIT : \
83 U_NT_NUMERIC)
84
85 /* number of properties vector words */
86 #define UPROPS_VECTOR_WORDS 3
87
88 /*
89 * Properties in vector word 0
90 * Bits
91 * 31..24 DerivedAge version major/minor one nibble each
92 * 23..22 3..1: Bits 7..0 = Script_Extensions index
93 * 3: Script value from Script_Extensions
94 * 2: Script=Inherited
95 * 1: Script=Common
96 * 0: Script=bits 7..0
97 * 21..20 reserved
98 * 19..17 East Asian Width
99 * 16.. 8 UBlockCode
100 * 7.. 0 UScriptCode, or index to Script_Extensions
101 */
102
103 /* derived age: one nibble each for major and minor version numbers */
104 #define UPROPS_AGE_MASK 0xff000000
105 #define UPROPS_AGE_SHIFT 24
106
107 /* Script_Extensions: mask includes Script */
108 #define UPROPS_SCRIPT_X_MASK 0x00c000ff
109 #define UPROPS_SCRIPT_X_SHIFT 22
110
111 #define UPROPS_EA_MASK 0x000e0000
112 #define UPROPS_EA_SHIFT 17
113
114 #define UPROPS_BLOCK_MASK 0x0001ff00
115 #define UPROPS_BLOCK_SHIFT 8
116
117 #define UPROPS_SCRIPT_MASK 0x000000ff
118
119 /* UPROPS_SCRIPT_X_WITH_COMMON must be the lowest value that involves Script_Extensions. */
120 #define UPROPS_SCRIPT_X_WITH_COMMON 0x400000
121 #define UPROPS_SCRIPT_X_WITH_INHERITED 0x800000
122 #define UPROPS_SCRIPT_X_WITH_OTHER 0xc00000
123
124 /*
125 * Properties in vector word 1
126 * Each bit encodes one binary property.
127 * The following constants represent the bit number, use 1<<UPROPS_XYZ.
128 * UPROPS_BINARY_1_TOP<=32!
129 *
130 * Keep this list of property enums in sync with
131 * propListNames[] in icu/source/tools/genprops/props2.c!
132 *
133 * ICU 2.6/uprops format version 3.2 stores full properties instead of "Other_".
134 */
135 enum {
136 UPROPS_WHITE_SPACE,
137 UPROPS_DASH,
138 UPROPS_HYPHEN,
139 UPROPS_QUOTATION_MARK,
140 UPROPS_TERMINAL_PUNCTUATION,
141 UPROPS_MATH,
142 UPROPS_HEX_DIGIT,
143 UPROPS_ASCII_HEX_DIGIT,
144 UPROPS_ALPHABETIC,
145 UPROPS_IDEOGRAPHIC,
146 UPROPS_DIACRITIC,
147 UPROPS_EXTENDER,
148 UPROPS_NONCHARACTER_CODE_POINT,
149 UPROPS_GRAPHEME_EXTEND,
150 UPROPS_GRAPHEME_LINK,
151 UPROPS_IDS_BINARY_OPERATOR,
152 UPROPS_IDS_TRINARY_OPERATOR,
153 UPROPS_RADICAL,
154 UPROPS_UNIFIED_IDEOGRAPH,
155 UPROPS_DEFAULT_IGNORABLE_CODE_POINT,
156 UPROPS_DEPRECATED,
157 UPROPS_LOGICAL_ORDER_EXCEPTION,
158 UPROPS_XID_START,
159 UPROPS_XID_CONTINUE,
160 UPROPS_ID_START, /* ICU 2.6, uprops format version 3.2 */
161 UPROPS_ID_CONTINUE,
162 UPROPS_GRAPHEME_BASE,
163 UPROPS_S_TERM, /* new in ICU 3.0 and Unicode 4.0.1 */
164 UPROPS_VARIATION_SELECTOR,
165 UPROPS_PATTERN_SYNTAX, /* new in ICU 3.4 and Unicode 4.1 */
166 UPROPS_PATTERN_WHITE_SPACE,
167 UPROPS_RESERVED, /* reserved & unused */
168 UPROPS_BINARY_1_TOP /* ==32 - full! */
169 };
170
171 /*
172 * Properties in vector word 2
173 * Bits
174 * 31..26 reserved
175 * 25..20 Line Break
176 * 19..15 Sentence Break
177 * 14..10 Word Break
178 * 9.. 5 Grapheme Cluster Break
179 * 4.. 0 Decomposition Type
180 */
181 #define UPROPS_LB_MASK 0x03f00000
182 #define UPROPS_LB_SHIFT 20
183
184 #define UPROPS_SB_MASK 0x000f8000
185 #define UPROPS_SB_SHIFT 15
186
187 #define UPROPS_WB_MASK 0x00007c00
188 #define UPROPS_WB_SHIFT 10
189
190 #define UPROPS_GCB_MASK 0x000003e0
191 #define UPROPS_GCB_SHIFT 5
192
193 #define UPROPS_DT_MASK 0x0000001f
194
195 /**
196 * Gets the main properties value for a code point.
197 * Implemented in uchar.c for uprops.cpp.
198 */
199 U_CFUNC uint32_t
200 u_getMainProperties(UChar32 c);
201
202 /**
203 * Get a properties vector word for a code point.
204 * Implemented in uchar.c for uprops.cpp.
205 * @return 0 if no data or illegal argument
206 */
207 U_CFUNC uint32_t
208 u_getUnicodeProperties(UChar32 c, int32_t column);
209
210 /**
211 * Get the the maximum values for some enum/int properties.
212 * Use the same column numbers as for u_getUnicodeProperties().
213 * The returned value will contain maximum values stored in the same bit fields
214 * as where the enum values are stored in the u_getUnicodeProperties()
215 * return values for the same columns.
216 *
217 * Valid columns are those for properties words that contain enumerated values.
218 * (ICU 2.6: columns 0 and 2)
219 * For other column numbers, this function will return 0.
220 *
221 * @internal
222 */
223 U_CFUNC int32_t
224 uprv_getMaxValues(int32_t column);
225
226 /**
227 * Checks if c is alphabetic, or a decimal digit; implements UCHAR_POSIX_ALNUM.
228 * @internal
229 */
230 U_CFUNC UBool
231 u_isalnumPOSIX(UChar32 c);
232
233 /**
234 * Checks if c is in
235 * [^\p{space}\p{gc=Control}\p{gc=Surrogate}\p{gc=Unassigned}]
236 * with space=\p{Whitespace} and Control=Cc.
237 * Implements UCHAR_POSIX_GRAPH.
238 * @internal
239 */
240 U_CFUNC UBool
241 u_isgraphPOSIX(UChar32 c);
242
243 /**
244 * Checks if c is in \p{graph}\p{blank} - \p{cntrl}.
245 * Implements UCHAR_POSIX_PRINT.
246 * @internal
247 */
248 U_CFUNC UBool
249 u_isprintPOSIX(UChar32 c);
250
251 /** Turn a bit index into a bit flag. @internal */
252 #define FLAG(n) ((uint32_t)1<<(n))
253
254 /** Flags for general categories in the order of UCharCategory. @internal */
255 #define _Cn FLAG(U_GENERAL_OTHER_TYPES)
256 #define _Lu FLAG(U_UPPERCASE_LETTER)
257 #define _Ll FLAG(U_LOWERCASE_LETTER)
258 #define _Lt FLAG(U_TITLECASE_LETTER)
259 #define _Lm FLAG(U_MODIFIER_LETTER)
260 /* #define _Lo FLAG(U_OTHER_LETTER) -- conflicts with MS Visual Studio 9.0 xiosbase */
261 #define _Mn FLAG(U_NON_SPACING_MARK)
262 #define _Me FLAG(U_ENCLOSING_MARK)
263 #define _Mc FLAG(U_COMBINING_SPACING_MARK)
264 #define _Nd FLAG(U_DECIMAL_DIGIT_NUMBER)
265 #define _Nl FLAG(U_LETTER_NUMBER)
266 #define _No FLAG(U_OTHER_NUMBER)
267 #define _Zs FLAG(U_SPACE_SEPARATOR)
268 #define _Zl FLAG(U_LINE_SEPARATOR)
269 #define _Zp FLAG(U_PARAGRAPH_SEPARATOR)
270 #define _Cc FLAG(U_CONTROL_CHAR)
271 #define _Cf FLAG(U_FORMAT_CHAR)
272 #define _Co FLAG(U_PRIVATE_USE_CHAR)
273 #define _Cs FLAG(U_SURROGATE)
274 #define _Pd FLAG(U_DASH_PUNCTUATION)
275 #define _Ps FLAG(U_START_PUNCTUATION)
276 /* #define _Pe FLAG(U_END_PUNCTUATION) -- conflicts with MS Visual Studio 9.0 xlocnum */
277 /* #define _Pc FLAG(U_CONNECTOR_PUNCTUATION) -- conflicts with MS Visual Studio 9.0 streambuf */
278 #define _Po FLAG(U_OTHER_PUNCTUATION)
279 #define _Sm FLAG(U_MATH_SYMBOL)
280 #define _Sc FLAG(U_CURRENCY_SYMBOL)
281 #define _Sk FLAG(U_MODIFIER_SYMBOL)
282 #define _So FLAG(U_OTHER_SYMBOL)
283 #define _Pi FLAG(U_INITIAL_PUNCTUATION)
284 /* #define _Pf FLAG(U_FINAL_PUNCTUATION) -- conflicts with MS Visual Studio 9.0 streambuf */
285
286 /** Some code points. @internal */
287 enum {
288 TAB =0x0009,
289 LF =0x000a,
290 FF =0x000c,
291 CR =0x000d,
292 U_A =0x0041,
293 U_F =0x0046,
294 U_Z =0x005a,
295 U_a =0x0061,
296 U_f =0x0066,
297 U_z =0x007a,
298 DEL =0x007f,
299 NL =0x0085,
300 NBSP =0x00a0,
301 CGJ =0x034f,
302 FIGURESP=0x2007,
303 HAIRSP =0x200a,
304 ZWNJ =0x200c,
305 ZWJ =0x200d,
306 RLM =0x200f,
307 NNBSP =0x202f,
308 WJ =0x2060,
309 INHSWAP =0x206a,
310 NOMDIG =0x206f,
311 U_FW_A =0xff21,
312 U_FW_F =0xff26,
313 U_FW_Z =0xff3a,
314 U_FW_a =0xff41,
315 U_FW_f =0xff46,
316 U_FW_z =0xff5a,
317 ZWNBSP =0xfeff
318 };
319
320 /**
321 * Get the maximum length of a (regular/1.0/extended) character name.
322 * @return 0 if no character names available.
323 */
324 U_CAPI int32_t U_EXPORT2
325 uprv_getMaxCharNameLength(void);
326
327 /**
328 * Fills set with characters that are used in Unicode character names.
329 * Includes all characters that are used in regular/Unicode 1.0/extended names.
330 * Just empties the set if no character names are available.
331 * @param sa USetAdder to receive characters.
332 */
333 U_CAPI void U_EXPORT2
334 uprv_getCharNameCharacters(const USetAdder *sa);
335
336 /**
337 * Constants for which data and implementation files provide which properties.
338 * Used by UnicodeSet for service-specific property enumeration.
339 * @internal
340 */
341 enum UPropertySource {
342 /** No source, not a supported property. */
343 UPROPS_SRC_NONE,
344 /** From uchar.c/uprops.icu main trie */
345 UPROPS_SRC_CHAR,
346 /** From uchar.c/uprops.icu properties vectors trie */
347 UPROPS_SRC_PROPSVEC,
348 /** From unames.c/unames.icu */
349 UPROPS_SRC_NAMES,
350 /** From ucase.c/ucase.icu */
351 UPROPS_SRC_CASE,
352 /** From ubidi_props.c/ubidi.icu */
353 UPROPS_SRC_BIDI,
354 /** From uchar.c/uprops.icu main trie as well as properties vectors trie */
355 UPROPS_SRC_CHAR_AND_PROPSVEC,
356 /** From ucase.c/ucase.icu as well as unorm.cpp/unorm.icu */
357 UPROPS_SRC_CASE_AND_NORM,
358 /** From normalizer2impl.cpp/nfc.nrm */
359 UPROPS_SRC_NFC,
360 /** From normalizer2impl.cpp/nfkc.nrm */
361 UPROPS_SRC_NFKC,
362 /** From normalizer2impl.cpp/nfkc_cf.nrm */
363 UPROPS_SRC_NFKC_CF,
364 /** From normalizer2impl.cpp/nfc.nrm canonical iterator data */
365 UPROPS_SRC_NFC_CANON_ITER,
366 /** One more than the highest UPropertySource (UPROPS_SRC_) constant. */
367 UPROPS_SRC_COUNT
368 };
369 typedef enum UPropertySource UPropertySource;
370
371 /**
372 * @see UPropertySource
373 * @internal
374 */
375 U_CFUNC UPropertySource U_EXPORT2
376 uprops_getSource(UProperty which);
377
378 /**
379 * Enumerate uprops.icu's main data trie and add the
380 * start of each range of same properties to the set.
381 * @internal
382 */
383 U_CFUNC void U_EXPORT2
384 uchar_addPropertyStarts(const USetAdder *sa, UErrorCode *pErrorCode);
385
386 /**
387 * Enumerate uprops.icu's properties vectors trie and add the
388 * start of each range of same properties to the set.
389 * @internal
390 */
391 U_CFUNC void U_EXPORT2
392 upropsvec_addPropertyStarts(const USetAdder *sa, UErrorCode *pErrorCode);
393
394 /**
395 * Return a set of characters for property enumeration.
396 * For each two consecutive characters (start, limit) in the set,
397 * all of the properties for start..limit-1 are all the same.
398 *
399 * @param sa USetAdder to receive result. Existing contents are lost.
400 * @internal
401 */
402 /*U_CFUNC void U_EXPORT2
403 uprv_getInclusions(const USetAdder *sa, UErrorCode *pErrorCode);
404 */
405
406 /**
407 * Swap the ICU Unicode character names file. See uchar.c.
408 * @internal
409 */
410 U_CAPI int32_t U_EXPORT2
411 uchar_swapNames(const UDataSwapper *ds,
412 const void *inData, int32_t length, void *outData,
413 UErrorCode *pErrorCode);
414
415 #ifdef __cplusplus
416
417 U_NAMESPACE_BEGIN
418
419 class UnicodeSet;
420
421 // implemented in uniset_props.cpp
422 U_CFUNC UnicodeSet *
423 uniset_getUnicode32Instance(UErrorCode &errorCode);
424
425 U_NAMESPACE_END
426
427 #endif
428
429 #endif