propname.h 8.0 KB

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