uprops.h 15 KB

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