| 1 |
. |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
#ifndef __COLLATIONSETTINGS_H__ |
| 15 |
#define __COLLATIONSETTINGS_H__ |
| 16 |
|
| 17 |
#include "unicode/utypes.h" |
| 18 |
|
| 19 |
#if !UCONFIG_NO_COLLATION |
| 20 |
|
| 21 |
#include "unicode/ucol.h" |
| 22 |
#include "collation.h" |
| 23 |
#include "sharedobject.h" |
| 24 |
#include "umutex.h" |
| 25 |
|
| 26 |
U_NAMESPACE_BEGIN |
| 27 |
|
| 28 |
struct CollationData; |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
struct U_I18N_API CollationSettings : public SharedObject { |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
static const int32_t CHECK_FCD = 1; |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
static const int32_t NUMERIC = 2; |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
static const int32_t SHIFTED = 4; |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
static const int32_t ALTERNATE_MASK = 0xc; |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
static const int32_t MAX_VARIABLE_SHIFT = 4; |
| 60 |
|
| 61 |
static const int32_t MAX_VARIABLE_MASK = 0x70; |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
static const int32_t UPPER_FIRST = 0x100; |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
static const int32_t CASE_FIRST = 0x200; |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
static const int32_t CASE_FIRST_AND_UPPER_MASK = CASE_FIRST | UPPER_FIRST; |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
static const int32_t CASE_LEVEL = 0x400; |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
static const int32_t BACKWARD_SECONDARY = 0x800; |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
static const int32_t STRENGTH_SHIFT = 12; |
| 94 |
|
| 95 |
static const int32_t STRENGTH_MASK = 0xf000; |
| 96 |
|
| 97 |
|
| 98 |
enum MaxVariable { |
| 99 |
MAX_VAR_SPACE, |
| 100 |
MAX_VAR_PUNCT, |
| 101 |
MAX_VAR_SYMBOL, |
| 102 |
MAX_VAR_CURRENCY |
| 103 |
}; |
| 104 |
|
| 105 |
CollationSettings() |
| 106 |
: options((UCOL_DEFAULT_STRENGTH << STRENGTH_SHIFT) | |
| 107 |
(MAX_VAR_PUNCT << MAX_VARIABLE_SHIFT)), |
| 108 |
variableTop(0), |
| 109 |
reorderTable(nullptr), |
| 110 |
minHighNoReorder(0), |
| 111 |
reorderRanges(nullptr), reorderRangesLength(0), |
| 112 |
reorderCodes(nullptr), reorderCodesLength(0), reorderCodesCapacity(0), |
| 113 |
fastLatinOptions(-1) {} |
| 114 |
|
| 115 |
CollationSettings(const CollationSettings &other); |
| 116 |
virtual ~CollationSettings(); |
| 117 |
|
| 118 |
bool operator==(const CollationSettings &other) const; |
| 119 |
|
| 120 |
inline bool operator!=(const CollationSettings &other) const { |
| 121 |
return !operator==(other); |
| 122 |
} |
| 123 |
|
| 124 |
int32_t hashCode() const; |
| 125 |
|
| 126 |
void resetReordering(); |
| 127 |
void aliasReordering(const CollationData &data, const int32_t *codes, int32_t length, |
| 128 |
const uint32_t *ranges, int32_t rangesLength, |
| 129 |
const uint8_t *table, UErrorCode &errorCode); |
| 130 |
void setReordering(const CollationData &data, const int32_t *codes, int32_t codesLength, |
| 131 |
UErrorCode &errorCode); |
| 132 |
void copyReorderingFrom(const CollationSettings &other, UErrorCode &errorCode); |
| 133 |
|
| 134 |
inline UBool hasReordering() const { return reorderTable != nullptr; } |
| 135 |
static UBool reorderTableHasSplitBytes(const uint8_t table[256]); |
| 136 |
inline uint32_t reorder(uint32_t p) const { |
| 137 |
uint8_t b = reorderTable[p >> 24]; |
| 138 |
if(b != 0 || p <= Collation::NO_CE_PRIMARY) { |
| 139 |
return (static_cast<uint32_t>(b) << 24) | (p & 0xffffff); |
| 140 |
} else { |
| 141 |
return reorderEx(p); |
| 142 |
} |
| 143 |
} |
| 144 |
|
| 145 |
void setStrength(int32_t value, int32_t defaultOptions, UErrorCode &errorCode); |
| 146 |
|
| 147 |
static int32_t getStrength(int32_t options) { |
| 148 |
return options >> STRENGTH_SHIFT; |
| 149 |
} |
| 150 |
|
| 151 |
int32_t getStrength() const { |
| 152 |
return getStrength(options); |
| 153 |
} |
| 154 |
|
| 155 |
|
| 156 |
void setFlag(int32_t bit, UColAttributeValue value, |
| 157 |
int32_t defaultOptions, UErrorCode &errorCode); |
| 158 |
|
| 159 |
UColAttributeValue getFlag(int32_t bit) const { |
| 160 |
return ((options & bit) != 0) ? UCOL_ON : UCOL_OFF; |
| 161 |
} |
| 162 |
|
| 163 |
void setCaseFirst(UColAttributeValue value, int32_t defaultOptions, UErrorCode &errorCode); |
| 164 |
|
| 165 |
UColAttributeValue getCaseFirst() const { |
| 166 |
int32_t option = options & CASE_FIRST_AND_UPPER_MASK; |
| 167 |
return (option == 0) ? UCOL_OFF : |
| 168 |
(option == CASE_FIRST) ? UCOL_LOWER_FIRST : UCOL_UPPER_FIRST; |
| 169 |
} |
| 170 |
|
| 171 |
void setAlternateHandling(UColAttributeValue value, |
| 172 |
int32_t defaultOptions, UErrorCode &errorCode); |
| 173 |
|
| 174 |
UColAttributeValue getAlternateHandling() const { |
| 175 |
return ((options & ALTERNATE_MASK) == 0) ? UCOL_NON_IGNORABLE : UCOL_SHIFTED; |
| 176 |
} |
| 177 |
|
| 178 |
void setMaxVariable(int32_t value, int32_t defaultOptions, UErrorCode &errorCode); |
| 179 |
|
| 180 |
MaxVariable getMaxVariable() const { |
| 181 |
return static_cast<MaxVariable>((options & MAX_VARIABLE_MASK) >> MAX_VARIABLE_SHIFT); |
| 182 |
} |
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
static inline UBool isTertiaryWithCaseBits(int32_t options) { |
| 188 |
return (options & (CASE_LEVEL | CASE_FIRST)) == CASE_FIRST; |
| 189 |
} |
| 190 |
static uint32_t getTertiaryMask(int32_t options) { |
| 191 |
|
| 192 |
return isTertiaryWithCaseBits(options) ? |
| 193 |
Collation::CASE_AND_TERTIARY_MASK : Collation::ONLY_TERTIARY_MASK; |
| 194 |
} |
| 195 |
|
| 196 |
static UBool sortsTertiaryUpperCaseFirst(int32_t options) { |
| 197 |
|
| 198 |
|
| 199 |
return (options & (CASE_LEVEL | CASE_FIRST_AND_UPPER_MASK)) == CASE_FIRST_AND_UPPER_MASK; |
| 200 |
} |
| 201 |
|
| 202 |
inline UBool dontCheckFCD() const { |
| 203 |
return (options & CHECK_FCD) == 0; |
| 204 |
} |
| 205 |
|
| 206 |
inline UBool hasBackwardSecondary() const { |
| 207 |
return (options & BACKWARD_SECONDARY) != 0; |
| 208 |
} |
| 209 |
|
| 210 |
inline UBool isNumeric() const { |
| 211 |
return (options & NUMERIC) != 0; |
| 212 |
} |
| 213 |
|
| 214 |
|
| 215 |
int32_t options; |
| 216 |
|
| 217 |
uint32_t variableTop; |
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
const uint8_t *reorderTable; |
| 225 |
|
| 226 |
uint32_t minHighNoReorder; |
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
const uint32_t *reorderRanges; |
| 247 |
int32_t reorderRangesLength; |
| 248 |
|
| 249 |
const int32_t *reorderCodes; |
| 250 |
|
| 251 |
int32_t reorderCodesLength; |
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
int32_t reorderCodesCapacity; |
| 259 |
|
| 260 |
|
| 261 |
int32_t fastLatinOptions; |
| 262 |
uint16_t fastLatinPrimaries[0x180]; |
| 263 |
|
| 264 |
private: |
| 265 |
void setReorderArrays(const int32_t *codes, int32_t codesLength, |
| 266 |
const uint32_t *ranges, int32_t rangesLength, |
| 267 |
const uint8_t *table, UErrorCode &errorCode); |
| 268 |
uint32_t reorderEx(uint32_t p) const; |
| 269 |
}; |
| 270 |
|
| 271 |
U_NAMESPACE_END |
| 272 |
|
| 273 |
#endif |
| 274 |
#endif |