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