]> git.saurik.com Git - apple/icu.git/blame - icuSources/common/propname.h
ICU-59173.0.1.tar.gz
[apple/icu.git] / icuSources / common / propname.h
CommitLineData
f3c0d7a5
A
1// © 2016 and later: Unicode, Inc. and others.
2// License & terms of use: http://www.unicode.org/copyright.html
b75a7d8f
A
3/*
4**********************************************************************
4388f060 5* Copyright (c) 2002-2011, International Business Machines
b75a7d8f
A
6* Corporation and others. All Rights Reserved.
7**********************************************************************
8* Author: Alan Liu
9* Created: October 30 2002
10* Since: ICU 2.4
4388f060 11* 2010nov19 Markus Scherer Rewrite for formatVersion 2.
b75a7d8f
A
12**********************************************************************
13*/
14#ifndef PROPNAME_H
15#define PROPNAME_H
16
17#include "unicode/utypes.h"
4388f060 18#include "unicode/bytestrie.h"
b75a7d8f 19#include "unicode/uchar.h"
374ca955 20#include "udataswp.h"
b75a7d8f
A
21#include "uprops.h"
22
374ca955
A
23/*
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
29 */
b75a7d8f 30
374ca955
A
31/* low-level char * property name comparison -------------------------------- */
32
33U_CDECL_BEGIN
b75a7d8f 34
374ca955
A
35/**
36 * \var uprv_comparePropertyNames
37 * Unicode property names and property value names are compared "loosely".
38 *
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:
43 *
44 * LM3. Ignore case, whitespace, underscore ('_'), and hyphens.
45 *
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).
49 *
50 * @internal
51 */
b75a7d8f 52
374ca955
A
53U_CAPI int32_t U_EXPORT2
54uprv_compareASCIIPropertyNames(const char *name1, const char *name2);
55
56U_CAPI int32_t U_EXPORT2
57uprv_compareEBCDICPropertyNames(const char *name1, const char *name2);
58
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
63#else
64# error U_CHARSET_FAMILY is not valid
65#endif
66
67U_CDECL_END
68
69/* UDataMemory structure and signatures ------------------------------------- */
b75a7d8f
A
70
71#define PNAME_DATA_NAME "pnames"
72#define PNAME_DATA_TYPE "icu"
73
374ca955 74/* Fields in UDataInfo: */
b75a7d8f 75
374ca955 76/* PNAME_SIG[] is encoded as numeric literals for compatibility with the HP compiler */
b75a7d8f
A
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 */
81
374ca955
A
82U_NAMESPACE_BEGIN
83
4388f060
A
84class PropNameData {
85public:
86 enum {
87 // Byte offsets from the start of the data, after the generic header.
88 IX_VALUE_MAPS_OFFSET,
89 IX_BYTE_TRIES_OFFSET,
90 IX_NAME_GROUPS_OFFSET,
91 IX_RESERVED3_OFFSET,
92 IX_RESERVED4_OFFSET,
93 IX_TOTAL_SIZE,
94
95 // Other values.
96 IX_MAX_NAME_LENGTH,
97 IX_RESERVED7,
98 IX_COUNT
99 };
100
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);
103
104 static int32_t getPropertyEnum(const char *alias);
105 static int32_t getPropertyValueEnum(int32_t property, const char *alias);
106
107private:
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);
112
113 static int32_t getPropertyOrValueEnum(int32_t bytesTrieOffset, const char *alias);
114
115 static const int32_t indexes[];
116 static const int32_t valueMaps[];
117 static const uint8_t bytesTries[];
118 static const char nameGroups[];
b75a7d8f
A
119};
120
4388f060
A
121/*
122 * pnames.icu formatVersion 2
b75a7d8f 123 *
4388f060
A
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.
b75a7d8f 127 *
4388f060
A
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).
b75a7d8f 130 *
4388f060
A
131 * The pnames.icu begins with the standard ICU DataHeader/UDataInfo.
132 * After that:
b75a7d8f 133 *
4388f060 134 * int32_t indexes[8];
374ca955 135 *
4388f060 136 * (See the PropNameData::IX_... constants.)
374ca955 137 *
4388f060
A
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
141 * and the next one.
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.)
374ca955 146 *
4388f060
A
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.)
150 *
151 * int32_t valueMaps[];
152 *
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.)
157 *
158 * valueMaps[0] contains the number of UProperty enum ranges.
159 * For each range:
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.
167 *
168 * For each property's value map:
169 * int32_t bytesTrieOffset; -- Offset into bytesTries[] for name->value mapping.
170 * int32_t numRanges;
171 * If numRanges is in the range 1..15, then that many ranges of values follow.
172 * Per range:
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.
183 *
184 * For both properties and property values, ranges are sorted by their start/limit values.
185 *
186 * uint8_t bytesTries[];
187 *
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.
193 *
194 * char nameGroups[];
195 *
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.
204 *
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.
b75a7d8f 208 */
b75a7d8f 209
4388f060 210U_NAMESPACE_END
b75a7d8f 211
374ca955 212#endif