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