uprops.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  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 unused since ICU 70 added uemoji.icu;
  197. * in ICU 57..69 stored emoji properties
  198. * 25..20 Line Break
  199. * 19..15 Sentence Break
  200. * 14..10 Word Break
  201. * 9.. 5 Grapheme Cluster Break
  202. * 4.. 0 Decomposition Type
  203. */
  204. enum {
  205. UPROPS_2_UNUSED_WAS_EXTENDED_PICTOGRAPHIC=26, // ICU 62..69
  206. UPROPS_2_UNUSED_WAS_EMOJI_COMPONENT, // ICU 60..69
  207. UPROPS_2_UNUSED_WAS_EMOJI, // ICU 57..69
  208. UPROPS_2_UNUSED_WAS_EMOJI_PRESENTATION, // ICU 57..69
  209. UPROPS_2_UNUSED_WAS_EMOJI_MODIFIER, // ICU 57..69
  210. UPROPS_2_UNUSED_WAS_EMOJI_MODIFIER_BASE // ICU 57..69
  211. };
  212. #define UPROPS_LB_MASK 0x03f00000
  213. #define UPROPS_LB_SHIFT 20
  214. #define UPROPS_SB_MASK 0x000f8000
  215. #define UPROPS_SB_SHIFT 15
  216. #define UPROPS_WB_MASK 0x00007c00
  217. #define UPROPS_WB_SHIFT 10
  218. #define UPROPS_GCB_MASK 0x000003e0
  219. #define UPROPS_GCB_SHIFT 5
  220. #define UPROPS_DT_MASK 0x0000001f
  221. /**
  222. * Gets the main properties value for a code point.
  223. * Implemented in uchar.c for uprops.cpp.
  224. */
  225. U_CFUNC uint32_t
  226. u_getMainProperties(UChar32 c);
  227. /**
  228. * Get a properties vector word for a code point.
  229. * Implemented in uchar.c for uprops.cpp.
  230. * @return 0 if no data or illegal argument
  231. */
  232. U_CFUNC uint32_t
  233. u_getUnicodeProperties(UChar32 c, int32_t column);
  234. /**
  235. * Get the the maximum values for some enum/int properties.
  236. * Use the same column numbers as for u_getUnicodeProperties().
  237. * The returned value will contain maximum values stored in the same bit fields
  238. * as where the enum values are stored in the u_getUnicodeProperties()
  239. * return values for the same columns.
  240. *
  241. * Valid columns are those for properties words that contain enumerated values.
  242. * (ICU 2.6: columns 0 and 2)
  243. * For other column numbers, this function will return 0.
  244. *
  245. * @internal
  246. */
  247. U_CFUNC int32_t
  248. uprv_getMaxValues(int32_t column);
  249. /**
  250. * Checks if c is alphabetic, or a decimal digit; implements UCHAR_POSIX_ALNUM.
  251. * @internal
  252. */
  253. U_CFUNC UBool
  254. u_isalnumPOSIX(UChar32 c);
  255. /**
  256. * Checks if c is in
  257. * [^\p{space}\p{gc=Control}\p{gc=Surrogate}\p{gc=Unassigned}]
  258. * with space=\p{Whitespace} and Control=Cc.
  259. * Implements UCHAR_POSIX_GRAPH.
  260. * @internal
  261. */
  262. U_CFUNC UBool
  263. u_isgraphPOSIX(UChar32 c);
  264. /**
  265. * Checks if c is in \p{graph}\p{blank} - \p{cntrl}.
  266. * Implements UCHAR_POSIX_PRINT.
  267. * @internal
  268. */
  269. U_CFUNC UBool
  270. u_isprintPOSIX(UChar32 c);
  271. /** Some code points. @internal */
  272. enum {
  273. TAB =0x0009,
  274. LF =0x000a,
  275. FF =0x000c,
  276. CR =0x000d,
  277. NBSP =0x00a0,
  278. CGJ =0x034f,
  279. FIGURESP=0x2007,
  280. HAIRSP =0x200a,
  281. ZWNJ =0x200c,
  282. ZWJ =0x200d,
  283. RLM =0x200f,
  284. NNBSP =0x202f,
  285. ZWNBSP =0xfeff
  286. };
  287. /**
  288. * Get the maximum length of a (regular/1.0/extended) character name.
  289. * @return 0 if no character names available.
  290. */
  291. U_CAPI int32_t U_EXPORT2
  292. uprv_getMaxCharNameLength(void);
  293. /**
  294. * Fills set with characters that are used in Unicode character names.
  295. * Includes all characters that are used in regular/Unicode 1.0/extended names.
  296. * Just empties the set if no character names are available.
  297. * @param sa USetAdder to receive characters.
  298. */
  299. U_CAPI void U_EXPORT2
  300. uprv_getCharNameCharacters(const USetAdder *sa);
  301. /**
  302. * Constants for which data and implementation files provide which properties.
  303. * Used by UnicodeSet for service-specific property enumeration.
  304. * @internal
  305. */
  306. enum UPropertySource {
  307. /** No source, not a supported property. */
  308. UPROPS_SRC_NONE,
  309. /** From uchar.c/uprops.icu main trie */
  310. UPROPS_SRC_CHAR,
  311. /** From uchar.c/uprops.icu properties vectors trie */
  312. UPROPS_SRC_PROPSVEC,
  313. /** From unames.c/unames.icu */
  314. UPROPS_SRC_NAMES,
  315. /** From ucase.c/ucase.icu */
  316. UPROPS_SRC_CASE,
  317. /** From ubidi_props.c/ubidi.icu */
  318. UPROPS_SRC_BIDI,
  319. /** From uchar.c/uprops.icu main trie as well as properties vectors trie */
  320. UPROPS_SRC_CHAR_AND_PROPSVEC,
  321. /** From ucase.c/ucase.icu as well as unorm.cpp/unorm.icu */
  322. UPROPS_SRC_CASE_AND_NORM,
  323. /** From normalizer2impl.cpp/nfc.nrm */
  324. UPROPS_SRC_NFC,
  325. /** From normalizer2impl.cpp/nfkc.nrm */
  326. UPROPS_SRC_NFKC,
  327. /** From normalizer2impl.cpp/nfkc_cf.nrm */
  328. UPROPS_SRC_NFKC_CF,
  329. /** From normalizer2impl.cpp/nfc.nrm canonical iterator data */
  330. UPROPS_SRC_NFC_CANON_ITER,
  331. // Text layout properties.
  332. UPROPS_SRC_INPC,
  333. UPROPS_SRC_INSC,
  334. UPROPS_SRC_VO,
  335. UPROPS_SRC_EMOJI,
  336. /** One more than the highest UPropertySource (UPROPS_SRC_) constant. */
  337. UPROPS_SRC_COUNT
  338. };
  339. typedef enum UPropertySource UPropertySource;
  340. /**
  341. * @see UPropertySource
  342. * @internal
  343. */
  344. U_CFUNC UPropertySource U_EXPORT2
  345. uprops_getSource(UProperty which);
  346. /**
  347. * Enumerate uprops.icu's main data trie and add the
  348. * start of each range of same properties to the set.
  349. * @internal
  350. */
  351. U_CFUNC void U_EXPORT2
  352. uchar_addPropertyStarts(const USetAdder *sa, UErrorCode *pErrorCode);
  353. /**
  354. * Enumerate uprops.icu's properties vectors trie and add the
  355. * start of each range of same properties to the set.
  356. * @internal
  357. */
  358. U_CFUNC void U_EXPORT2
  359. upropsvec_addPropertyStarts(const USetAdder *sa, UErrorCode *pErrorCode);
  360. U_CFUNC void U_EXPORT2
  361. uprops_addPropertyStarts(UPropertySource src, const USetAdder *sa, UErrorCode *pErrorCode);
  362. /**
  363. * Return a set of characters for property enumeration.
  364. * For each two consecutive characters (start, limit) in the set,
  365. * all of the properties for start..limit-1 are all the same.
  366. *
  367. * @param sa USetAdder to receive result. Existing contents are lost.
  368. * @internal
  369. */
  370. /*U_CFUNC void U_EXPORT2
  371. uprv_getInclusions(const USetAdder *sa, UErrorCode *pErrorCode);
  372. */
  373. /**
  374. * Swap the ICU Unicode character names file. See uchar.c.
  375. * @internal
  376. */
  377. U_CAPI int32_t U_EXPORT2
  378. uchar_swapNames(const UDataSwapper *ds,
  379. const void *inData, int32_t length, void *outData,
  380. UErrorCode *pErrorCode);
  381. #ifdef __cplusplus
  382. U_NAMESPACE_BEGIN
  383. class UnicodeSet;
  384. class CharacterProperties {
  385. public:
  386. CharacterProperties() = delete;
  387. static const UnicodeSet *getInclusionsForProperty(UProperty prop, UErrorCode &errorCode);
  388. static const UnicodeSet *getBinaryPropertySet(UProperty property, UErrorCode &errorCode);
  389. };
  390. // implemented in uniset_props.cpp
  391. U_CFUNC UnicodeSet *
  392. uniset_getUnicode32Instance(UErrorCode &errorCode);
  393. U_NAMESPACE_END
  394. #endif
  395. #endif