| 1 |
. |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
#ifndef __LOCALEPRIORITYLIST_H__ |
| 8 |
#define __LOCALEPRIORITYLIST_H__ |
| 9 |
|
| 10 |
#include "unicode/utypes.h" |
| 11 |
#include "unicode/locid.h" |
| 12 |
#include "unicode/stringpiece.h" |
| 13 |
#include "unicode/uobject.h" |
| 14 |
|
| 15 |
struct UHashtable; |
| 16 |
|
| 17 |
U_NAMESPACE_BEGIN |
| 18 |
|
| 19 |
struct LocaleAndWeightArray; |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
class U_COMMON_API LocalePriorityList : public UMemory { |
| 58 |
public: |
| 59 |
class Iterator : public Locale::Iterator { |
| 60 |
public: |
| 61 |
UBool hasNext() const override { return count < length; } |
| 62 |
|
| 63 |
const Locale &next() override { |
| 64 |
for(;;) { |
| 65 |
const Locale *locale = list.localeAt(index++); |
| 66 |
if (locale != nullptr) { |
| 67 |
++count; |
| 68 |
return *locale; |
| 69 |
} |
| 70 |
} |
| 71 |
} |
| 72 |
|
| 73 |
private: |
| 74 |
friend class LocalePriorityList; |
| 75 |
|
| 76 |
Iterator(const LocalePriorityList &list) : list(list), length(list.getLength()) {} |
| 77 |
|
| 78 |
const LocalePriorityList &list; |
| 79 |
int32_t index = 0; |
| 80 |
int32_t count = 0; |
| 81 |
const int32_t length; |
| 82 |
}; |
| 83 |
|
| 84 |
LocalePriorityList(StringPiece s, UErrorCode &errorCode); |
| 85 |
|
| 86 |
~LocalePriorityList(); |
| 87 |
|
| 88 |
int32_t getLength() const { return listLength - numRemoved; } |
| 89 |
|
| 90 |
int32_t getLengthIncludingRemoved() const { return listLength; } |
| 91 |
|
| 92 |
Iterator iterator() const { return Iterator(*this); } |
| 93 |
|
| 94 |
const Locale *localeAt(int32_t i) const; |
| 95 |
|
| 96 |
Locale *orphanLocaleAt(int32_t i); |
| 97 |
|
| 98 |
private: |
| 99 |
LocalePriorityList(const LocalePriorityList &) = delete; |
| 100 |
LocalePriorityList &operator=(const LocalePriorityList &) = delete; |
| 101 |
|
| 102 |
bool add(const Locale &locale, int32_t weight, UErrorCode &errorCode); |
| 103 |
|
| 104 |
void sort(UErrorCode &errorCode); |
| 105 |
|
| 106 |
LocaleAndWeightArray *list = nullptr; |
| 107 |
int32_t listLength = 0; |
| 108 |
int32_t numRemoved = 0; |
| 109 |
bool hasWeights = false; |
| 110 |
UHashtable *map = nullptr; |
| 111 |
}; |
| 112 |
|
| 113 |
U_NAMESPACE_END |
| 114 |
|
| 115 |
#endif |