mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-04 13:05:31 +00:00
ICU-22531 Remove X from XLikelySubtags*
This commit is contained in:
parent
102ed8b6bd
commit
8d3d214ad7
18 changed files with 87 additions and 89 deletions
|
@ -302,7 +302,7 @@ LocaleMatcher LocaleMatcher::Builder::build(UErrorCode &errorCode) const {
|
|||
|
||||
namespace {
|
||||
|
||||
LSR getMaximalLsrOrUnd(const XLikelySubtags &likelySubtags, const Locale &locale,
|
||||
LSR getMaximalLsrOrUnd(const LikelySubtags &likelySubtags, const Locale &locale,
|
||||
UErrorCode &errorCode) {
|
||||
if (U_FAILURE(errorCode) || locale.isBogus() || *locale.getName() == 0 /* "und" */) {
|
||||
return UND_LSR;
|
||||
|
@ -338,7 +338,7 @@ int32_t LocaleMatcher::putIfAbsent(const LSR &lsr, int32_t i, int32_t suppLength
|
|||
}
|
||||
|
||||
LocaleMatcher::LocaleMatcher(const Builder &builder, UErrorCode &errorCode) :
|
||||
likelySubtags(*XLikelySubtags::getSingleton(errorCode)),
|
||||
likelySubtags(*LikelySubtags::getSingleton(errorCode)),
|
||||
localeDistance(*LocaleDistance::getSingleton(errorCode)),
|
||||
thresholdDistance(builder.thresholdDistance_),
|
||||
demotionPerDesiredLocale(0),
|
||||
|
@ -551,7 +551,7 @@ LocaleMatcher &LocaleMatcher::operator=(LocaleMatcher &&src) noexcept {
|
|||
|
||||
class LocaleLsrIterator {
|
||||
public:
|
||||
LocaleLsrIterator(const XLikelySubtags &likelySubtags, Locale::Iterator &locales,
|
||||
LocaleLsrIterator(const LikelySubtags &likelySubtags, Locale::Iterator &locales,
|
||||
ULocMatchLifetime lifetime) :
|
||||
likelySubtags(likelySubtags), locales(locales), lifetime(lifetime) {}
|
||||
|
||||
|
@ -596,7 +596,7 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
const XLikelySubtags &likelySubtags;
|
||||
const LikelySubtags &likelySubtags;
|
||||
Locale::Iterator &locales;
|
||||
ULocMatchLifetime lifetime;
|
||||
const Locale *current = nullptr, *remembered = nullptr;
|
||||
|
|
|
@ -59,7 +59,7 @@ UBool U_CALLCONV cleanup() {
|
|||
void U_CALLCONV LocaleDistance::initLocaleDistance(UErrorCode &errorCode) {
|
||||
// This function is invoked only via umtx_initOnce().
|
||||
U_ASSERT(gLocaleDistance == nullptr);
|
||||
const XLikelySubtags &likely = *XLikelySubtags::getSingleton(errorCode);
|
||||
const LikelySubtags &likely = *LikelySubtags::getSingleton(errorCode);
|
||||
if (U_FAILURE(errorCode)) { return; }
|
||||
const LocaleDistanceData &data = likely.getDistanceData();
|
||||
if (data.distanceTrieBytes == nullptr ||
|
||||
|
@ -83,7 +83,7 @@ const LocaleDistance *LocaleDistance::getSingleton(UErrorCode &errorCode) {
|
|||
return gLocaleDistance;
|
||||
}
|
||||
|
||||
LocaleDistance::LocaleDistance(const LocaleDistanceData &data, const XLikelySubtags &likely) :
|
||||
LocaleDistance::LocaleDistance(const LocaleDistanceData &data, const LikelySubtags &likely) :
|
||||
likelySubtags(likely),
|
||||
trie(data.distanceTrieBytes),
|
||||
regionToPartitionsIndex(data.regionToPartitions), partitionArrays(data.partitions),
|
||||
|
@ -119,7 +119,7 @@ int32_t LocaleDistance::getBestIndexAndDistance(
|
|||
uint64_t desLangState = desLangDistance >= 0 && supportedLSRsLength > 1 ? iter.getState64() : 0;
|
||||
// Index of the supported LSR with the lowest distance.
|
||||
int32_t bestIndex = -1;
|
||||
// Cached lookup info from XLikelySubtags.compareLikely().
|
||||
// Cached lookup info from LikelySubtags.compareLikely().
|
||||
int32_t bestLikelyInfo = -1;
|
||||
for (int32_t slIndex = 0; slIndex < supportedLSRsLength; ++slIndex) {
|
||||
const LSR &supported = *supportedLSRs[slIndex];
|
||||
|
|
|
@ -83,7 +83,7 @@ private:
|
|||
// tic constexpr int32_t MAX_INDEX = 0x1fffff; // avoids sign bit
|
||||
static constexpr int32_t INDEX_NEG_1 = 0xfffffc00;
|
||||
|
||||
LocaleDistance(const LocaleDistanceData &data, const XLikelySubtags &likely);
|
||||
LocaleDistance(const LocaleDistanceData &data, const LikelySubtags &likely);
|
||||
LocaleDistance(const LocaleDistance &other) = delete;
|
||||
LocaleDistance &operator=(const LocaleDistance &other) = delete;
|
||||
|
||||
|
@ -119,7 +119,7 @@ private:
|
|||
return defaultRegionDistance;
|
||||
}
|
||||
|
||||
const XLikelySubtags &likelySubtags;
|
||||
const LikelySubtags &likelySubtags;
|
||||
|
||||
// The trie maps each dlang+slang+dscript+sscript+dregion+sregion
|
||||
// (encoded in ASCII with bit 7 set on the last character of each subtag) to a distance.
|
||||
|
|
|
@ -486,7 +486,7 @@ _uloc_addLikelySubtags(const char* localeID,
|
|||
|
||||
CHECK_TRAILING_VARIANT_SIZE(trailing, trailingLength);
|
||||
{
|
||||
const icu::XLikelySubtags* likelySubtags = icu::XLikelySubtags::getSingleton(*err);
|
||||
const icu::LikelySubtags* likelySubtags = icu::LikelySubtags::getSingleton(*err);
|
||||
if(U_FAILURE(*err)) {
|
||||
goto error;
|
||||
}
|
||||
|
@ -590,7 +590,7 @@ _uloc_minimizeSubtags(const char* localeID,
|
|||
CHECK_TRAILING_VARIANT_SIZE(trailing, trailingLength);
|
||||
|
||||
{
|
||||
const icu::XLikelySubtags* likelySubtags = icu::XLikelySubtags::getSingleton(*err);
|
||||
const icu::LikelySubtags* likelySubtags = icu::LikelySubtags::getSingleton(*err);
|
||||
if(U_FAILURE(*err)) {
|
||||
goto error;
|
||||
}
|
||||
|
|
|
@ -51,8 +51,7 @@ LocaleDistanceData::~LocaleDistanceData() {
|
|||
delete[] paradigms;
|
||||
}
|
||||
|
||||
// TODO(ICU-20777): Rename to just LikelySubtagsData.
|
||||
struct XLikelySubtagsData {
|
||||
struct LikelySubtagsData {
|
||||
UResourceBundle *langInfoBundle = nullptr;
|
||||
UniqueCharStrings strings;
|
||||
CharStringMap languageAliases;
|
||||
|
@ -63,9 +62,9 @@ struct XLikelySubtagsData {
|
|||
|
||||
LocaleDistanceData distanceData;
|
||||
|
||||
XLikelySubtagsData(UErrorCode &errorCode) : strings(errorCode) {}
|
||||
LikelySubtagsData(UErrorCode &errorCode) : strings(errorCode) {}
|
||||
|
||||
~XLikelySubtagsData() {
|
||||
~LikelySubtagsData() {
|
||||
ures_close(langInfoBundle);
|
||||
delete[] lsrs;
|
||||
}
|
||||
|
@ -339,7 +338,7 @@ private:
|
|||
|
||||
namespace {
|
||||
|
||||
XLikelySubtags *gLikelySubtags = nullptr;
|
||||
LikelySubtags *gLikelySubtags = nullptr;
|
||||
UVector *gMacroregions = nullptr;
|
||||
UInitOnce gInitOnce {};
|
||||
|
||||
|
@ -443,13 +442,13 @@ UVector* getStaticMacroregions(UErrorCode &status) {
|
|||
|
||||
} // namespace
|
||||
|
||||
void U_CALLCONV XLikelySubtags::initLikelySubtags(UErrorCode &errorCode) {
|
||||
void U_CALLCONV LikelySubtags::initLikelySubtags(UErrorCode &errorCode) {
|
||||
// This function is invoked only via umtx_initOnce().
|
||||
U_ASSERT(gLikelySubtags == nullptr);
|
||||
XLikelySubtagsData data(errorCode);
|
||||
LikelySubtagsData data(errorCode);
|
||||
data.load(errorCode);
|
||||
if (U_FAILURE(errorCode)) { return; }
|
||||
gLikelySubtags = new XLikelySubtags(data);
|
||||
gLikelySubtags = new LikelySubtags(data);
|
||||
gMacroregions = getStaticMacroregions(errorCode);
|
||||
#if U_DEBUG
|
||||
auto macroregionsFromData = loadMacroregions(errorCode);
|
||||
|
@ -466,13 +465,13 @@ void U_CALLCONV XLikelySubtags::initLikelySubtags(UErrorCode &errorCode) {
|
|||
ucln_common_registerCleanup(UCLN_COMMON_LIKELY_SUBTAGS, cleanup);
|
||||
}
|
||||
|
||||
const XLikelySubtags *XLikelySubtags::getSingleton(UErrorCode &errorCode) {
|
||||
const LikelySubtags *LikelySubtags::getSingleton(UErrorCode &errorCode) {
|
||||
if (U_FAILURE(errorCode)) { return nullptr; }
|
||||
umtx_initOnce(gInitOnce, &XLikelySubtags::initLikelySubtags, errorCode);
|
||||
umtx_initOnce(gInitOnce, &LikelySubtags::initLikelySubtags, errorCode);
|
||||
return gLikelySubtags;
|
||||
}
|
||||
|
||||
XLikelySubtags::XLikelySubtags(XLikelySubtagsData &data) :
|
||||
LikelySubtags::LikelySubtags(LikelySubtagsData &data) :
|
||||
langInfoBundle(data.langInfoBundle),
|
||||
strings(data.strings.orphanCharStrings()),
|
||||
languageAliases(std::move(data.languageAliases)),
|
||||
|
@ -507,13 +506,13 @@ XLikelySubtags::XLikelySubtags(XLikelySubtagsData &data) :
|
|||
}
|
||||
}
|
||||
|
||||
XLikelySubtags::~XLikelySubtags() {
|
||||
LikelySubtags::~LikelySubtags() {
|
||||
ures_close(langInfoBundle);
|
||||
delete strings;
|
||||
delete[] lsrs;
|
||||
}
|
||||
|
||||
LSR XLikelySubtags::makeMaximizedLsrFrom(const Locale &locale,
|
||||
LSR LikelySubtags::makeMaximizedLsrFrom(const Locale &locale,
|
||||
bool returnInputIfUnmatch,
|
||||
UErrorCode &errorCode) const {
|
||||
if (locale.isBogus()) {
|
||||
|
@ -550,7 +549,7 @@ const char *getCanonical(const CharStringMap &aliases, const char *alias) {
|
|||
|
||||
} // namespace
|
||||
|
||||
LSR XLikelySubtags::makeMaximizedLsr(const char *language, const char *script, const char *region,
|
||||
LSR LikelySubtags::makeMaximizedLsr(const char *language, const char *script, const char *region,
|
||||
const char *variant,
|
||||
bool returnInputIfUnmatch,
|
||||
UErrorCode &errorCode) const {
|
||||
|
@ -605,7 +604,7 @@ LSR XLikelySubtags::makeMaximizedLsr(const char *language, const char *script, c
|
|||
return maximize(language, script, region, returnInputIfUnmatch, errorCode);
|
||||
}
|
||||
|
||||
LSR XLikelySubtags::maximize(const char *language, const char *script, const char *region,
|
||||
LSR LikelySubtags::maximize(const char *language, const char *script, const char *region,
|
||||
bool returnInputIfUnmatch,
|
||||
UErrorCode &errorCode) const {
|
||||
return maximize({language, (int32_t)uprv_strlen(language)},
|
||||
|
@ -615,18 +614,18 @@ LSR XLikelySubtags::maximize(const char *language, const char *script, const cha
|
|||
errorCode);
|
||||
}
|
||||
|
||||
bool XLikelySubtags::isMacroregion(StringPiece& region, UErrorCode& errorCode) const {
|
||||
bool LikelySubtags::isMacroregion(StringPiece& region, UErrorCode& errorCode) const {
|
||||
// In Java, we use Region class. In C++, since Region is under i18n,
|
||||
// we read the same data used by Region into gMacroregions avoid dependency
|
||||
// from common to i18n/region.cpp
|
||||
if (U_FAILURE(errorCode)) { return false; }
|
||||
umtx_initOnce(gInitOnce, &XLikelySubtags::initLikelySubtags, errorCode);
|
||||
umtx_initOnce(gInitOnce, &LikelySubtags::initLikelySubtags, errorCode);
|
||||
if (U_FAILURE(errorCode)) { return false; }
|
||||
UnicodeString str(UnicodeString::fromUTF8(region));
|
||||
return gMacroregions->contains((void *)&str);
|
||||
}
|
||||
|
||||
LSR XLikelySubtags::maximize(StringPiece language, StringPiece script, StringPiece region,
|
||||
LSR LikelySubtags::maximize(StringPiece language, StringPiece script, StringPiece region,
|
||||
bool returnInputIfUnmatch,
|
||||
UErrorCode &errorCode) const {
|
||||
if (U_FAILURE(errorCode)) {
|
||||
|
@ -750,7 +749,7 @@ LSR XLikelySubtags::maximize(StringPiece language, StringPiece script, StringPie
|
|||
return LSR(language, script, region, retainMask, errorCode);
|
||||
}
|
||||
|
||||
int32_t XLikelySubtags::compareLikely(const LSR &lsr, const LSR &other, int32_t likelyInfo) const {
|
||||
int32_t LikelySubtags::compareLikely(const LSR &lsr, const LSR &other, int32_t likelyInfo) const {
|
||||
// If likelyInfo >= 0:
|
||||
// likelyInfo bit 1 is set if the previous comparison with lsr
|
||||
// was for equal language and script.
|
||||
|
@ -792,7 +791,7 @@ int32_t XLikelySubtags::compareLikely(const LSR &lsr, const LSR &other, int32_t
|
|||
}
|
||||
|
||||
// Subset of maximize().
|
||||
int32_t XLikelySubtags::getLikelyIndex(const char *language, const char *script) const {
|
||||
int32_t LikelySubtags::getLikelyIndex(const char *language, const char *script) const {
|
||||
if (uprv_strcmp(language, "und") == 0) {
|
||||
language = "";
|
||||
}
|
||||
|
@ -850,7 +849,7 @@ int32_t XLikelySubtags::getLikelyIndex(const char *language, const char *script)
|
|||
return value;
|
||||
}
|
||||
|
||||
int32_t XLikelySubtags::trieNext(BytesTrie &iter, const char *s, int32_t i) {
|
||||
int32_t LikelySubtags::trieNext(BytesTrie &iter, const char *s, int32_t i) {
|
||||
UStringTrieResult result;
|
||||
uint8_t c;
|
||||
if ((c = s[i]) == 0) {
|
||||
|
@ -883,7 +882,7 @@ int32_t XLikelySubtags::trieNext(BytesTrie &iter, const char *s, int32_t i) {
|
|||
default: return -1;
|
||||
}
|
||||
}
|
||||
int32_t XLikelySubtags::trieNext(BytesTrie &iter, StringPiece s, int32_t i) {
|
||||
int32_t LikelySubtags::trieNext(BytesTrie &iter, StringPiece s, int32_t i) {
|
||||
UStringTrieResult result;
|
||||
uint8_t c;
|
||||
if (s.length() == i) {
|
||||
|
@ -917,7 +916,7 @@ int32_t XLikelySubtags::trieNext(BytesTrie &iter, StringPiece s, int32_t i) {
|
|||
}
|
||||
}
|
||||
|
||||
LSR XLikelySubtags::minimizeSubtags(StringPiece language, StringPiece script,
|
||||
LSR LikelySubtags::minimizeSubtags(StringPiece language, StringPiece script,
|
||||
StringPiece region,
|
||||
bool favorScript,
|
||||
UErrorCode &errorCode) const {
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
struct XLikelySubtagsData;
|
||||
struct LikelySubtagsData;
|
||||
|
||||
struct LocaleDistanceData {
|
||||
LocaleDistanceData() = default;
|
||||
|
@ -37,15 +37,14 @@ private:
|
|||
LocaleDistanceData &operator=(const LocaleDistanceData &) = delete;
|
||||
};
|
||||
|
||||
// TODO(ICU-20777): Rename to just LikelySubtags.
|
||||
class XLikelySubtags final : public UMemory {
|
||||
class LikelySubtags final : public UMemory {
|
||||
public:
|
||||
~XLikelySubtags();
|
||||
~LikelySubtags();
|
||||
|
||||
static constexpr int32_t SKIP_SCRIPT = 1;
|
||||
|
||||
// VisibleForTesting
|
||||
static const XLikelySubtags *getSingleton(UErrorCode &errorCode);
|
||||
static const LikelySubtags *getSingleton(UErrorCode &errorCode);
|
||||
|
||||
// VisibleForTesting
|
||||
LSR makeMaximizedLsrFrom(const Locale &locale,
|
||||
|
@ -72,9 +71,9 @@ public:
|
|||
const LocaleDistanceData &getDistanceData() const { return distanceData; }
|
||||
|
||||
private:
|
||||
XLikelySubtags(XLikelySubtagsData &data);
|
||||
XLikelySubtags(const XLikelySubtags &other) = delete;
|
||||
XLikelySubtags &operator=(const XLikelySubtags &other) = delete;
|
||||
LikelySubtags(LikelySubtagsData &data);
|
||||
LikelySubtags(const LikelySubtags &other) = delete;
|
||||
LikelySubtags &operator=(const LikelySubtags &other) = delete;
|
||||
|
||||
static void initLikelySubtags(UErrorCode &errorCode);
|
||||
|
||||
|
@ -120,7 +119,7 @@ private:
|
|||
int32_t lsrsLength;
|
||||
#endif
|
||||
|
||||
// distance/matcher data: see comment in XLikelySubtagsData::load()
|
||||
// distance/matcher data: see comment in LikelySubtagsData::load()
|
||||
LocaleDistanceData distanceData;
|
||||
};
|
||||
|
||||
|
|
|
@ -133,10 +133,10 @@ U_NAMESPACE_BEGIN
|
|||
|
||||
struct LSR;
|
||||
|
||||
class LikelySubtags;
|
||||
class LocaleDistance;
|
||||
class LocaleLsrIterator;
|
||||
class UVector;
|
||||
class XLikelySubtags;
|
||||
|
||||
/**
|
||||
* Immutable class that picks the best match between a user's desired locales and
|
||||
|
@ -680,7 +680,7 @@ private:
|
|||
|
||||
int32_t getBestSuppIndex(LSR desiredLSR, LocaleLsrIterator *remainingIter, UErrorCode &errorCode) const;
|
||||
|
||||
const XLikelySubtags &likelySubtags;
|
||||
const LikelySubtags &likelySubtags;
|
||||
const LocaleDistance &localeDistance;
|
||||
int32_t thresholdDistance;
|
||||
int32_t demotionPerDesiredLocale;
|
||||
|
|
|
@ -273,6 +273,17 @@ com/ibm/icu/impl/locale/LanguageTag#canonicalizeExtensionSubtag:(Ljava/lang/Stri
|
|||
com/ibm/icu/impl/locale/LanguageTag#canonicalizeExtlang:(Ljava/lang/String;)Ljava/lang/String;
|
||||
com/ibm/icu/impl/locale/LanguageTag#canonicalizePrivateuseSubtag:(Ljava/lang/String;)Ljava/lang/String;
|
||||
com/ibm/icu/impl/locale/LanguageTag#toString:()Ljava/lang/String;
|
||||
com/ibm/icu/impl/locale/LikelySubtags#getDefault:()Lcom/ibm/icu/impl/locale/LikelySubtags;
|
||||
com/ibm/icu/impl/locale/LikelySubtags#maximize:(Lcom/ibm/icu/impl/locale/LikelySubtags$LSR;)Lcom/ibm/icu/impl/locale/LikelySubtags$LSR;
|
||||
com/ibm/icu/impl/locale/LikelySubtags#maximize:(Lcom/ibm/icu/util/ULocale;)Lcom/ibm/icu/impl/locale/LikelySubtags$LSR;
|
||||
com/ibm/icu/impl/locale/LikelySubtags#maximize:(Ljava/lang/String;)Lcom/ibm/icu/impl/locale/LikelySubtags$LSR;
|
||||
com/ibm/icu/impl/locale/LikelySubtags#minimizeSubtags:(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lcom/ibm/icu/util/ULocale$Minimize;)Lcom/ibm/icu/impl/locale/LikelySubtags$LSR;
|
||||
com/ibm/icu/impl/locale/LikelySubtags#show:(Ljava/util/Map;Ljava/lang/String;Ljava/lang/StringBuilder;)Ljava/lang/StringBuilder;
|
||||
com/ibm/icu/impl/locale/LikelySubtags#toString:()Ljava/lang/String;
|
||||
com/ibm/icu/impl/locale/LikelySubtags$LSR#from:(Lcom/ibm/icu/util/ULocale;)Lcom/ibm/icu/impl/locale/LikelySubtags$LSR;
|
||||
com/ibm/icu/impl/locale/LikelySubtags$LSR#from:(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Lcom/ibm/icu/impl/locale/LikelySubtags$LSR;
|
||||
com/ibm/icu/impl/locale/LikelySubtags$LSR#toString:()Ljava/lang/String;
|
||||
com/ibm/icu/impl/locale/LikelySubtags$Maker$1#make:()Ljava/util/Map;
|
||||
com/ibm/icu/impl/locale/LocaleExtensions#equals:(Ljava/lang/Object;)Z
|
||||
com/ibm/icu/impl/locale/LocaleExtensions#getID:()Ljava/lang/String;
|
||||
com/ibm/icu/impl/locale/LocaleExtensions#hashCode:()I
|
||||
|
@ -307,17 +318,6 @@ com/ibm/icu/impl/locale/XCldrStub$RegexUtilities#<init>:()V
|
|||
com/ibm/icu/impl/locale/XCldrStub$RegexUtilities#findMismatch:(Ljava/util/regex/Matcher;Ljava/lang/CharSequence;)I
|
||||
com/ibm/icu/impl/locale/XCldrStub$RegexUtilities#showMismatch:(Ljava/util/regex/Matcher;Ljava/lang/CharSequence;)Ljava/lang/String;
|
||||
com/ibm/icu/impl/locale/XCldrStub$ReusableEntry#setValue:(Ljava/lang/Object;)Ljava/lang/Object;
|
||||
com/ibm/icu/impl/locale/XLikelySubtags#getDefault:()Lcom/ibm/icu/impl/locale/XLikelySubtags;
|
||||
com/ibm/icu/impl/locale/XLikelySubtags#maximize:(Lcom/ibm/icu/impl/locale/XLikelySubtags$LSR;)Lcom/ibm/icu/impl/locale/XLikelySubtags$LSR;
|
||||
com/ibm/icu/impl/locale/XLikelySubtags#maximize:(Lcom/ibm/icu/util/ULocale;)Lcom/ibm/icu/impl/locale/XLikelySubtags$LSR;
|
||||
com/ibm/icu/impl/locale/XLikelySubtags#maximize:(Ljava/lang/String;)Lcom/ibm/icu/impl/locale/XLikelySubtags$LSR;
|
||||
com/ibm/icu/impl/locale/XLikelySubtags#minimizeSubtags:(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lcom/ibm/icu/util/ULocale$Minimize;)Lcom/ibm/icu/impl/locale/XLikelySubtags$LSR;
|
||||
com/ibm/icu/impl/locale/XLikelySubtags#show:(Ljava/util/Map;Ljava/lang/String;Ljava/lang/StringBuilder;)Ljava/lang/StringBuilder;
|
||||
com/ibm/icu/impl/locale/XLikelySubtags#toString:()Ljava/lang/String;
|
||||
com/ibm/icu/impl/locale/XLikelySubtags$LSR#from:(Lcom/ibm/icu/util/ULocale;)Lcom/ibm/icu/impl/locale/XLikelySubtags$LSR;
|
||||
com/ibm/icu/impl/locale/XLikelySubtags$LSR#from:(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Lcom/ibm/icu/impl/locale/XLikelySubtags$LSR;
|
||||
com/ibm/icu/impl/locale/XLikelySubtags$LSR#toString:()Ljava/lang/String;
|
||||
com/ibm/icu/impl/locale/XLikelySubtags$Maker$1#make:()Ljava/util/Map;
|
||||
com/ibm/icu/impl/locale/XLocaleDistance#fixedName:(Ljava/util/List;)Ljava/lang/String;
|
||||
com/ibm/icu/impl/locale/XLocaleDistance#getContainingMacrosFor:(Ljava/util/Collection;Ljava/util/Set;)Ljava/util/Set;
|
||||
com/ibm/icu/impl/locale/XLocaleDistance#getDefaultLanguageDistance:()I
|
||||
|
|
|
@ -18,7 +18,7 @@ import com.ibm.icu.util.BytesTrie;
|
|||
import com.ibm.icu.util.Region;
|
||||
import com.ibm.icu.util.ULocale;
|
||||
|
||||
public final class XLikelySubtags {
|
||||
public final class LikelySubtags {
|
||||
private static final String PSEUDO_ACCENTS_PREFIX = "'"; // -XA, -PSACCENT
|
||||
private static final String PSEUDO_BIDI_PREFIX = "+"; // -XB, -PSBIDI
|
||||
private static final String PSEUDO_CRACKED_PREFIX = ","; // -XC, -PSCRACK
|
||||
|
@ -109,7 +109,7 @@ public final class XLikelySubtags {
|
|||
}
|
||||
|
||||
// VisibleForTesting
|
||||
public static final XLikelySubtags INSTANCE = new XLikelySubtags(Data.load());
|
||||
public static final LikelySubtags INSTANCE = new LikelySubtags(Data.load());
|
||||
|
||||
private final Map<String, String> languageAliases;
|
||||
private final Map<String, String> regionAliases;
|
||||
|
@ -124,7 +124,7 @@ public final class XLikelySubtags {
|
|||
private final long[] trieFirstLetterStates = new long[26];
|
||||
private final LSR[] lsrs;
|
||||
|
||||
private XLikelySubtags(XLikelySubtags.Data data) {
|
||||
private LikelySubtags(LikelySubtags.Data data) {
|
||||
languageAliases = data.languageAliases;
|
||||
regionAliases = data.regionAliases;
|
||||
trie = new BytesTrie(data.trie, 0);
|
|
@ -225,8 +225,8 @@ public class LocaleDistance {
|
|||
// VisibleForTesting
|
||||
public int testOnlyDistance(ULocale desired, ULocale supported,
|
||||
int threshold, FavorSubtag favorSubtag) {
|
||||
LSR supportedLSR = XLikelySubtags.INSTANCE.makeMaximizedLsrFrom(supported, false);
|
||||
LSR desiredLSR = XLikelySubtags.INSTANCE.makeMaximizedLsrFrom(desired, false);
|
||||
LSR supportedLSR = LikelySubtags.INSTANCE.makeMaximizedLsrFrom(supported, false);
|
||||
LSR desiredLSR = LikelySubtags.INSTANCE.makeMaximizedLsrFrom(desired, false);
|
||||
int indexAndDistance = getBestIndexAndDistance(desiredLSR, new LSR[] { supportedLSR }, 1,
|
||||
shiftDistance(threshold), favorSubtag, LocaleMatcher.Direction.WITH_ONE_WAY);
|
||||
return getDistanceFloor(indexAndDistance);
|
||||
|
@ -250,7 +250,7 @@ public class LocaleDistance {
|
|||
long desLangState = desLangDistance >= 0 && supportedLSRsLength > 1 ? iter.getState64() : 0;
|
||||
// Index of the supported LSR with the lowest distance.
|
||||
int bestIndex = -1;
|
||||
// Cached lookup info from XLikelySubtags.compareLikely().
|
||||
// Cached lookup info from LikelySubtags.compareLikely().
|
||||
int bestLikelyInfo = -1;
|
||||
for (int slIndex = 0; slIndex < supportedLSRsLength; ++slIndex) {
|
||||
LSR supported = supportedLSRs[slIndex];
|
||||
|
@ -369,7 +369,7 @@ public class LocaleDistance {
|
|||
if (direction != LocaleMatcher.Direction.ONLY_TWO_WAY ||
|
||||
// Is there also a match when we swap desired/supported?
|
||||
isMatch(supported, desired, shiftedThreshold, favorSubtag)) {
|
||||
bestLikelyInfo = XLikelySubtags.INSTANCE.compareLikely(
|
||||
bestLikelyInfo = LikelySubtags.INSTANCE.compareLikely(
|
||||
supported, supportedLSRs[bestIndex], bestLikelyInfo);
|
||||
if ((bestLikelyInfo & 1) != 0) {
|
||||
// This supported locale matches as well as the previous best match,
|
||||
|
|
|
@ -17,8 +17,8 @@ import java.util.Locale;
|
|||
import java.util.Map;
|
||||
|
||||
import com.ibm.icu.impl.locale.LSR;
|
||||
import com.ibm.icu.impl.locale.LikelySubtags;
|
||||
import com.ibm.icu.impl.locale.LocaleDistance;
|
||||
import com.ibm.icu.impl.locale.XLikelySubtags;
|
||||
|
||||
/**
|
||||
* Immutable class that picks the best match between a user's desired locales and
|
||||
|
@ -796,7 +796,7 @@ public final class LocaleMatcher {
|
|||
if (locale.equals(UND_ULOCALE)) {
|
||||
return UND_LSR;
|
||||
} else {
|
||||
return XLikelySubtags.INSTANCE.makeMaximizedLsrFrom(locale, false);
|
||||
return LikelySubtags.INSTANCE.makeMaximizedLsrFrom(locale, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -804,7 +804,7 @@ public final class LocaleMatcher {
|
|||
if (locale.equals(UND_LOCALE) || locale.equals(EMPTY_LOCALE)) {
|
||||
return UND_LSR;
|
||||
} else {
|
||||
return XLikelySubtags.INSTANCE.makeMaximizedLsrFrom(locale);
|
||||
return LikelySubtags.INSTANCE.makeMaximizedLsrFrom(locale);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1169,7 +1169,7 @@ public final class LocaleMatcher {
|
|||
* @stable ICU 4.4
|
||||
*/
|
||||
public ULocale canonicalize(ULocale locale) {
|
||||
return XLikelySubtags.INSTANCE.canonicalize(locale);
|
||||
return LikelySubtags.INSTANCE.canonicalize(locale);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -44,11 +44,11 @@ import com.ibm.icu.impl.locale.InternalLocaleBuilder;
|
|||
import com.ibm.icu.impl.locale.KeyTypeData;
|
||||
import com.ibm.icu.impl.locale.LSR;
|
||||
import com.ibm.icu.impl.locale.LanguageTag;
|
||||
import com.ibm.icu.impl.locale.LikelySubtags;
|
||||
import com.ibm.icu.impl.locale.LocaleExtensions;
|
||||
import com.ibm.icu.impl.locale.LocaleSyntaxException;
|
||||
import com.ibm.icu.impl.locale.ParseStatus;
|
||||
import com.ibm.icu.impl.locale.UnicodeLocaleExtension;
|
||||
import com.ibm.icu.impl.locale.XLikelySubtags;
|
||||
import com.ibm.icu.lang.UScript;
|
||||
import com.ibm.icu.text.LocaleDisplayNames;
|
||||
import com.ibm.icu.text.LocaleDisplayNames.DialectHandling;
|
||||
|
@ -2723,7 +2723,7 @@ public final class ULocale implements Serializable, Comparable<ULocale> {
|
|||
trailing = loc.localeID.substring(trailingIndex);
|
||||
}
|
||||
|
||||
LSR max = XLikelySubtags.INSTANCE.makeMaximizedLsrFrom(
|
||||
LSR max = LikelySubtags.INSTANCE.makeMaximizedLsrFrom(
|
||||
new ULocale(loc.getLanguage(), loc.getScript(), loc.getCountry()), true);
|
||||
String newLocaleID = createTagString(max.language, max.script, max.region,
|
||||
trailing);
|
||||
|
@ -2828,7 +2828,7 @@ public final class ULocale implements Serializable, Comparable<ULocale> {
|
|||
trailing = loc.localeID.substring(trailingIndex);
|
||||
}
|
||||
|
||||
LSR lsr = XLikelySubtags.INSTANCE.minimizeSubtags(
|
||||
LSR lsr = LikelySubtags.INSTANCE.minimizeSubtags(
|
||||
loc.getLanguage(), loc.getScript(), loc.getCountry(), fieldToFavor);
|
||||
String newLocaleID = createTagString(lsr.language, lsr.script, lsr.region,
|
||||
trailing);
|
||||
|
|
|
@ -24,8 +24,8 @@ import org.junit.Test;
|
|||
import org.junit.runner.RunWith;
|
||||
|
||||
import com.ibm.icu.dev.test.CoreTestFmwk;
|
||||
import com.ibm.icu.impl.locale.LikelySubtags;
|
||||
import com.ibm.icu.impl.locale.XCldrStub.FileUtilities;
|
||||
import com.ibm.icu.impl.locale.XLikelySubtags;
|
||||
import com.ibm.icu.util.LocaleMatcher;
|
||||
import com.ibm.icu.util.LocaleMatcher.FavorSubtag;
|
||||
import com.ibm.icu.util.LocalePriorityList;
|
||||
|
@ -868,7 +868,7 @@ public class LocaleMatcherTest extends CoreTestFmwk {
|
|||
long start = System.nanoTime();
|
||||
for (int i = iterations; i > 0; --i) {
|
||||
for (ULocale locale : list) {
|
||||
XLikelySubtags.INSTANCE.makeMaximizedLsrFrom(locale, false);
|
||||
LikelySubtags.INSTANCE.makeMaximizedLsrFrom(locale, false);
|
||||
}
|
||||
}
|
||||
return System.nanoTime() - start;
|
||||
|
|
|
@ -26,12 +26,12 @@ import com.ibm.icu.impl.ICUData;
|
|||
import com.ibm.icu.impl.ICUResourceBundle;
|
||||
import com.ibm.icu.impl.UResource;
|
||||
import com.ibm.icu.impl.locale.LSR;
|
||||
import com.ibm.icu.impl.locale.LikelySubtags;
|
||||
import com.ibm.icu.impl.locale.LocaleDistance;
|
||||
import com.ibm.icu.impl.locale.XCldrStub.Multimap;
|
||||
import com.ibm.icu.impl.locale.XCldrStub.Predicate;
|
||||
import com.ibm.icu.impl.locale.XCldrStub.Splitter;
|
||||
import com.ibm.icu.impl.locale.XCldrStub.TreeMultimap;
|
||||
import com.ibm.icu.impl.locale.XLikelySubtags;
|
||||
import com.ibm.icu.util.BytesTrieBuilder;
|
||||
import com.ibm.icu.util.Output;
|
||||
import com.ibm.icu.util.ULocale;
|
||||
|
@ -489,7 +489,7 @@ public final class LocaleDistanceBuilder {
|
|||
Set<LSR> paradigmLSRs = new LinkedHashSet<>(); // could be TreeSet if LSR were Comparable
|
||||
for (String paradigm : paradigms) {
|
||||
ULocale pl = new ULocale(paradigm);
|
||||
LSR max = XLikelySubtags.INSTANCE.makeMaximizedLsrFrom(pl, false);
|
||||
LSR max = LikelySubtags.INSTANCE.makeMaximizedLsrFrom(pl, false);
|
||||
// Clear the LSR flags to make the data equality test in
|
||||
// LocaleDistanceTest happy.
|
||||
paradigmLSRs.add(new LSR(max.language, max.script, max.region, LSR.DONT_CARE_FLAGS));
|
||||
|
@ -887,7 +887,7 @@ public final class LocaleDistanceBuilder {
|
|||
}
|
||||
|
||||
public static final void main(String[] args) throws IOException {
|
||||
XLikelySubtags.Data likelyData = XLikelySubtags.Data.load();
|
||||
LikelySubtags.Data likelyData = LikelySubtags.Data.load();
|
||||
LocaleDistance.Data distanceData = build();
|
||||
System.out.println("Writing LocaleDistance.Data to " + TXT_PATH + '/' + TXT_FILE_NAME);
|
||||
try (PrintWriter out = openWriter()) {
|
||||
|
|
|
@ -8,7 +8,7 @@ import com.google.common.collect.ImmutableSet;
|
|||
import com.google.common.collect.ImmutableSetMultimap;
|
||||
import com.google.common.collect.ImmutableSortedMap;
|
||||
import com.ibm.icu.impl.locale.LSR;
|
||||
import com.ibm.icu.impl.locale.XLikelySubtags;
|
||||
import com.ibm.icu.impl.locale.LikelySubtags;
|
||||
import org.unicode.cldr.api.AttributeKey;
|
||||
import org.unicode.cldr.api.CldrData;
|
||||
import org.unicode.cldr.api.CldrPath;
|
||||
|
@ -149,7 +149,7 @@ final class LikelySubtagsBuilder {
|
|||
}
|
||||
}
|
||||
|
||||
public static XLikelySubtags.Data build(CldrData supplementalData) {
|
||||
public static LikelySubtags.Data build(CldrData supplementalData) {
|
||||
// Build the table of LSR data from CLDR aliases and likely subtag information.
|
||||
Aliases languageAliases = Aliases.getAliases(supplementalData, AliasType.LANGUAGE);
|
||||
Aliases regionAliases = Aliases.getAliases(supplementalData, AliasType.TERRITORY);
|
||||
|
@ -175,12 +175,12 @@ final class LikelySubtagsBuilder {
|
|||
// Build the Trie of the LSR table data.
|
||||
Trie trie = writeLsrTable(lsrTable, lsrToIndex);
|
||||
|
||||
// Note: Using XLikelySubtags as a fairly "dumb" container for the return values
|
||||
// Note: Using LikelySubtags as a fairly "dumb" container for the return values
|
||||
// requires us to do slightly awkward things like passing mutable arrays around, but
|
||||
// the advantage it has is that this data structure is also what's used in client code,
|
||||
// so if the likely subtags data changes, it will be a forcing function to change this
|
||||
// code.
|
||||
return new XLikelySubtags.Data(
|
||||
return new LikelySubtags.Data(
|
||||
languageAliases.getCanonicalMap(),
|
||||
regionAliases.getCanonicalMap(),
|
||||
trie.toByteArray(),
|
||||
|
@ -214,7 +214,7 @@ final class LikelySubtagsBuilder {
|
|||
// We already checked '*' is in every scripts table.
|
||||
Map<String, LSR> regions = scripts.get("*");
|
||||
if (regions.size() > 1) {
|
||||
languageSpan.putPrefixAndValue(XLikelySubtags.SKIP_SCRIPT);
|
||||
languageSpan.putPrefixAndValue(LikelySubtags.SKIP_SCRIPT);
|
||||
}
|
||||
writeRegions(languageSpan, regions, lsrToIndex);
|
||||
} else {
|
||||
|
|
|
@ -41,8 +41,8 @@ import com.google.common.collect.ImmutableSet;
|
|||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.primitives.Bytes;
|
||||
import com.ibm.icu.impl.locale.LSR;
|
||||
import com.ibm.icu.impl.locale.LikelySubtags;
|
||||
import com.ibm.icu.impl.locale.LocaleDistance;
|
||||
import com.ibm.icu.impl.locale.XLikelySubtags;
|
||||
import com.ibm.icu.lang.UScript;
|
||||
|
||||
import com.ibm.icu.util.ULocale;
|
||||
|
@ -141,7 +141,7 @@ public final class LocaleDistanceMapper {
|
|||
throw new IllegalStateException(
|
||||
"The M49 list is too long. We can only encode up to 27 M49 codes.");
|
||||
}
|
||||
XLikelySubtags.Data likelyData = LikelySubtagsBuilder.build(data);
|
||||
LikelySubtags.Data likelyData = LikelySubtagsBuilder.build(data);
|
||||
icuData.add(LIKELY_LANGUAGES, ofMapEntries(likelyData.languageAliases));
|
||||
icuData.add(LIKELY_M49, RbValue.of(M49));
|
||||
icuData.add(LIKELY_REGIONS, ofMapEntries(likelyData.regionAliases));
|
||||
|
@ -422,7 +422,7 @@ public final class LocaleDistanceMapper {
|
|||
|
||||
Set<LSR> paradigmLSRs = new LinkedHashSet<>();
|
||||
for (String paradigm : LIST_SPLITTER.split(localesList)) {
|
||||
LSR max = XLikelySubtags.INSTANCE.makeMaximizedLsrFrom(new ULocale(paradigm), false);
|
||||
LSR max = LikelySubtags.INSTANCE.makeMaximizedLsrFrom(new ULocale(paradigm), false);
|
||||
// Clear the LSR flags to make the data equality test in LocaleDistanceTest happy.
|
||||
paradigmLSRs.add(new LSR(max.language, max.script, max.region, LSR.DONT_CARE_FLAGS));
|
||||
}
|
||||
|
|
|
@ -20,14 +20,14 @@ import org.unicode.cldr.api.CldrValue;
|
|||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.ibm.icu.impl.locale.LSR;
|
||||
import com.ibm.icu.impl.locale.XLikelySubtags;
|
||||
import com.ibm.icu.impl.locale.LikelySubtags;
|
||||
import com.ibm.icu.util.BytesTrie;
|
||||
|
||||
public class LikelySubtagsBuilderTest {
|
||||
|
||||
@Test
|
||||
public void testLanguageAliases() {
|
||||
XLikelySubtags.Data subtags = LikelySubtagsBuilder.build(getTestData(
|
||||
LikelySubtags.Data subtags = LikelySubtagsBuilder.build(getTestData(
|
||||
// Minimum mapping (or else code complains).
|
||||
likelySubtag("und", "en_Latn_US"),
|
||||
|
||||
|
@ -44,7 +44,7 @@ public class LikelySubtagsBuilderTest {
|
|||
|
||||
@Test
|
||||
public void testTerritoryAliases() {
|
||||
XLikelySubtags.Data subtags = LikelySubtagsBuilder.build(getTestData(
|
||||
LikelySubtags.Data subtags = LikelySubtagsBuilder.build(getTestData(
|
||||
// Minimum mapping (or else code complains).
|
||||
likelySubtag("und", "en_Latn_US"),
|
||||
|
||||
|
@ -60,7 +60,7 @@ public class LikelySubtagsBuilderTest {
|
|||
|
||||
@Test
|
||||
public void testLikelySubtags() {
|
||||
XLikelySubtags.Data subtags = LikelySubtagsBuilder.build(getTestData(
|
||||
LikelySubtags.Data subtags = LikelySubtagsBuilder.build(getTestData(
|
||||
likelySubtag("und", "en_Latn_US"),
|
||||
likelySubtag("en", "en_Latn_US"),
|
||||
likelySubtag("pt", "pt_Latn_BR"),
|
||||
|
@ -99,7 +99,7 @@ public class LikelySubtagsBuilderTest {
|
|||
.inOrder();
|
||||
}
|
||||
|
||||
private static ImmutableMap<String, LSR> getTrieTable(XLikelySubtags.Data subtags) {
|
||||
private static ImmutableMap<String, LSR> getTrieTable(LikelySubtags.Data subtags) {
|
||||
// We rebuild the Trie from the byte[] data.
|
||||
return TestData.getTrieTable(new BytesTrie(subtags.trie, 0), "*", i -> subtags.lsrs[i]);
|
||||
}
|
||||
|
|
|
@ -139,7 +139,7 @@ public class TrieTest {
|
|||
// We rebuild the Trie from the byte[] data.
|
||||
BytesTrie trie = new BytesTrie(data, 0);
|
||||
|
||||
// Mostly copied from XLikelySubtags (since the necessary constructor is private).
|
||||
// Mostly copied from LikelySubtags (since the necessary constructor is private).
|
||||
// Main change is the this no longer uses a TreeMap, since we want to test order.
|
||||
Map<String, Integer> map = new LinkedHashMap<>();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
|
Loading…
Add table
Reference in a new issue