1*0e209d39SAndroid Build Coastguard Worker // © 2016 and later: Unicode, Inc. and others. 2*0e209d39SAndroid Build Coastguard Worker // License & terms of use: http://www.unicode.org/copyright.html 3*0e209d39SAndroid Build Coastguard Worker /* 4*0e209d39SAndroid Build Coastguard Worker ********************************************************************** 5*0e209d39SAndroid Build Coastguard Worker * Copyright (c) 2002-2011, International Business Machines 6*0e209d39SAndroid Build Coastguard Worker * Corporation and others. All Rights Reserved. 7*0e209d39SAndroid Build Coastguard Worker ********************************************************************** 8*0e209d39SAndroid Build Coastguard Worker * Author: Alan Liu 9*0e209d39SAndroid Build Coastguard Worker * Created: October 30 2002 10*0e209d39SAndroid Build Coastguard Worker * Since: ICU 2.4 11*0e209d39SAndroid Build Coastguard Worker * 2010nov19 Markus Scherer Rewrite for formatVersion 2. 12*0e209d39SAndroid Build Coastguard Worker ********************************************************************** 13*0e209d39SAndroid Build Coastguard Worker */ 14*0e209d39SAndroid Build Coastguard Worker #ifndef PROPNAME_H 15*0e209d39SAndroid Build Coastguard Worker #define PROPNAME_H 16*0e209d39SAndroid Build Coastguard Worker 17*0e209d39SAndroid Build Coastguard Worker #include "unicode/utypes.h" 18*0e209d39SAndroid Build Coastguard Worker #include "unicode/bytestrie.h" 19*0e209d39SAndroid Build Coastguard Worker #include "unicode/uchar.h" 20*0e209d39SAndroid Build Coastguard Worker #include "udataswp.h" 21*0e209d39SAndroid Build Coastguard Worker #include "uprops.h" 22*0e209d39SAndroid Build Coastguard Worker 23*0e209d39SAndroid Build Coastguard Worker /* 24*0e209d39SAndroid Build Coastguard Worker * This header defines the in-memory layout of the property names data 25*0e209d39SAndroid Build Coastguard Worker * structure representing the UCD data files PropertyAliases.txt and 26*0e209d39SAndroid Build Coastguard Worker * PropertyValueAliases.txt. It is used by: 27*0e209d39SAndroid Build Coastguard Worker * propname.cpp - reads data 28*0e209d39SAndroid Build Coastguard Worker * genpname - creates data 29*0e209d39SAndroid Build Coastguard Worker */ 30*0e209d39SAndroid Build Coastguard Worker 31*0e209d39SAndroid Build Coastguard Worker /* low-level char * property name comparison -------------------------------- */ 32*0e209d39SAndroid Build Coastguard Worker 33*0e209d39SAndroid Build Coastguard Worker U_CDECL_BEGIN 34*0e209d39SAndroid Build Coastguard Worker 35*0e209d39SAndroid Build Coastguard Worker /** 36*0e209d39SAndroid Build Coastguard Worker * \var uprv_comparePropertyNames 37*0e209d39SAndroid Build Coastguard Worker * Unicode property names and property value names are compared "loosely". 38*0e209d39SAndroid Build Coastguard Worker * 39*0e209d39SAndroid Build Coastguard Worker * UCD.html 4.0.1 says: 40*0e209d39SAndroid Build Coastguard Worker * For all property names, property value names, and for property values for 41*0e209d39SAndroid Build Coastguard Worker * Enumerated, Binary, or Catalog properties, use the following 42*0e209d39SAndroid Build Coastguard Worker * loose matching rule: 43*0e209d39SAndroid Build Coastguard Worker * 44*0e209d39SAndroid Build Coastguard Worker * LM3. Ignore case, whitespace, underscore ('_'), and hyphens. 45*0e209d39SAndroid Build Coastguard Worker * 46*0e209d39SAndroid Build Coastguard Worker * This function does just that, for (char *) name strings. 47*0e209d39SAndroid Build Coastguard Worker * It is almost identical to ucnv_compareNames() but also ignores 48*0e209d39SAndroid Build Coastguard Worker * C0 White_Space characters (U+0009..U+000d, and U+0085 on EBCDIC). 49*0e209d39SAndroid Build Coastguard Worker * 50*0e209d39SAndroid Build Coastguard Worker * @internal 51*0e209d39SAndroid Build Coastguard Worker */ 52*0e209d39SAndroid Build Coastguard Worker 53*0e209d39SAndroid Build Coastguard Worker U_CAPI int32_t U_EXPORT2 54*0e209d39SAndroid Build Coastguard Worker uprv_compareASCIIPropertyNames(const char *name1, const char *name2); 55*0e209d39SAndroid Build Coastguard Worker 56*0e209d39SAndroid Build Coastguard Worker U_CAPI int32_t U_EXPORT2 57*0e209d39SAndroid Build Coastguard Worker uprv_compareEBCDICPropertyNames(const char *name1, const char *name2); 58*0e209d39SAndroid Build Coastguard Worker 59*0e209d39SAndroid Build Coastguard Worker #if U_CHARSET_FAMILY==U_ASCII_FAMILY 60*0e209d39SAndroid Build Coastguard Worker # define uprv_comparePropertyNames uprv_compareASCIIPropertyNames 61*0e209d39SAndroid Build Coastguard Worker #elif U_CHARSET_FAMILY==U_EBCDIC_FAMILY 62*0e209d39SAndroid Build Coastguard Worker # define uprv_comparePropertyNames uprv_compareEBCDICPropertyNames 63*0e209d39SAndroid Build Coastguard Worker #else 64*0e209d39SAndroid Build Coastguard Worker # error U_CHARSET_FAMILY is not valid 65*0e209d39SAndroid Build Coastguard Worker #endif 66*0e209d39SAndroid Build Coastguard Worker 67*0e209d39SAndroid Build Coastguard Worker U_CDECL_END 68*0e209d39SAndroid Build Coastguard Worker 69*0e209d39SAndroid Build Coastguard Worker /* UDataMemory structure and signatures ------------------------------------- */ 70*0e209d39SAndroid Build Coastguard Worker 71*0e209d39SAndroid Build Coastguard Worker #define PNAME_DATA_NAME "pnames" 72*0e209d39SAndroid Build Coastguard Worker #define PNAME_DATA_TYPE "icu" 73*0e209d39SAndroid Build Coastguard Worker 74*0e209d39SAndroid Build Coastguard Worker /* Fields in UDataInfo: */ 75*0e209d39SAndroid Build Coastguard Worker 76*0e209d39SAndroid Build Coastguard Worker /* PNAME_SIG[] is encoded as numeric literals for compatibility with the HP compiler */ 77*0e209d39SAndroid Build Coastguard Worker #define PNAME_SIG_0 ((uint8_t)0x70) /* p */ 78*0e209d39SAndroid Build Coastguard Worker #define PNAME_SIG_1 ((uint8_t)0x6E) /* n */ 79*0e209d39SAndroid Build Coastguard Worker #define PNAME_SIG_2 ((uint8_t)0x61) /* a */ 80*0e209d39SAndroid Build Coastguard Worker #define PNAME_SIG_3 ((uint8_t)0x6D) /* m */ 81*0e209d39SAndroid Build Coastguard Worker 82*0e209d39SAndroid Build Coastguard Worker U_NAMESPACE_BEGIN 83*0e209d39SAndroid Build Coastguard Worker 84*0e209d39SAndroid Build Coastguard Worker class PropNameData { 85*0e209d39SAndroid Build Coastguard Worker public: 86*0e209d39SAndroid Build Coastguard Worker enum { 87*0e209d39SAndroid Build Coastguard Worker // Byte offsets from the start of the data, after the generic header. 88*0e209d39SAndroid Build Coastguard Worker IX_VALUE_MAPS_OFFSET, 89*0e209d39SAndroid Build Coastguard Worker IX_BYTE_TRIES_OFFSET, 90*0e209d39SAndroid Build Coastguard Worker IX_NAME_GROUPS_OFFSET, 91*0e209d39SAndroid Build Coastguard Worker IX_RESERVED3_OFFSET, 92*0e209d39SAndroid Build Coastguard Worker IX_RESERVED4_OFFSET, 93*0e209d39SAndroid Build Coastguard Worker IX_TOTAL_SIZE, 94*0e209d39SAndroid Build Coastguard Worker 95*0e209d39SAndroid Build Coastguard Worker // Other values. 96*0e209d39SAndroid Build Coastguard Worker IX_MAX_NAME_LENGTH, 97*0e209d39SAndroid Build Coastguard Worker IX_RESERVED7, 98*0e209d39SAndroid Build Coastguard Worker IX_COUNT 99*0e209d39SAndroid Build Coastguard Worker }; 100*0e209d39SAndroid Build Coastguard Worker 101*0e209d39SAndroid Build Coastguard Worker static const char *getPropertyName(int32_t property, int32_t nameChoice); 102*0e209d39SAndroid Build Coastguard Worker static const char *getPropertyValueName(int32_t property, int32_t value, int32_t nameChoice); 103*0e209d39SAndroid Build Coastguard Worker 104*0e209d39SAndroid Build Coastguard Worker static int32_t getPropertyEnum(const char *alias); 105*0e209d39SAndroid Build Coastguard Worker static int32_t getPropertyValueEnum(int32_t property, const char *alias); 106*0e209d39SAndroid Build Coastguard Worker 107*0e209d39SAndroid Build Coastguard Worker private: 108*0e209d39SAndroid Build Coastguard Worker static int32_t findProperty(int32_t property); 109*0e209d39SAndroid Build Coastguard Worker static int32_t findPropertyValueNameGroup(int32_t valueMapIndex, int32_t value); 110*0e209d39SAndroid Build Coastguard Worker static const char *getName(const char *nameGroup, int32_t nameIndex); 111*0e209d39SAndroid Build Coastguard Worker static UBool containsName(BytesTrie &trie, const char *name); 112*0e209d39SAndroid Build Coastguard Worker 113*0e209d39SAndroid Build Coastguard Worker static int32_t getPropertyOrValueEnum(int32_t bytesTrieOffset, const char *alias); 114*0e209d39SAndroid Build Coastguard Worker 115*0e209d39SAndroid Build Coastguard Worker static const int32_t indexes[]; 116*0e209d39SAndroid Build Coastguard Worker static const int32_t valueMaps[]; 117*0e209d39SAndroid Build Coastguard Worker static const uint8_t bytesTries[]; 118*0e209d39SAndroid Build Coastguard Worker static const char nameGroups[]; 119*0e209d39SAndroid Build Coastguard Worker }; 120*0e209d39SAndroid Build Coastguard Worker 121*0e209d39SAndroid Build Coastguard Worker /* 122*0e209d39SAndroid Build Coastguard Worker * pnames.icu formatVersion 2 123*0e209d39SAndroid Build Coastguard Worker * 124*0e209d39SAndroid Build Coastguard Worker * formatVersion 2 is new in ICU 4.8. 125*0e209d39SAndroid Build Coastguard Worker * In ICU 4.8, the pnames.icu data file is used only in ICU4J. 126*0e209d39SAndroid Build Coastguard Worker * ICU4C 4.8 has the same data structures hardcoded in source/common/propname_data.h. 127*0e209d39SAndroid Build Coastguard Worker * 128*0e209d39SAndroid Build Coastguard Worker * For documentation of pnames.icu formatVersion 1 see ICU4C 4.6 (2010-dec-01) 129*0e209d39SAndroid Build Coastguard Worker * or earlier versions of this header file (source/common/propname.h). 130*0e209d39SAndroid Build Coastguard Worker * 131*0e209d39SAndroid Build Coastguard Worker * The pnames.icu begins with the standard ICU DataHeader/UDataInfo. 132*0e209d39SAndroid Build Coastguard Worker * After that: 133*0e209d39SAndroid Build Coastguard Worker * 134*0e209d39SAndroid Build Coastguard Worker * int32_t indexes[8]; 135*0e209d39SAndroid Build Coastguard Worker * 136*0e209d39SAndroid Build Coastguard Worker * (See the PropNameData::IX_... constants.) 137*0e209d39SAndroid Build Coastguard Worker * 138*0e209d39SAndroid Build Coastguard Worker * The first 6 indexes are byte offsets from the beginning of the data 139*0e209d39SAndroid Build Coastguard Worker * (beginning of indexes[]) to following structures. 140*0e209d39SAndroid Build Coastguard Worker * The length of each structure is the difference between its offset 141*0e209d39SAndroid Build Coastguard Worker * and the next one. 142*0e209d39SAndroid Build Coastguard Worker * All offsets are filled in: Where there is no data between two offsets, 143*0e209d39SAndroid Build Coastguard Worker * those two offsets are the same. 144*0e209d39SAndroid Build Coastguard Worker * The last offset (indexes[PropNameData::IX_TOTAL_SIZE]) indicates the 145*0e209d39SAndroid Build Coastguard Worker * total number of bytes in the file. (Not counting the standard headers.) 146*0e209d39SAndroid Build Coastguard Worker * 147*0e209d39SAndroid Build Coastguard Worker * The sixth index (indexes[PropNameData::IX_MAX_NAME_LENGTH]) has the 148*0e209d39SAndroid Build Coastguard Worker * maximum length of any Unicode property (or property value) alias. 149*0e209d39SAndroid Build Coastguard Worker * (Without normalization, that is, including underscores etc.) 150*0e209d39SAndroid Build Coastguard Worker * 151*0e209d39SAndroid Build Coastguard Worker * int32_t valueMaps[]; 152*0e209d39SAndroid Build Coastguard Worker * 153*0e209d39SAndroid Build Coastguard Worker * The valueMaps[] begins with a map from UProperty enums to properties, 154*0e209d39SAndroid Build Coastguard Worker * followed by the per-property value maps from property values to names, 155*0e209d39SAndroid Build Coastguard Worker * for those properties that have named values. 156*0e209d39SAndroid Build Coastguard Worker * (Binary & enumerated, plus General_Category_Mask.) 157*0e209d39SAndroid Build Coastguard Worker * 158*0e209d39SAndroid Build Coastguard Worker * valueMaps[0] contains the number of UProperty enum ranges. 159*0e209d39SAndroid Build Coastguard Worker * For each range: 160*0e209d39SAndroid Build Coastguard Worker * int32_t start, limit -- first and last+1 UProperty enum of a dense range 161*0e209d39SAndroid Build Coastguard Worker * Followed by (limit-start) pairs of 162*0e209d39SAndroid Build Coastguard Worker * int32_t nameGroupOffset; 163*0e209d39SAndroid Build Coastguard Worker * Offset into nameGroups[] for the property's names/aliases. 164*0e209d39SAndroid Build Coastguard Worker * int32_t valueMapIndex; 165*0e209d39SAndroid Build Coastguard Worker * Offset of the property's value map in the valueMaps[] array. 166*0e209d39SAndroid Build Coastguard Worker * If the valueMapIndex is 0, then the property does not have named values. 167*0e209d39SAndroid Build Coastguard Worker * 168*0e209d39SAndroid Build Coastguard Worker * For each property's value map: 169*0e209d39SAndroid Build Coastguard Worker * int32_t bytesTrieOffset; -- Offset into bytesTries[] for name->value mapping. 170*0e209d39SAndroid Build Coastguard Worker * int32_t numRanges; 171*0e209d39SAndroid Build Coastguard Worker * If numRanges is in the range 1..15, then that many ranges of values follow. 172*0e209d39SAndroid Build Coastguard Worker * Per range: 173*0e209d39SAndroid Build Coastguard Worker * int32_t start, limit -- first and last+1 UProperty enum of a range 174*0e209d39SAndroid Build Coastguard Worker * Followed by (limit-start) entries of 175*0e209d39SAndroid Build Coastguard Worker * int32_t nameGroupOffset; 176*0e209d39SAndroid Build Coastguard Worker * Offset into nameGroups[] for the property value's names/aliases. 177*0e209d39SAndroid Build Coastguard Worker * If the nameGroupOffset is 0, then this is not a named value for this property. 178*0e209d39SAndroid Build Coastguard Worker * (That is, the ranges need not be dense.) 179*0e209d39SAndroid Build Coastguard Worker * If numRanges is >=0x10, then (numRanges-0x10) sorted values 180*0e209d39SAndroid Build Coastguard Worker * and then (numRanges-0x10) corresponding nameGroupOffsets follow. 181*0e209d39SAndroid Build Coastguard Worker * Values are sorted as signed integers. 182*0e209d39SAndroid Build Coastguard Worker * In this case, the set of values is dense; no nameGroupOffset will be 0. 183*0e209d39SAndroid Build Coastguard Worker * 184*0e209d39SAndroid Build Coastguard Worker * For both properties and property values, ranges are sorted by their start/limit values. 185*0e209d39SAndroid Build Coastguard Worker * 186*0e209d39SAndroid Build Coastguard Worker * uint8_t bytesTries[]; 187*0e209d39SAndroid Build Coastguard Worker * 188*0e209d39SAndroid Build Coastguard Worker * This is a sequence of BytesTrie structures, byte-serialized tries for 189*0e209d39SAndroid Build Coastguard Worker * mapping from names/aliases to values. 190*0e209d39SAndroid Build Coastguard Worker * The first one maps from property names/aliases to UProperty enum constants. 191*0e209d39SAndroid Build Coastguard Worker * The following ones are indexed by property value map bytesTrieOffsets 192*0e209d39SAndroid Build Coastguard Worker * for mapping each property's names/aliases to their property values. 193*0e209d39SAndroid Build Coastguard Worker * 194*0e209d39SAndroid Build Coastguard Worker * char nameGroups[]; 195*0e209d39SAndroid Build Coastguard Worker * 196*0e209d39SAndroid Build Coastguard Worker * This is a sequence of property name groups. 197*0e209d39SAndroid Build Coastguard Worker * Each group is a list of names/aliases (invariant-character strings) for 198*0e209d39SAndroid Build Coastguard Worker * one property or property value, in the order of UCharNameChoice. 199*0e209d39SAndroid Build Coastguard Worker * The first byte of each group is the number of names in the group. 200*0e209d39SAndroid Build Coastguard Worker * It is followed by that many NUL-terminated strings. 201*0e209d39SAndroid Build Coastguard Worker * The first string is for the short name; if there is no short name, 202*0e209d39SAndroid Build Coastguard Worker * then the first string is empty. 203*0e209d39SAndroid Build Coastguard Worker * The second string is the long name. Further strings are additional aliases. 204*0e209d39SAndroid Build Coastguard Worker * 205*0e209d39SAndroid Build Coastguard Worker * The first name group is for a property rather than a property value, 206*0e209d39SAndroid Build Coastguard Worker * so that a nameGroupOffset of 0 can be used to indicate "no value" 207*0e209d39SAndroid Build Coastguard Worker * in a property's sparse value ranges. 208*0e209d39SAndroid Build Coastguard Worker */ 209*0e209d39SAndroid Build Coastguard Worker 210*0e209d39SAndroid Build Coastguard Worker U_NAMESPACE_END 211*0e209d39SAndroid Build Coastguard Worker 212*0e209d39SAndroid Build Coastguard Worker #endif 213