| 1 |
. |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
#ifndef __COLLATIONKEYS_H__ |
| 15 |
#define __COLLATIONKEYS_H__ |
| 16 |
|
| 17 |
#include "unicode/utypes.h" |
| 18 |
|
| 19 |
#if !UCONFIG_NO_COLLATION |
| 20 |
|
| 21 |
#include "unicode/bytestream.h" |
| 22 |
#include "unicode/ucol.h" |
| 23 |
#include "charstr.h" |
| 24 |
#include "collation.h" |
| 25 |
|
| 26 |
U_NAMESPACE_BEGIN |
| 27 |
|
| 28 |
class CollationIterator; |
| 29 |
struct CollationDataReader; |
| 30 |
struct CollationSettings; |
| 31 |
|
| 32 |
class SortKeyByteSink : public ByteSink { |
| 33 |
public: |
| 34 |
SortKeyByteSink(char *dest, int32_t destCapacity) |
| 35 |
: buffer_(dest), capacity_(destCapacity), |
| 36 |
appended_(0), ignore_(0) {} |
| 37 |
virtual ~SortKeyByteSink(); |
| 38 |
|
| 39 |
void IgnoreBytes(int32_t numIgnore) { ignore_ = numIgnore; } |
| 40 |
|
| 41 |
virtual void Append(const char *bytes, int32_t n) override; |
| 42 |
void Append(uint32_t b) { |
| 43 |
if (ignore_ > 0) { |
| 44 |
--ignore_; |
| 45 |
} else { |
| 46 |
if (appended_ < capacity_ || Resize(1, appended_)) { |
| 47 |
buffer_[appended_] = static_cast<char>(b); |
| 48 |
} |
| 49 |
++appended_; |
| 50 |
} |
| 51 |
} |
| 52 |
virtual char *GetAppendBuffer(int32_t min_capacity, |
| 53 |
int32_t desired_capacity_hint, |
| 54 |
char *scratch, int32_t scratch_capacity, |
| 55 |
int32_t *result_capacity) override; |
| 56 |
int32_t NumberOfBytesAppended() const { return appended_; } |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
int32_t GetRemainingCapacity() const { |
| 63 |
|
| 64 |
return ignore_ + capacity_ - appended_; |
| 65 |
} |
| 66 |
|
| 67 |
UBool Overflowed() const { return appended_ > capacity_; } |
| 68 |
|
| 69 |
UBool IsOk() const { return buffer_ != nullptr; } |
| 70 |
|
| 71 |
protected: |
| 72 |
virtual void AppendBeyondCapacity(const char *bytes, int32_t n, int32_t length) = 0; |
| 73 |
virtual UBool Resize(int32_t appendCapacity, int32_t length) = 0; |
| 74 |
|
| 75 |
void SetNotOk() { |
| 76 |
buffer_ = nullptr; |
| 77 |
capacity_ = 0; |
| 78 |
} |
| 79 |
|
| 80 |
char *buffer_; |
| 81 |
int32_t capacity_; |
| 82 |
int32_t appended_; |
| 83 |
int32_t ignore_; |
| 84 |
|
| 85 |
private: |
| 86 |
SortKeyByteSink(const SortKeyByteSink &); |
| 87 |
SortKeyByteSink &operator=(const SortKeyByteSink &); |
| 88 |
}; |
| 89 |
|
| 90 |
class U_I18N_API CollationKeys { |
| 91 |
public: |
| 92 |
class LevelCallback : public UMemory { |
| 93 |
public: |
| 94 |
virtual ~LevelCallback(); |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
virtual UBool needToWrite(Collation::Level level); |
| 101 |
}; |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
static void writeSortKeyUpToQuaternary(CollationIterator &iter, |
| 111 |
const UBool *compressibleBytes, |
| 112 |
const CollationSettings &settings, |
| 113 |
SortKeyByteSink &sink, |
| 114 |
Collation::Level minLevel, LevelCallback &callback, |
| 115 |
UBool preflight, UErrorCode &errorCode); |
| 116 |
private: |
| 117 |
friend struct CollationDataReader; |
| 118 |
|
| 119 |
CollationKeys() = delete; |
| 120 |
|
| 121 |
|
| 122 |
static const uint32_t SEC_COMMON_LOW = Collation::COMMON_BYTE; |
| 123 |
static const uint32_t SEC_COMMON_MIDDLE = SEC_COMMON_LOW + 0x20; |
| 124 |
static const uint32_t SEC_COMMON_HIGH = SEC_COMMON_LOW + 0x40; |
| 125 |
static const int32_t SEC_COMMON_MAX_COUNT = 0x21; |
| 126 |
|
| 127 |
|
| 128 |
static const uint32_t CASE_LOWER_FIRST_COMMON_LOW = 1; |
| 129 |
static const uint32_t CASE_LOWER_FIRST_COMMON_MIDDLE = 7; |
| 130 |
static const uint32_t CASE_LOWER_FIRST_COMMON_HIGH = 13; |
| 131 |
static const int32_t CASE_LOWER_FIRST_COMMON_MAX_COUNT = 7; |
| 132 |
|
| 133 |
|
| 134 |
static const uint32_t CASE_UPPER_FIRST_COMMON_LOW = 3; |
| 135 |
static const uint32_t CASE_UPPER_FIRST_COMMON_HIGH = 15; |
| 136 |
static const int32_t CASE_UPPER_FIRST_COMMON_MAX_COUNT = 13; |
| 137 |
|
| 138 |
|
| 139 |
static const uint32_t TER_ONLY_COMMON_LOW = Collation::COMMON_BYTE; |
| 140 |
static const uint32_t TER_ONLY_COMMON_MIDDLE = TER_ONLY_COMMON_LOW + 0x60; |
| 141 |
static const uint32_t TER_ONLY_COMMON_HIGH = TER_ONLY_COMMON_LOW + 0xc0; |
| 142 |
static const int32_t TER_ONLY_COMMON_MAX_COUNT = 0x61; |
| 143 |
|
| 144 |
|
| 145 |
static const uint32_t TER_LOWER_FIRST_COMMON_LOW = Collation::COMMON_BYTE; |
| 146 |
static const uint32_t TER_LOWER_FIRST_COMMON_MIDDLE = TER_LOWER_FIRST_COMMON_LOW + 0x20; |
| 147 |
static const uint32_t TER_LOWER_FIRST_COMMON_HIGH = TER_LOWER_FIRST_COMMON_LOW + 0x40; |
| 148 |
static const int32_t TER_LOWER_FIRST_COMMON_MAX_COUNT = 0x21; |
| 149 |
|
| 150 |
|
| 151 |
static const uint32_t TER_UPPER_FIRST_COMMON_LOW = Collation::COMMON_BYTE + 0x80; |
| 152 |
static const uint32_t TER_UPPER_FIRST_COMMON_MIDDLE = TER_UPPER_FIRST_COMMON_LOW + 0x20; |
| 153 |
static const uint32_t TER_UPPER_FIRST_COMMON_HIGH = TER_UPPER_FIRST_COMMON_LOW + 0x40; |
| 154 |
static const int32_t TER_UPPER_FIRST_COMMON_MAX_COUNT = 0x21; |
| 155 |
|
| 156 |
|
| 157 |
static const uint32_t QUAT_COMMON_LOW = 0x1c; |
| 158 |
static const uint32_t QUAT_COMMON_MIDDLE = QUAT_COMMON_LOW + 0x70; |
| 159 |
static const uint32_t QUAT_COMMON_HIGH = QUAT_COMMON_LOW + 0xE0; |
| 160 |
static const int32_t QUAT_COMMON_MAX_COUNT = 0x71; |
| 161 |
|
| 162 |
|
| 163 |
static const uint32_t QUAT_SHIFTED_LIMIT_BYTE = QUAT_COMMON_LOW - 1; |
| 164 |
}; |
| 165 |
|
| 166 |
U_NAMESPACE_END |
| 167 |
|
| 168 |
#endif |
| 169 |
#endif |