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