diff --git a/icu4c/source/common/localematcher.cpp b/icu4c/source/common/localematcher.cpp index 6fc578af118b..aa5ba0778c5c 100644 --- a/icu4c/source/common/localematcher.cpp +++ b/icu4c/source/common/localematcher.cpp @@ -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 @@ class LocaleLsrIterator { } private: - const XLikelySubtags &likelySubtags; + const LikelySubtags &likelySubtags; Locale::Iterator &locales; ULocMatchLifetime lifetime; const Locale *current = nullptr, *remembered = nullptr; diff --git a/icu4c/source/common/locdistance.cpp b/icu4c/source/common/locdistance.cpp index fb22fe79ed36..61822e5b78c2 100644 --- a/icu4c/source/common/locdistance.cpp +++ b/icu4c/source/common/locdistance.cpp @@ -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]; diff --git a/icu4c/source/common/locdistance.h b/icu4c/source/common/locdistance.h index 51b777e62723..b0fbe9ad6cf2 100644 --- a/icu4c/source/common/locdistance.h +++ b/icu4c/source/common/locdistance.h @@ -83,7 +83,7 @@ class LocaleDistance final : public UMemory { // 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 @@ class LocaleDistance final : public UMemory { 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. diff --git a/icu4c/source/common/loclikely.cpp b/icu4c/source/common/loclikely.cpp index c7cf21486e0c..bd3a597df40a 100644 --- a/icu4c/source/common/loclikely.cpp +++ b/icu4c/source/common/loclikely.cpp @@ -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; } diff --git a/icu4c/source/common/loclikelysubtags.cpp b/icu4c/source/common/loclikelysubtags.cpp index 3693feabb301..8800111d166e 100644 --- a/icu4c/source/common/loclikelysubtags.cpp +++ b/icu4c/source/common/loclikelysubtags.cpp @@ -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 @@ struct XLikelySubtagsData { 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 { diff --git a/icu4c/source/common/loclikelysubtags.h b/icu4c/source/common/loclikelysubtags.h index ebd9c153068e..5c51e353c1e7 100644 --- a/icu4c/source/common/loclikelysubtags.h +++ b/icu4c/source/common/loclikelysubtags.h @@ -19,7 +19,7 @@ U_NAMESPACE_BEGIN -struct XLikelySubtagsData; +struct LikelySubtagsData; struct LocaleDistanceData { LocaleDistanceData() = default; @@ -37,15 +37,14 @@ struct LocaleDistanceData { 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 @@ class XLikelySubtags final : public UMemory { 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 @@ class XLikelySubtags final : public UMemory { int32_t lsrsLength; #endif - // distance/matcher data: see comment in XLikelySubtagsData::load() + // distance/matcher data: see comment in LikelySubtagsData::load() LocaleDistanceData distanceData; }; diff --git a/icu4c/source/common/unicode/localematcher.h b/icu4c/source/common/unicode/localematcher.h index 603daf7231dd..3e62c67c7e16 100644 --- a/icu4c/source/common/unicode/localematcher.h +++ b/icu4c/source/common/unicode/localematcher.h @@ -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 @@ class U_COMMON_API LocaleMatcher : public UMemory { 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; diff --git a/icu4j/coverage-exclusion.txt b/icu4j/coverage-exclusion.txt index 06ae033381b2..183f13604cab 100644 --- a/icu4j/coverage-exclusion.txt +++ b/icu4j/coverage-exclusion.txt @@ -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#:()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 diff --git a/icu4j/main/core/src/main/java/com/ibm/icu/impl/locale/XLikelySubtags.java b/icu4j/main/core/src/main/java/com/ibm/icu/impl/locale/LikelySubtags.java similarity index 99% rename from icu4j/main/core/src/main/java/com/ibm/icu/impl/locale/XLikelySubtags.java rename to icu4j/main/core/src/main/java/com/ibm/icu/impl/locale/LikelySubtags.java index 299b1f8276b2..6d5a35379378 100644 --- a/icu4j/main/core/src/main/java/com/ibm/icu/impl/locale/XLikelySubtags.java +++ b/icu4j/main/core/src/main/java/com/ibm/icu/impl/locale/LikelySubtags.java @@ -18,7 +18,7 @@ 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 boolean equals(Object other) { } // VisibleForTesting - public static final XLikelySubtags INSTANCE = new XLikelySubtags(Data.load()); + public static final LikelySubtags INSTANCE = new LikelySubtags(Data.load()); private final Map languageAliases; private final Map regionAliases; @@ -124,7 +124,7 @@ public boolean equals(Object other) { 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); diff --git a/icu4j/main/core/src/main/java/com/ibm/icu/impl/locale/LocaleDistance.java b/icu4j/main/core/src/main/java/com/ibm/icu/impl/locale/LocaleDistance.java index 3d4d540a3fef..40becdd77f05 100644 --- a/icu4j/main/core/src/main/java/com/ibm/icu/impl/locale/LocaleDistance.java +++ b/icu4j/main/core/src/main/java/com/ibm/icu/impl/locale/LocaleDistance.java @@ -225,8 +225,8 @@ private LocaleDistance(Data data) { // 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 int getBestIndexAndDistance(LSR desired, LSR[] supportedLSRs, int support 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 int getBestIndexAndDistance(LSR desired, LSR[] supportedLSRs, int support 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, diff --git a/icu4j/main/core/src/main/java/com/ibm/icu/util/LocaleMatcher.java b/icu4j/main/core/src/main/java/com/ibm/icu/util/LocaleMatcher.java index 074ee0a4f1ec..9fd35660a533 100644 --- a/icu4j/main/core/src/main/java/com/ibm/icu/util/LocaleMatcher.java +++ b/icu4j/main/core/src/main/java/com/ibm/icu/util/LocaleMatcher.java @@ -17,8 +17,8 @@ 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 @@ private static final LSR getMaximalLsrOrUnd(ULocale locale) { 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 @@ private static final LSR getMaximalLsrOrUnd(Locale locale) { 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 double match(ULocale desired, ULocale desiredMax, ULocale supported, ULoc * @stable ICU 4.4 */ public ULocale canonicalize(ULocale locale) { - return XLikelySubtags.INSTANCE.canonicalize(locale); + return LikelySubtags.INSTANCE.canonicalize(locale); } /** diff --git a/icu4j/main/core/src/main/java/com/ibm/icu/util/ULocale.java b/icu4j/main/core/src/main/java/com/ibm/icu/util/ULocale.java index d002bc2ee984..d2fa84a8c94b 100644 --- a/icu4j/main/core/src/main/java/com/ibm/icu/util/ULocale.java +++ b/icu4j/main/core/src/main/java/com/ibm/icu/util/ULocale.java @@ -44,11 +44,11 @@ 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 static ULocale addLikelySubtags(ULocale loc) { 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 static ULocale minimizeSubtags(ULocale loc, Minimize fieldToFavor) { 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); diff --git a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/util/LocaleMatcherTest.java b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/util/LocaleMatcherTest.java index 74a3216ac8c0..9b7f5e667596 100644 --- a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/util/LocaleMatcherTest.java +++ b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/util/LocaleMatcherTest.java @@ -24,8 +24,8 @@ 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 @@ private static long timeMaximize(Iterable list, int iterations) { 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; diff --git a/icu4j/main/core/src/test/java/com/ibm/icu/dev/tool/locale/LocaleDistanceBuilder.java b/icu4j/main/core/src/test/java/com/ibm/icu/dev/tool/locale/LocaleDistanceBuilder.java index 4a0736a99b6c..258ac46f7101 100644 --- a/icu4j/main/core/src/test/java/com/ibm/icu/dev/tool/locale/LocaleDistanceBuilder.java +++ b/icu4j/main/core/src/test/java/com/ibm/icu/dev/tool/locale/LocaleDistanceBuilder.java @@ -26,12 +26,12 @@ 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 static LocaleDistance.Data build() { Set 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 @@ private static void printManyHexBytes(PrintWriter out, byte[] bytes) { } 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()) { diff --git a/tools/cldr/cldr-to-icu/src/main/java/org/unicode/icu/tool/cldrtoicu/localedistance/LikelySubtagsBuilder.java b/tools/cldr/cldr-to-icu/src/main/java/org/unicode/icu/tool/cldrtoicu/localedistance/LikelySubtagsBuilder.java index 30d1b73269db..edce6b06e90b 100644 --- a/tools/cldr/cldr-to-icu/src/main/java/org/unicode/icu/tool/cldrtoicu/localedistance/LikelySubtagsBuilder.java +++ b/tools/cldr/cldr-to-icu/src/main/java/org/unicode/icu/tool/cldrtoicu/localedistance/LikelySubtagsBuilder.java @@ -8,7 +8,7 @@ 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 @@ public ImmutableSet getAliases(String canonical) { } } - 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 @@ public static XLikelySubtags.Data build(CldrData supplementalData) { // 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 @@ private static void writeScripts( // We already checked '*' is in every scripts table. Map regions = scripts.get("*"); if (regions.size() > 1) { - languageSpan.putPrefixAndValue(XLikelySubtags.SKIP_SCRIPT); + languageSpan.putPrefixAndValue(LikelySubtags.SKIP_SCRIPT); } writeRegions(languageSpan, regions, lsrToIndex); } else { diff --git a/tools/cldr/cldr-to-icu/src/main/java/org/unicode/icu/tool/cldrtoicu/localedistance/LocaleDistanceMapper.java b/tools/cldr/cldr-to-icu/src/main/java/org/unicode/icu/tool/cldrtoicu/localedistance/LocaleDistanceMapper.java index 150a9db28680..c8938397b54f 100644 --- a/tools/cldr/cldr-to-icu/src/main/java/org/unicode/icu/tool/cldrtoicu/localedistance/LocaleDistanceMapper.java +++ b/tools/cldr/cldr-to-icu/src/main/java/org/unicode/icu/tool/cldrtoicu/localedistance/LocaleDistanceMapper.java @@ -41,8 +41,8 @@ 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 @@ static IcuData process(CldrData data) { 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 @@ private static Set getParadigmLsrs(CldrData supplementalData) { Set 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)); } diff --git a/tools/cldr/cldr-to-icu/src/test/java/org/unicode/icu/tool/cldrtoicu/localedistance/LikelySubtagsBuilderTest.java b/tools/cldr/cldr-to-icu/src/test/java/org/unicode/icu/tool/cldrtoicu/localedistance/LikelySubtagsBuilderTest.java index b16a1b119701..b38f926d3d5e 100644 --- a/tools/cldr/cldr-to-icu/src/test/java/org/unicode/icu/tool/cldrtoicu/localedistance/LikelySubtagsBuilderTest.java +++ b/tools/cldr/cldr-to-icu/src/test/java/org/unicode/icu/tool/cldrtoicu/localedistance/LikelySubtagsBuilderTest.java @@ -20,14 +20,14 @@ 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 void testLanguageAliases() { @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 void testTerritoryAliases() { @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 void testLikelySubtags() { .inOrder(); } - private static ImmutableMap getTrieTable(XLikelySubtags.Data subtags) { + private static ImmutableMap getTrieTable(LikelySubtags.Data subtags) { // We rebuild the Trie from the byte[] data. return TestData.getTrieTable(new BytesTrie(subtags.trie, 0), "*", i -> subtags.lsrs[i]); } diff --git a/tools/cldr/cldr-to-icu/src/test/java/org/unicode/icu/tool/cldrtoicu/localedistance/TrieTest.java b/tools/cldr/cldr-to-icu/src/test/java/org/unicode/icu/tool/cldrtoicu/localedistance/TrieTest.java index e57981a82193..a4f2312596d9 100644 --- a/tools/cldr/cldr-to-icu/src/test/java/org/unicode/icu/tool/cldrtoicu/localedistance/TrieTest.java +++ b/tools/cldr/cldr-to-icu/src/test/java/org/unicode/icu/tool/cldrtoicu/localedistance/TrieTest.java @@ -139,7 +139,7 @@ private static ImmutableMap getRawTrieTable(byte[] data) { // 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 map = new LinkedHashMap<>(); StringBuilder sb = new StringBuilder();