intl/unicharutil/util/nsUnicodeProperties.h

Wed, 31 Dec 2014 07:22:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:22:50 +0100
branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
permissions
-rw-r--r--

Correct previous dual key logic pending first delivery installment.

michael@0 1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
michael@0 2 * This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #ifndef NS_UNICODEPROPERTIES_H
michael@0 7 #define NS_UNICODEPROPERTIES_H
michael@0 8
michael@0 9 #include "nsBidiUtils.h"
michael@0 10 #include "nsIUGenCategory.h"
michael@0 11 #include "nsUnicodeScriptCodes.h"
michael@0 12
michael@0 13 const nsCharProps1& GetCharProps1(uint32_t aCh);
michael@0 14 const nsCharProps2& GetCharProps2(uint32_t aCh);
michael@0 15
michael@0 16 namespace mozilla {
michael@0 17
michael@0 18 namespace unicode {
michael@0 19
michael@0 20 extern nsIUGenCategory::nsUGenCategory sDetailedToGeneralCategory[];
michael@0 21
michael@0 22 uint32_t GetMirroredChar(uint32_t aCh);
michael@0 23
michael@0 24 inline uint8_t GetCombiningClass(uint32_t aCh) {
michael@0 25 return GetCharProps1(aCh).mCombiningClass;
michael@0 26 }
michael@0 27
michael@0 28 // returns the detailed General Category in terms of HB_UNICODE_* values
michael@0 29 inline uint8_t GetGeneralCategory(uint32_t aCh) {
michael@0 30 return GetCharProps2(aCh).mCategory;
michael@0 31 }
michael@0 32
michael@0 33 // returns the simplified Gen Category as defined in nsIUGenCategory
michael@0 34 inline nsIUGenCategory::nsUGenCategory GetGenCategory(uint32_t aCh) {
michael@0 35 return sDetailedToGeneralCategory[GetGeneralCategory(aCh)];
michael@0 36 }
michael@0 37
michael@0 38 inline uint8_t GetEastAsianWidth(uint32_t aCh) {
michael@0 39 return GetCharProps2(aCh).mEAW;
michael@0 40 }
michael@0 41
michael@0 42 inline uint8_t GetScriptCode(uint32_t aCh) {
michael@0 43 return GetCharProps2(aCh).mScriptCode;
michael@0 44 }
michael@0 45
michael@0 46 uint32_t GetScriptTagForCode(int32_t aScriptCode);
michael@0 47
michael@0 48 inline nsCharType GetBidiCat(uint32_t aCh) {
michael@0 49 return nsCharType(GetCharProps2(aCh).mBidiCategory);
michael@0 50 }
michael@0 51
michael@0 52 enum XidmodType {
michael@0 53 XIDMOD_INCLUSION,
michael@0 54 XIDMOD_RECOMMENDED,
michael@0 55 XIDMOD_DEFAULT_IGNORABLE,
michael@0 56 XIDMOD_HISTORIC,
michael@0 57 XIDMOD_LIMITED_USE,
michael@0 58 XIDMOD_NOT_NFKC,
michael@0 59 XIDMOD_NOT_XID,
michael@0 60 XIDMOD_OBSOLETE,
michael@0 61 XIDMOD_TECHNICAL,
michael@0 62 XIDMOD_NOT_CHARS
michael@0 63 };
michael@0 64
michael@0 65 inline XidmodType GetIdentifierModification(uint32_t aCh) {
michael@0 66 return XidmodType(GetCharProps2(aCh).mXidmod);
michael@0 67 }
michael@0 68
michael@0 69 inline bool IsRestrictedForIdentifiers(uint32_t aCh) {
michael@0 70 XidmodType xm = GetIdentifierModification(aCh);
michael@0 71 return (xm > XIDMOD_RECOMMENDED);
michael@0 72 }
michael@0 73
michael@0 74 /**
michael@0 75 * Return the numeric value of the character. The value returned is the value
michael@0 76 * of the Numeric_Value in field 7 of the UCD, or -1 if field 7 is empty.
michael@0 77 * To restrict to decimal digits, the caller should also check whether
michael@0 78 * GetGeneralCategory returns HB_UNICODE_GENERAL_CATEGORY_DECIMAL_NUMBER
michael@0 79 */
michael@0 80 inline int8_t GetNumericValue(uint32_t aCh) {
michael@0 81 return GetCharProps2(aCh).mNumericValue;
michael@0 82 }
michael@0 83
michael@0 84 enum HanVariantType {
michael@0 85 HVT_NotHan = 0x0,
michael@0 86 HVT_SimplifiedOnly = 0x1,
michael@0 87 HVT_TraditionalOnly = 0x2,
michael@0 88 HVT_AnyHan = 0x3
michael@0 89 };
michael@0 90
michael@0 91 HanVariantType GetHanVariant(uint32_t aCh);
michael@0 92
michael@0 93 uint32_t GetFullWidth(uint32_t aCh);
michael@0 94
michael@0 95 bool IsClusterExtender(uint32_t aCh, uint8_t aCategory);
michael@0 96
michael@0 97 inline bool IsClusterExtender(uint32_t aCh) {
michael@0 98 return IsClusterExtender(aCh, GetGeneralCategory(aCh));
michael@0 99 }
michael@0 100
michael@0 101 enum HSType {
michael@0 102 HST_NONE = 0x00,
michael@0 103 HST_L = 0x01,
michael@0 104 HST_V = 0x02,
michael@0 105 HST_T = 0x04,
michael@0 106 HST_LV = 0x03,
michael@0 107 HST_LVT = 0x07
michael@0 108 };
michael@0 109
michael@0 110 inline HSType GetHangulSyllableType(uint32_t aCh) {
michael@0 111 return HSType(GetCharProps1(aCh).mHangulType);
michael@0 112 }
michael@0 113
michael@0 114 // Case mappings for the full Unicode range;
michael@0 115 // note that it may be worth testing for ASCII chars and taking
michael@0 116 // a separate fast-path before calling these, in perf-critical places
michael@0 117 uint32_t GetUppercase(uint32_t aCh);
michael@0 118 uint32_t GetLowercase(uint32_t aCh);
michael@0 119 uint32_t GetTitlecaseForLower(uint32_t aCh); // maps LC to titlecase, UC unchanged
michael@0 120 uint32_t GetTitlecaseForAll(uint32_t aCh); // maps both UC and LC to titlecase
michael@0 121
michael@0 122 enum ShapingType {
michael@0 123 SHAPING_DEFAULT = 0x0001,
michael@0 124 SHAPING_ARABIC = 0x0002,
michael@0 125 SHAPING_HEBREW = 0x0004,
michael@0 126 SHAPING_HANGUL = 0x0008,
michael@0 127 SHAPING_MONGOLIAN = 0x0010,
michael@0 128 SHAPING_INDIC = 0x0020,
michael@0 129 SHAPING_THAI = 0x0040
michael@0 130 };
michael@0 131
michael@0 132 int32_t ScriptShapingType(int32_t aScriptCode);
michael@0 133
michael@0 134 // A simple iterator for a string of char16_t codepoints that advances
michael@0 135 // by Unicode grapheme clusters
michael@0 136 class ClusterIterator
michael@0 137 {
michael@0 138 public:
michael@0 139 ClusterIterator(const char16_t* aText, uint32_t aLength)
michael@0 140 : mPos(aText), mLimit(aText + aLength)
michael@0 141 #ifdef DEBUG
michael@0 142 , mText(aText)
michael@0 143 #endif
michael@0 144 { }
michael@0 145
michael@0 146 operator const char16_t* () const {
michael@0 147 return mPos;
michael@0 148 }
michael@0 149
michael@0 150 bool AtEnd() const {
michael@0 151 return mPos >= mLimit;
michael@0 152 }
michael@0 153
michael@0 154 void Next();
michael@0 155
michael@0 156 private:
michael@0 157 const char16_t* mPos;
michael@0 158 const char16_t* mLimit;
michael@0 159 #ifdef DEBUG
michael@0 160 const char16_t* mText;
michael@0 161 #endif
michael@0 162 };
michael@0 163
michael@0 164 } // end namespace unicode
michael@0 165
michael@0 166 } // end namespace mozilla
michael@0 167
michael@0 168 #endif /* NS_UNICODEPROPERTIES_H */

mercurial