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