michael@0: /* michael@0: ********************************************************************** michael@0: * Copyright (c) 2002-2011, International Business Machines michael@0: * Corporation and others. All Rights Reserved. michael@0: ********************************************************************** michael@0: * Author: Alan Liu michael@0: * Created: October 30 2002 michael@0: * Since: ICU 2.4 michael@0: * 2010nov19 Markus Scherer Rewrite for formatVersion 2. michael@0: ********************************************************************** michael@0: */ michael@0: #ifndef PROPNAME_H michael@0: #define PROPNAME_H michael@0: michael@0: #include "unicode/utypes.h" michael@0: #include "unicode/bytestrie.h" michael@0: #include "unicode/uchar.h" michael@0: #include "udataswp.h" michael@0: #include "uprops.h" michael@0: michael@0: /* michael@0: * This header defines the in-memory layout of the property names data michael@0: * structure representing the UCD data files PropertyAliases.txt and michael@0: * PropertyValueAliases.txt. It is used by: michael@0: * propname.cpp - reads data michael@0: * genpname - creates data michael@0: */ michael@0: michael@0: /* low-level char * property name comparison -------------------------------- */ michael@0: michael@0: U_CDECL_BEGIN michael@0: michael@0: /** michael@0: * \var uprv_comparePropertyNames michael@0: * Unicode property names and property value names are compared "loosely". michael@0: * michael@0: * UCD.html 4.0.1 says: michael@0: * For all property names, property value names, and for property values for michael@0: * Enumerated, Binary, or Catalog properties, use the following michael@0: * loose matching rule: michael@0: * michael@0: * LM3. Ignore case, whitespace, underscore ('_'), and hyphens. michael@0: * michael@0: * This function does just that, for (char *) name strings. michael@0: * It is almost identical to ucnv_compareNames() but also ignores michael@0: * C0 White_Space characters (U+0009..U+000d, and U+0085 on EBCDIC). michael@0: * michael@0: * @internal michael@0: */ michael@0: michael@0: U_CAPI int32_t U_EXPORT2 michael@0: uprv_compareASCIIPropertyNames(const char *name1, const char *name2); michael@0: michael@0: U_CAPI int32_t U_EXPORT2 michael@0: uprv_compareEBCDICPropertyNames(const char *name1, const char *name2); michael@0: michael@0: #if U_CHARSET_FAMILY==U_ASCII_FAMILY michael@0: # define uprv_comparePropertyNames uprv_compareASCIIPropertyNames michael@0: #elif U_CHARSET_FAMILY==U_EBCDIC_FAMILY michael@0: # define uprv_comparePropertyNames uprv_compareEBCDICPropertyNames michael@0: #else michael@0: # error U_CHARSET_FAMILY is not valid michael@0: #endif michael@0: michael@0: U_CDECL_END michael@0: michael@0: /* UDataMemory structure and signatures ------------------------------------- */ michael@0: michael@0: #define PNAME_DATA_NAME "pnames" michael@0: #define PNAME_DATA_TYPE "icu" michael@0: michael@0: /* Fields in UDataInfo: */ michael@0: michael@0: /* PNAME_SIG[] is encoded as numeric literals for compatibility with the HP compiler */ michael@0: #define PNAME_SIG_0 ((uint8_t)0x70) /* p */ michael@0: #define PNAME_SIG_1 ((uint8_t)0x6E) /* n */ michael@0: #define PNAME_SIG_2 ((uint8_t)0x61) /* a */ michael@0: #define PNAME_SIG_3 ((uint8_t)0x6D) /* m */ michael@0: michael@0: U_NAMESPACE_BEGIN michael@0: michael@0: class PropNameData { michael@0: public: michael@0: enum { michael@0: // Byte offsets from the start of the data, after the generic header. michael@0: IX_VALUE_MAPS_OFFSET, michael@0: IX_BYTE_TRIES_OFFSET, michael@0: IX_NAME_GROUPS_OFFSET, michael@0: IX_RESERVED3_OFFSET, michael@0: IX_RESERVED4_OFFSET, michael@0: IX_TOTAL_SIZE, michael@0: michael@0: // Other values. michael@0: IX_MAX_NAME_LENGTH, michael@0: IX_RESERVED7, michael@0: IX_COUNT michael@0: }; michael@0: michael@0: static const char *getPropertyName(int32_t property, int32_t nameChoice); michael@0: static const char *getPropertyValueName(int32_t property, int32_t value, int32_t nameChoice); michael@0: michael@0: static int32_t getPropertyEnum(const char *alias); michael@0: static int32_t getPropertyValueEnum(int32_t property, const char *alias); michael@0: michael@0: private: michael@0: static int32_t findProperty(int32_t property); michael@0: static int32_t findPropertyValueNameGroup(int32_t valueMapIndex, int32_t value); michael@0: static const char *getName(const char *nameGroup, int32_t nameIndex); michael@0: static UBool containsName(BytesTrie &trie, const char *name); michael@0: michael@0: static int32_t getPropertyOrValueEnum(int32_t bytesTrieOffset, const char *alias); michael@0: michael@0: static const int32_t indexes[]; michael@0: static const int32_t valueMaps[]; michael@0: static const uint8_t bytesTries[]; michael@0: static const char nameGroups[]; michael@0: }; michael@0: michael@0: /* michael@0: * pnames.icu formatVersion 2 michael@0: * michael@0: * formatVersion 2 is new in ICU 4.8. michael@0: * In ICU 4.8, the pnames.icu data file is used only in ICU4J. michael@0: * ICU4C 4.8 has the same data structures hardcoded in source/common/propname_data.h. michael@0: * michael@0: * For documentation of pnames.icu formatVersion 1 see ICU4C 4.6 (2010-dec-01) michael@0: * or earlier versions of this header file (source/common/propname.h). michael@0: * michael@0: * The pnames.icu begins with the standard ICU DataHeader/UDataInfo. michael@0: * After that: michael@0: * michael@0: * int32_t indexes[8]; michael@0: * michael@0: * (See the PropNameData::IX_... constants.) michael@0: * michael@0: * The first 6 indexes are byte offsets from the beginning of the data michael@0: * (beginning of indexes[]) to following structures. michael@0: * The length of each structure is the difference between its offset michael@0: * and the next one. michael@0: * All offsets are filled in: Where there is no data between two offsets, michael@0: * those two offsets are the same. michael@0: * The last offset (indexes[PropNameData::IX_TOTAL_SIZE]) indicates the michael@0: * total number of bytes in the file. (Not counting the standard headers.) michael@0: * michael@0: * The sixth index (indexes[PropNameData::IX_MAX_NAME_LENGTH]) has the michael@0: * maximum length of any Unicode property (or property value) alias. michael@0: * (Without normalization, that is, including underscores etc.) michael@0: * michael@0: * int32_t valueMaps[]; michael@0: * michael@0: * The valueMaps[] begins with a map from UProperty enums to properties, michael@0: * followed by the per-property value maps from property values to names, michael@0: * for those properties that have named values. michael@0: * (Binary & enumerated, plus General_Category_Mask.) michael@0: * michael@0: * valueMaps[0] contains the number of UProperty enum ranges. michael@0: * For each range: michael@0: * int32_t start, limit -- first and last+1 UProperty enum of a dense range michael@0: * Followed by (limit-start) pairs of michael@0: * int32_t nameGroupOffset; michael@0: * Offset into nameGroups[] for the property's names/aliases. michael@0: * int32_t valueMapIndex; michael@0: * Offset of the property's value map in the valueMaps[] array. michael@0: * If the valueMapIndex is 0, then the property does not have named values. michael@0: * michael@0: * For each property's value map: michael@0: * int32_t bytesTrieOffset; -- Offset into bytesTries[] for name->value mapping. michael@0: * int32_t numRanges; michael@0: * If numRanges is in the range 1..15, then that many ranges of values follow. michael@0: * Per range: michael@0: * int32_t start, limit -- first and last+1 UProperty enum of a range michael@0: * Followed by (limit-start) entries of michael@0: * int32_t nameGroupOffset; michael@0: * Offset into nameGroups[] for the property value's names/aliases. michael@0: * If the nameGroupOffset is 0, then this is not a named value for this property. michael@0: * (That is, the ranges need not be dense.) michael@0: * If numRanges is >=0x10, then (numRanges-0x10) sorted values michael@0: * and then (numRanges-0x10) corresponding nameGroupOffsets follow. michael@0: * Values are sorted as signed integers. michael@0: * In this case, the set of values is dense; no nameGroupOffset will be 0. michael@0: * michael@0: * For both properties and property values, ranges are sorted by their start/limit values. michael@0: * michael@0: * uint8_t bytesTries[]; michael@0: * michael@0: * This is a sequence of BytesTrie structures, byte-serialized tries for michael@0: * mapping from names/aliases to values. michael@0: * The first one maps from property names/aliases to UProperty enum constants. michael@0: * The following ones are indexed by property value map bytesTrieOffsets michael@0: * for mapping each property's names/aliases to their property values. michael@0: * michael@0: * char nameGroups[]; michael@0: * michael@0: * This is a sequence of property name groups. michael@0: * Each group is a list of names/aliases (invariant-character strings) for michael@0: * one property or property value, in the order of UCharNameChoice. michael@0: * The first byte of each group is the number of names in the group. michael@0: * It is followed by that many NUL-terminated strings. michael@0: * The first string is for the short name; if there is no short name, michael@0: * then the first string is empty. michael@0: * The second string is the long name. Further strings are additional aliases. michael@0: * michael@0: * The first name group is for a property rather than a property value, michael@0: * so that a nameGroupOffset of 0 can be used to indicate "no value" michael@0: * in a property's sparse value ranges. michael@0: */ michael@0: michael@0: U_NAMESPACE_END michael@0: michael@0: #endif