]>
git.saurik.com Git - apple/icu.git/blob - icuSources/common/propname.h
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 **********************************************************************
5 * Copyright (c) 2002-2011, International Business Machines
6 * Corporation and others. All Rights Reserved.
7 **********************************************************************
9 * Created: October 30 2002
11 * 2010nov19 Markus Scherer Rewrite for formatVersion 2.
12 **********************************************************************
17 #include "unicode/utypes.h"
18 #include "unicode/bytestrie.h"
19 #include "unicode/uchar.h"
24 * This header defines the in-memory layout of the property names data
25 * structure representing the UCD data files PropertyAliases.txt and
26 * PropertyValueAliases.txt. It is used by:
27 * propname.cpp - reads data
28 * genpname - creates data
31 /* low-level char * property name comparison -------------------------------- */
36 * \var uprv_comparePropertyNames
37 * Unicode property names and property value names are compared "loosely".
39 * UCD.html 4.0.1 says:
40 * For all property names, property value names, and for property values for
41 * Enumerated, Binary, or Catalog properties, use the following
42 * loose matching rule:
44 * LM3. Ignore case, whitespace, underscore ('_'), and hyphens.
46 * This function does just that, for (char *) name strings.
47 * It is almost identical to ucnv_compareNames() but also ignores
48 * C0 White_Space characters (U+0009..U+000d, and U+0085 on EBCDIC).
53 U_CAPI
int32_t U_EXPORT2
54 uprv_compareASCIIPropertyNames(const char *name1
, const char *name2
);
56 U_CAPI
int32_t U_EXPORT2
57 uprv_compareEBCDICPropertyNames(const char *name1
, const char *name2
);
59 #if U_CHARSET_FAMILY==U_ASCII_FAMILY
60 # define uprv_comparePropertyNames uprv_compareASCIIPropertyNames
61 #elif U_CHARSET_FAMILY==U_EBCDIC_FAMILY
62 # define uprv_comparePropertyNames uprv_compareEBCDICPropertyNames
64 # error U_CHARSET_FAMILY is not valid
69 /* UDataMemory structure and signatures ------------------------------------- */
71 #define PNAME_DATA_NAME "pnames"
72 #define PNAME_DATA_TYPE "icu"
74 /* Fields in UDataInfo: */
76 /* PNAME_SIG[] is encoded as numeric literals for compatibility with the HP compiler */
77 #define PNAME_SIG_0 ((uint8_t)0x70) /* p */
78 #define PNAME_SIG_1 ((uint8_t)0x6E) /* n */
79 #define PNAME_SIG_2 ((uint8_t)0x61) /* a */
80 #define PNAME_SIG_3 ((uint8_t)0x6D) /* m */
87 // Byte offsets from the start of the data, after the generic header.
90 IX_NAME_GROUPS_OFFSET
,
101 static const char *getPropertyName(int32_t property
, int32_t nameChoice
);
102 static const char *getPropertyValueName(int32_t property
, int32_t value
, int32_t nameChoice
);
104 static int32_t getPropertyEnum(const char *alias
);
105 static int32_t getPropertyValueEnum(int32_t property
, const char *alias
);
108 static int32_t findProperty(int32_t property
);
109 static int32_t findPropertyValueNameGroup(int32_t valueMapIndex
, int32_t value
);
110 static const char *getName(const char *nameGroup
, int32_t nameIndex
);
111 static UBool
containsName(BytesTrie
&trie
, const char *name
);
113 static int32_t getPropertyOrValueEnum(int32_t bytesTrieOffset
, const char *alias
);
115 static const int32_t indexes
[];
116 static const int32_t valueMaps
[];
117 static const uint8_t bytesTries
[];
118 static const char nameGroups
[];
122 * pnames.icu formatVersion 2
124 * formatVersion 2 is new in ICU 4.8.
125 * In ICU 4.8, the pnames.icu data file is used only in ICU4J.
126 * ICU4C 4.8 has the same data structures hardcoded in source/common/propname_data.h.
128 * For documentation of pnames.icu formatVersion 1 see ICU4C 4.6 (2010-dec-01)
129 * or earlier versions of this header file (source/common/propname.h).
131 * The pnames.icu begins with the standard ICU DataHeader/UDataInfo.
134 * int32_t indexes[8];
136 * (See the PropNameData::IX_... constants.)
138 * The first 6 indexes are byte offsets from the beginning of the data
139 * (beginning of indexes[]) to following structures.
140 * The length of each structure is the difference between its offset
142 * All offsets are filled in: Where there is no data between two offsets,
143 * those two offsets are the same.
144 * The last offset (indexes[PropNameData::IX_TOTAL_SIZE]) indicates the
145 * total number of bytes in the file. (Not counting the standard headers.)
147 * The sixth index (indexes[PropNameData::IX_MAX_NAME_LENGTH]) has the
148 * maximum length of any Unicode property (or property value) alias.
149 * (Without normalization, that is, including underscores etc.)
151 * int32_t valueMaps[];
153 * The valueMaps[] begins with a map from UProperty enums to properties,
154 * followed by the per-property value maps from property values to names,
155 * for those properties that have named values.
156 * (Binary & enumerated, plus General_Category_Mask.)
158 * valueMaps[0] contains the number of UProperty enum ranges.
160 * int32_t start, limit -- first and last+1 UProperty enum of a dense range
161 * Followed by (limit-start) pairs of
162 * int32_t nameGroupOffset;
163 * Offset into nameGroups[] for the property's names/aliases.
164 * int32_t valueMapIndex;
165 * Offset of the property's value map in the valueMaps[] array.
166 * If the valueMapIndex is 0, then the property does not have named values.
168 * For each property's value map:
169 * int32_t bytesTrieOffset; -- Offset into bytesTries[] for name->value mapping.
171 * If numRanges is in the range 1..15, then that many ranges of values follow.
173 * int32_t start, limit -- first and last+1 UProperty enum of a range
174 * Followed by (limit-start) entries of
175 * int32_t nameGroupOffset;
176 * Offset into nameGroups[] for the property value's names/aliases.
177 * If the nameGroupOffset is 0, then this is not a named value for this property.
178 * (That is, the ranges need not be dense.)
179 * If numRanges is >=0x10, then (numRanges-0x10) sorted values
180 * and then (numRanges-0x10) corresponding nameGroupOffsets follow.
181 * Values are sorted as signed integers.
182 * In this case, the set of values is dense; no nameGroupOffset will be 0.
184 * For both properties and property values, ranges are sorted by their start/limit values.
186 * uint8_t bytesTries[];
188 * This is a sequence of BytesTrie structures, byte-serialized tries for
189 * mapping from names/aliases to values.
190 * The first one maps from property names/aliases to UProperty enum constants.
191 * The following ones are indexed by property value map bytesTrieOffsets
192 * for mapping each property's names/aliases to their property values.
196 * This is a sequence of property name groups.
197 * Each group is a list of names/aliases (invariant-character strings) for
198 * one property or property value, in the order of UCharNameChoice.
199 * The first byte of each group is the number of names in the group.
200 * It is followed by that many NUL-terminated strings.
201 * The first string is for the short name; if there is no short name,
202 * then the first string is empty.
203 * The second string is the long name. Further strings are additional aliases.
205 * The first name group is for a property rather than a property value,
206 * so that a nameGroupOffset of 0 can be used to indicate "no value"
207 * in a property's sparse value ranges.