Backed out 2 changesets (bug 1733659) for causing build bustages. CLOSED TREE

Backed out changeset 9e23aa79fda9 (bug 1733659)
Backed out changeset e316768591c0 (bug 1733659)
This commit is contained in:
Sandor Molnar 2021-11-22 20:51:20 +02:00
parent 76b501598c
commit 2594d2ac61
21 changed files with 1090 additions and 1099 deletions

View File

@ -475,17 +475,17 @@ void nsLineBreaker::UpdateCurrentWordLanguage(nsAtom* aHyphenationLanguage) {
if (aHyphenationLanguage && !mCurrentWordLanguage) {
Locale loc;
auto result =
LocaleParser::TryParse(nsAtomCString(aHyphenationLanguage), loc);
LocaleParser::tryParse(nsAtomCString(aHyphenationLanguage), loc);
if (result.isErr()) {
return;
}
if (loc.Script().Missing() && loc.AddLikelySubtags().isErr()) {
if (loc.script().missing() && loc.addLikelySubtags().isErr()) {
return;
}
mScriptIsChineseOrJapanese =
loc.Script().EqualTo("Hans") || loc.Script().EqualTo("Hant") ||
loc.Script().EqualTo("Jpan") || loc.Script().EqualTo("Hrkt");
loc.script().equalTo("Hans") || loc.script().equalTo("Hant") ||
loc.script().equalTo("Jpan") || loc.script().equalTo("Hrkt");
}
mCurrentWordLanguage = aHyphenationLanguage;
}

View File

@ -96,9 +96,9 @@ bool PaymentRequest::PrefEnabled(JSContext* aCx, JSObject* aObj) {
nsAutoCString locale;
LocaleService::GetInstance()->GetAppLocaleAsBCP47(locale);
mozilla::intl::Locale loc;
auto result = mozilla::intl::LocaleParser::TryParse(locale, loc);
if (!(result.isOk() && loc.Canonicalize().isOk() &&
loc.Language().EqualTo("en") && loc.Region().EqualTo("US"))) {
auto result = mozilla::intl::LocaleParser::tryParse(locale, loc);
if (!(result.isOk() && loc.canonicalize().isOk() &&
loc.language().equalTo("en") && loc.region().equalTo("US"))) {
return false;
}

View File

@ -894,9 +894,9 @@ void EditorSpellCheck::SetFallbackDictionary(DictionaryFetcher* aFetcher) {
// Required dictionary was not available. Try to get a dictionary
// matching at least language part of dictName.
mozilla::intl::Locale loc;
if (mozilla::intl::LocaleParser::TryParse(dictName, loc).isOk() &&
loc.Canonicalize().isOk()) {
Span<const char> language = loc.Language().Span();
if (mozilla::intl::LocaleParser::tryParse(dictName, loc).isOk() &&
loc.canonicalize().isOk()) {
Span<const char> language = loc.language().span();
nsAutoCString langCode(language.data(), language.size());
// Try dictionary.spellchecker preference, if it starts with langCode,
@ -922,9 +922,9 @@ void EditorSpellCheck::SetFallbackDictionary(DictionaryFetcher* aFetcher) {
if (!appLocaleStr.IsEmpty()) {
mozilla::intl::Locale appLoc;
auto result =
mozilla::intl::LocaleParser::TryParse(appLocaleStr, appLoc);
if (result.isOk() && loc.Canonicalize().isOk() &&
loc.Language().Span() == appLoc.Language().Span()) {
mozilla::intl::LocaleParser::tryParse(appLocaleStr, appLoc);
if (result.isOk() && loc.canonicalize().isOk() &&
loc.language().span() == appLoc.language().span()) {
BuildDictionaryList(appLocaleStr, dictList,
DICT_COMPARE_CASE_INSENSITIVE, tryDictList);
}
@ -937,9 +937,9 @@ void EditorSpellCheck::SetFallbackDictionary(DictionaryFetcher* aFetcher) {
if (!sysLocaleStr.IsEmpty()) {
mozilla::intl::Locale sysLoc;
auto result =
mozilla::intl::LocaleParser::TryParse(sysLocaleStr, sysLoc);
if (result.isOk() && loc.Canonicalize().isOk() &&
loc.Language().Span() == sysLoc.Language().Span()) {
mozilla::intl::LocaleParser::tryParse(sysLocaleStr, sysLoc);
if (result.isOk() && loc.canonicalize().isOk() &&
loc.language().span() == sysLoc.language().span()) {
BuildDictionaryList(sysLocaleStr, dictList,
DICT_COMPARE_CASE_INSENSITIVE, tryDictList);
}

View File

@ -2174,19 +2174,19 @@ void gfxPlatformFontList::AppendCJKPrefLangs(eFontPrefLang aPrefLangs[],
{
Locale locale;
if (LocaleParser::TryParse(localeStr, locale).isOk() &&
locale.Canonicalize().isOk()) {
if (locale.Language().EqualTo("ja")) {
if (LocaleParser::tryParse(localeStr, locale).isOk() &&
locale.canonicalize().isOk()) {
if (locale.language().equalTo("ja")) {
AppendPrefLang(tempPrefLangs, tempLen, eFontPrefLang_Japanese);
} else if (locale.Language().EqualTo("zh")) {
if (locale.Region().EqualTo("CN")) {
} else if (locale.language().equalTo("zh")) {
if (locale.region().equalTo("CN")) {
AppendPrefLang(tempPrefLangs, tempLen, eFontPrefLang_ChineseCN);
} else if (locale.Region().EqualTo("TW")) {
} else if (locale.region().equalTo("TW")) {
AppendPrefLang(tempPrefLangs, tempLen, eFontPrefLang_ChineseTW);
} else if (locale.Region().EqualTo("HK")) {
} else if (locale.region().equalTo("HK")) {
AppendPrefLang(tempPrefLangs, tempLen, eFontPrefLang_ChineseHK);
}
} else if (locale.Language().EqualTo("ko")) {
} else if (locale.language().equalTo("ko")) {
AppendPrefLang(tempPrefLangs, tempLen, eFontPrefLang_Korean);
}
}
@ -2209,19 +2209,19 @@ void gfxPlatformFontList::AppendCJKPrefLangs(eFontPrefLang aPrefLangs[],
LocaleService::kLangNegStrategyFiltering, negLocales);
for (const auto& localeStr : negLocales) {
Locale locale;
if (LocaleParser::TryParse(localeStr, locale).isOk() &&
locale.Canonicalize().isOk()) {
if (locale.Language().EqualTo("ja")) {
if (LocaleParser::tryParse(localeStr, locale).isOk() &&
locale.canonicalize().isOk()) {
if (locale.language().equalTo("ja")) {
AppendPrefLang(tempPrefLangs, tempLen, eFontPrefLang_Japanese);
} else if (locale.Language().EqualTo("zh")) {
if (locale.Region().EqualTo("CN")) {
} else if (locale.language().equalTo("zh")) {
if (locale.region().equalTo("CN")) {
AppendPrefLang(tempPrefLangs, tempLen, eFontPrefLang_ChineseCN);
} else if (locale.Region().EqualTo("TW")) {
} else if (locale.region().equalTo("TW")) {
AppendPrefLang(tempPrefLangs, tempLen, eFontPrefLang_ChineseTW);
} else if (locale.Region().EqualTo("HK")) {
} else if (locale.region().equalTo("HK")) {
AppendPrefLang(tempPrefLangs, tempLen, eFontPrefLang_ChineseHK);
}
} else if (locale.Language().EqualTo("ko")) {
} else if (locale.language().equalTo("ko")) {
AppendPrefLang(tempPrefLangs, tempLen, eFontPrefLang_Korean);
}
}

View File

@ -13,30 +13,29 @@ namespace mozilla::intl {
TEST(IntlLocale, LocaleSettersAndGetters)
{
Locale locale;
locale.SetLanguage("fr");
locale.SetRegion("CA");
locale.SetScript("Latn");
locale.setLanguage("fr");
locale.setRegion("CA");
locale.setScript("Latn");
ASSERT_TRUE(
locale.SetUnicodeExtension(MakeStringSpan("u-ca-gregory")).isOk());
ASSERT_TRUE(locale.Language().EqualTo("fr"));
ASSERT_TRUE(locale.Region().EqualTo("CA"));
ASSERT_TRUE(locale.Script().EqualTo("Latn"));
ASSERT_EQ(locale.GetUnicodeExtension().value(),
MakeStringSpan("u-ca-gregory"));
locale.setUnicodeExtension(MakeStringSpan("u-ca-gregory")).isOk());
ASSERT_TRUE(locale.language().equalTo("fr"));
ASSERT_TRUE(locale.region().equalTo("CA"));
ASSERT_TRUE(locale.script().equalTo("Latn"));
ASSERT_EQ(locale.unicodeExtension().value(), MakeStringSpan("u-ca-gregory"));
TestBuffer<char> buffer;
ASSERT_TRUE(locale.ToString(buffer).isOk());
ASSERT_TRUE(locale.toString(buffer).isOk());
ASSERT_TRUE(buffer.verboseMatches("fr-Latn-CA-u-ca-gregory"));
// No setters for variants or other extensions...
Locale locale2;
ASSERT_TRUE(LocaleParser::TryParse(
ASSERT_TRUE(LocaleParser::tryParse(
MakeStringSpan("fr-CA-fonipa-t-es-AR-h0-hybrid"), locale2)
.isOk());
ASSERT_EQ(locale2.Variants()[0], MakeStringSpan("fonipa"));
ASSERT_EQ(locale2.Extensions()[0], MakeStringSpan("t-es-AR-h0-hybrid"));
locale2.ClearVariants();
ASSERT_EQ(locale2.Variants().length(), 0UL);
ASSERT_EQ(locale2.variants()[0], MakeStringSpan("fonipa"));
ASSERT_EQ(locale2.extensions()[0], MakeStringSpan("t-es-AR-h0-hybrid"));
locale2.clearVariants();
ASSERT_EQ(locale2.variants().length(), 0UL);
}
TEST(IntlLocale, LocaleParser)
@ -53,21 +52,21 @@ TEST(IntlLocale, LocaleParser)
Locale locale;
for (const auto* tag : tags) {
ASSERT_TRUE(LocaleParser::TryParse(MakeStringSpan(tag), locale).isOk());
ASSERT_TRUE(LocaleParser::tryParse(MakeStringSpan(tag), locale).isOk());
}
}
TEST(IntlLocale, LikelySubtags)
{
Locale locale;
ASSERT_TRUE(LocaleParser::TryParse(MakeStringSpan("zh"), locale).isOk());
ASSERT_TRUE(locale.AddLikelySubtags().isOk());
ASSERT_TRUE(LocaleParser::tryParse(MakeStringSpan("zh"), locale).isOk());
ASSERT_TRUE(locale.addLikelySubtags().isOk());
TestBuffer<char> buffer;
ASSERT_TRUE(locale.ToString(buffer).isOk());
ASSERT_TRUE(locale.toString(buffer).isOk());
ASSERT_TRUE(buffer.verboseMatches("zh-Hans-CN"));
ASSERT_TRUE(locale.RemoveLikelySubtags().isOk());
ASSERT_TRUE(locale.removeLikelySubtags().isOk());
buffer.clear();
ASSERT_TRUE(locale.ToString(buffer).isOk());
ASSERT_TRUE(locale.toString(buffer).isOk());
ASSERT_TRUE(buffer.verboseMatches("zh"));
}
@ -75,10 +74,10 @@ TEST(IntlLocale, Canonicalize)
{
Locale locale;
ASSERT_TRUE(
LocaleParser::TryParse(MakeStringSpan("nob-bokmal"), locale).isOk());
ASSERT_TRUE(locale.Canonicalize().isOk());
LocaleParser::tryParse(MakeStringSpan("nob-bokmal"), locale).isOk());
ASSERT_TRUE(locale.canonicalize().isOk());
TestBuffer<char> buffer;
ASSERT_TRUE(locale.ToString(buffer).isOk());
ASSERT_TRUE(locale.toString(buffer).isOk());
ASSERT_TRUE(buffer.verboseMatches("nb"));
}

File diff suppressed because it is too large Load Diff

View File

@ -32,68 +32,68 @@ namespace mozilla::intl {
* Return true if |language| is a valid language subtag.
*/
template <typename CharT>
bool IsStructurallyValidLanguageTag(mozilla::Span<const CharT> aLanguage);
bool IsStructurallyValidLanguageTag(mozilla::Span<const CharT> language);
/**
* Return true if |script| is a valid script subtag.
*/
template <typename CharT>
bool IsStructurallyValidScriptTag(mozilla::Span<const CharT> aScript);
bool IsStructurallyValidScriptTag(mozilla::Span<const CharT> script);
/**
* Return true if |region| is a valid region subtag.
*/
template <typename CharT>
bool IsStructurallyValidRegionTag(mozilla::Span<const CharT> aRegion);
bool IsStructurallyValidRegionTag(mozilla::Span<const CharT> region);
#ifdef DEBUG
/**
* Return true if |variant| is a valid variant subtag.
*/
bool IsStructurallyValidVariantTag(mozilla::Span<const char> aVariant);
bool IsStructurallyValidVariantTag(mozilla::Span<const char> variant);
/**
* Return true if |extension| is a valid Unicode extension subtag.
*/
bool IsStructurallyValidUnicodeExtensionTag(
mozilla::Span<const char> aExtension);
mozilla::Span<const char> extension);
/**
* Return true if |privateUse| is a valid private-use subtag.
*/
bool IsStructurallyValidPrivateUseTag(mozilla::Span<const char> aPrivateUse);
bool IsStructurallyValidPrivateUseTag(mozilla::Span<const char> privateUse);
#endif
template <typename CharT>
char AsciiToLowerCase(CharT aChar) {
MOZ_ASSERT(mozilla::IsAscii(aChar));
return mozilla::IsAsciiUppercaseAlpha(aChar) ? (aChar + 0x20) : aChar;
char AsciiToLowerCase(CharT c) {
MOZ_ASSERT(mozilla::IsAscii(c));
return mozilla::IsAsciiUppercaseAlpha(c) ? (c + 0x20) : c;
}
template <typename CharT>
char AsciiToUpperCase(CharT aChar) {
MOZ_ASSERT(mozilla::IsAscii(aChar));
return mozilla::IsAsciiLowercaseAlpha(aChar) ? (aChar - 0x20) : aChar;
char AsciiToUpperCase(CharT c) {
MOZ_ASSERT(mozilla::IsAscii(c));
return mozilla::IsAsciiLowercaseAlpha(c) ? (c - 0x20) : c;
}
template <typename CharT>
void AsciiToLowerCase(CharT* aChars, size_t aLength, char* aDest) {
void AsciiToLowerCase(CharT* chars, size_t length, char* dest) {
char (&fn)(CharT) = AsciiToLowerCase;
std::transform(aChars, aChars + aLength, aDest, fn);
std::transform(chars, chars + length, dest, fn);
}
template <typename CharT>
void AsciiToUpperCase(CharT* aChars, size_t aLength, char* aDest) {
void AsciiToUpperCase(CharT* chars, size_t length, char* dest) {
char (&fn)(CharT) = AsciiToUpperCase;
std::transform(aChars, aChars + aLength, aDest, fn);
std::transform(chars, chars + length, dest, fn);
}
template <typename CharT>
void AsciiToTitleCase(CharT* aChars, size_t aLength, char* aDest) {
if (aLength > 0) {
AsciiToUpperCase(aChars, 1, aDest);
AsciiToLowerCase(aChars + 1, aLength - 1, aDest + 1);
void AsciiToTitleCase(CharT* chars, size_t length, char* dest) {
if (length > 0) {
AsciiToUpperCase(chars, 1, dest);
AsciiToLowerCase(chars + 1, length - 1, dest + 1);
}
}
@ -120,10 +120,10 @@ static constexpr size_t TransformKeyLength = 2;
} // namespace LanguageTagLimits
// Fixed size language subtag which is stored inline in Locale.
template <size_t SubtagLength>
template <size_t Length>
class LanguageTagSubtag final {
uint8_t mLength = 0;
char mChars[SubtagLength] = {}; // zero initialize
uint8_t length_ = 0;
char chars_[Length] = {}; // zero initialize
public:
LanguageTagSubtag() = default;
@ -131,40 +131,39 @@ class LanguageTagSubtag final {
LanguageTagSubtag(const LanguageTagSubtag&) = delete;
LanguageTagSubtag& operator=(const LanguageTagSubtag&) = delete;
size_t Length() const { return mLength; }
bool Missing() const { return mLength == 0; }
bool Present() const { return mLength > 0; }
size_t length() const { return length_; }
bool missing() const { return length_ == 0; }
bool present() const { return length_ > 0; }
mozilla::Span<const char> Span() const { return {mChars, mLength}; }
mozilla::Span<const char> span() const { return {chars_, length_}; }
template <typename CharT>
void Set(mozilla::Span<const CharT> str) {
MOZ_ASSERT(str.size() <= SubtagLength);
std::copy_n(str.data(), str.size(), mChars);
mLength = str.size();
void set(mozilla::Span<const CharT> str) {
MOZ_ASSERT(str.size() <= Length);
std::copy_n(str.data(), str.size(), chars_);
length_ = str.size();
}
// The toXYZCase() methods are using |SubtagLength| instead of |length()|,
// because current compilers (tested GCC and Clang) can't infer the maximum
// string length - even when using hints like |std::min| - and instead are
// emitting SIMD optimized code. Using a fixed sized length avoids emitting
// the SIMD code. (Emitting SIMD code doesn't make sense here, because the
// SIMD code only kicks in for long strings.) A fixed length will
// additionally ensure the compiler unrolls the loop in the case conversion
// code.
// The toXYZCase() methods are using |Length| instead of |length()|, because
// current compilers (tested GCC and Clang) can't infer the maximum string
// length - even when using hints like |std::min| - and instead are emitting
// SIMD optimized code. Using a fixed sized length avoids emitting the SIMD
// code. (Emitting SIMD code doesn't make sense here, because the SIMD code
// only kicks in for long strings.) A fixed length will additionally ensure
// the compiler unrolls the loop in the case conversion code.
void ToLowerCase() { AsciiToLowerCase(mChars, SubtagLength, mChars); }
void toLowerCase() { AsciiToLowerCase(chars_, Length, chars_); }
void ToUpperCase() { AsciiToUpperCase(mChars, SubtagLength, mChars); }
void toUpperCase() { AsciiToUpperCase(chars_, Length, chars_); }
void ToTitleCase() { AsciiToTitleCase(mChars, SubtagLength, mChars); }
void toTitleCase() { AsciiToTitleCase(chars_, Length, chars_); }
template <size_t N>
bool EqualTo(const char (&str)[N]) const {
static_assert(N - 1 <= SubtagLength,
bool equalTo(const char (&str)[N]) const {
static_assert(N - 1 <= Length,
"subtag literals must not exceed the maximum subtag length");
return mLength == N - 1 && memcmp(mChars, str, N - 1) == 0;
return length_ == N - 1 && memcmp(chars_, str, N - 1) == 0;
}
};
@ -181,16 +180,16 @@ using UniqueChars = UniquePtr<char[]>;
* All subtags are already in canonicalized case.
*/
class MOZ_STACK_CLASS Locale final {
LanguageSubtag mLanguage = {};
ScriptSubtag mScript = {};
RegionSubtag mRegion = {};
LanguageSubtag language_ = {};
ScriptSubtag script_ = {};
RegionSubtag region_ = {};
using VariantsVector = Vector<UniqueChars, 2>;
using ExtensionsVector = Vector<UniqueChars, 2>;
VariantsVector mVariants;
ExtensionsVector mExtensions;
UniqueChars mPrivateUse = nullptr;
VariantsVector variants_;
ExtensionsVector extensions_;
UniqueChars privateuse_ = nullptr;
friend class LocaleParser;
@ -202,44 +201,44 @@ class MOZ_STACK_CLASS Locale final {
};
private:
Result<Ok, CanonicalizationError> CanonicalizeUnicodeExtension(
Result<Ok, CanonicalizationError> canonicalizeUnicodeExtension(
UniqueChars& unicodeExtension);
Result<Ok, CanonicalizationError> CanonicalizeTransformExtension(
Result<Ok, CanonicalizationError> canonicalizeTransformExtension(
UniqueChars& transformExtension);
public:
static bool LanguageMapping(LanguageSubtag& aLanguage);
static bool ComplexLanguageMapping(const LanguageSubtag& aLanguage);
static bool languageMapping(LanguageSubtag& language);
static bool complexLanguageMapping(const LanguageSubtag& language);
private:
static bool ScriptMapping(ScriptSubtag& aScript);
static bool RegionMapping(RegionSubtag& aRegion);
static bool ComplexRegionMapping(const RegionSubtag& aRegion);
static bool scriptMapping(ScriptSubtag& script);
static bool regionMapping(RegionSubtag& region);
static bool complexRegionMapping(const RegionSubtag& region);
void PerformComplexLanguageMappings();
void PerformComplexRegionMappings();
[[nodiscard]] bool PerformVariantMappings();
void performComplexLanguageMappings();
void performComplexRegionMappings();
[[nodiscard]] bool performVariantMappings();
[[nodiscard]] bool UpdateLegacyMappings();
[[nodiscard]] bool updateLegacyMappings();
static bool SignLanguageMapping(LanguageSubtag& aLanguage,
const RegionSubtag& aRegion);
static bool signLanguageMapping(LanguageSubtag& language,
const RegionSubtag& region);
static const char* ReplaceTransformExtensionType(
mozilla::Span<const char> aKey, mozilla::Span<const char> aType);
static const char* replaceTransformExtensionType(
mozilla::Span<const char> key, mozilla::Span<const char> type);
public:
/**
* Given a Unicode key and type, return the null-terminated preferred
* replacement for that type if there is one, or null if there is none, e.g.
* in effect
* |ReplaceUnicodeExtensionType("ca", "islamicc") == "islamic-civil"|
* |replaceUnicodeExtensionType("ca", "islamicc") == "islamic-civil"|
* and
* |ReplaceUnicodeExtensionType("ca", "islamic-civil") == nullptr|.
* |replaceUnicodeExtensionType("ca", "islamic-civil") == nullptr|.
*/
static const char* ReplaceUnicodeExtensionType(
mozilla::Span<const char> aKey, mozilla::Span<const char> aType);
static const char* replaceUnicodeExtensionType(
mozilla::Span<const char> key, mozilla::Span<const char> type);
public:
Locale() = default;
@ -250,10 +249,10 @@ class MOZ_STACK_CLASS Locale final {
class SubtagIterator {
using Iter = decltype(std::declval<const Vec>().begin());
Iter mIter;
Iter iter_;
public:
explicit SubtagIterator(Iter iter) : mIter(iter) {}
explicit SubtagIterator(Iter iter) : iter_(iter) {}
// std::iterator traits.
using iterator_category = std::input_iterator_tag;
@ -263,7 +262,7 @@ class MOZ_STACK_CLASS Locale final {
using reference = value_type&;
SubtagIterator& operator++() {
mIter++;
iter_++;
return *this;
}
@ -274,43 +273,43 @@ class MOZ_STACK_CLASS Locale final {
}
bool operator==(const SubtagIterator& aOther) const {
return mIter == aOther.mIter;
return iter_ == aOther.iter_;
}
bool operator!=(const SubtagIterator& aOther) const {
return !(*this == aOther);
}
value_type operator*() const { return MakeStringSpan(mIter->get()); }
value_type operator*() const { return MakeStringSpan(iter_->get()); }
};
template <size_t N>
class SubtagEnumeration {
using Vec = Vector<UniqueChars, N>;
const Vec& mVector;
const Vec& vector_;
public:
explicit SubtagEnumeration(const Vec& aVector) : mVector(aVector) {}
explicit SubtagEnumeration(const Vec& vector) : vector_(vector) {}
size_t length() const { return mVector.length(); }
bool empty() const { return mVector.empty(); }
size_t length() const { return vector_.length(); }
bool empty() const { return vector_.empty(); }
auto begin() const { return SubtagIterator<Vec>(mVector.begin()); }
auto end() const { return SubtagIterator<Vec>(mVector.end()); }
auto begin() const { return SubtagIterator<Vec>(vector_.begin()); }
auto end() const { return SubtagIterator<Vec>(vector_.end()); }
Span<const char> operator[](size_t aIndex) const {
return MakeStringSpan(mVector[aIndex].get());
Span<const char> operator[](size_t index) const {
return MakeStringSpan(vector_[index].get());
}
};
const LanguageSubtag& Language() const { return mLanguage; }
const ScriptSubtag& Script() const { return mScript; }
const RegionSubtag& Region() const { return mRegion; }
auto Variants() const { return SubtagEnumeration(mVariants); }
auto Extensions() const { return SubtagEnumeration(mExtensions); }
Maybe<Span<const char>> PrivateUse() const {
if (const char* p = mPrivateUse.get()) {
const LanguageSubtag& language() const { return language_; }
const ScriptSubtag& script() const { return script_; }
const RegionSubtag& region() const { return region_; }
auto variants() const { return SubtagEnumeration(variants_); }
auto extensions() const { return SubtagEnumeration(extensions_); }
Maybe<Span<const char>> privateuse() const {
if (const char* p = privateuse_.get()) {
return Some(MakeStringSpan(p));
}
return Nothing();
@ -319,93 +318,91 @@ class MOZ_STACK_CLASS Locale final {
/**
* Return the Unicode extension subtag or Nothing if not present.
*/
Maybe<Span<const char>> GetUnicodeExtension() const;
Maybe<Span<const char>> unicodeExtension() const;
private:
ptrdiff_t UnicodeExtensionIndex() const;
ptrdiff_t unicodeExtensionIndex() const;
public:
/**
* Set the language subtag. The input must be a valid language subtag.
*/
template <size_t N>
void SetLanguage(const char (&aLanguage)[N]) {
mozilla::Span<const char> span(aLanguage, N - 1);
void setLanguage(const char (&language)[N]) {
mozilla::Span<const char> span(language, N - 1);
MOZ_ASSERT(IsStructurallyValidLanguageTag(span));
mLanguage.Set(span);
language_.set(span);
}
/**
* Set the language subtag. The input must be a valid language subtag.
*/
void SetLanguage(const LanguageSubtag& aLanguage) {
MOZ_ASSERT(IsStructurallyValidLanguageTag(aLanguage.Span()));
mLanguage.Set(aLanguage.Span());
void setLanguage(const LanguageSubtag& language) {
MOZ_ASSERT(IsStructurallyValidLanguageTag(language.span()));
language_.set(language.span());
}
/**
* Set the script subtag. The input must be a valid script subtag.
*/
template <size_t N>
void SetScript(const char (&aScript)[N]) {
mozilla::Span<const char> span(aScript, N - 1);
void setScript(const char (&script)[N]) {
mozilla::Span<const char> span(script, N - 1);
MOZ_ASSERT(IsStructurallyValidScriptTag(span));
mScript.Set(span);
script_.set(span);
}
/**
* Set the script subtag. The input must be a valid script subtag or the empty
* string.
*/
void SetScript(const ScriptSubtag& aScript) {
MOZ_ASSERT(aScript.Missing() ||
IsStructurallyValidScriptTag(aScript.Span()));
mScript.Set(aScript.Span());
void setScript(const ScriptSubtag& script) {
MOZ_ASSERT(script.missing() || IsStructurallyValidScriptTag(script.span()));
script_.set(script.span());
}
/**
* Set the region subtag. The input must be a valid region subtag.
*/
template <size_t N>
void SetRegion(const char (&aRegion)[N]) {
mozilla::Span<const char> span(aRegion, N - 1);
void setRegion(const char (&region)[N]) {
mozilla::Span<const char> span(region, N - 1);
MOZ_ASSERT(IsStructurallyValidRegionTag(span));
mRegion.Set(span);
region_.set(span);
}
/**
* Set the region subtag. The input must be a valid region subtag or the empty
* empty string.
*/
void SetRegion(const RegionSubtag& aRegion) {
MOZ_ASSERT(aRegion.Missing() ||
IsStructurallyValidRegionTag(aRegion.Span()));
mRegion.Set(aRegion.Span());
void setRegion(const RegionSubtag& region) {
MOZ_ASSERT(region.missing() || IsStructurallyValidRegionTag(region.span()));
region_.set(region.span());
}
/**
* Removes all variant subtags.
*/
void ClearVariants() { mVariants.clearAndFree(); }
void clearVariants() { variants_.clearAndFree(); }
/**
* Set the Unicode extension subtag. The input must be a valid Unicode
* extension subtag.
*/
ICUResult SetUnicodeExtension(Span<const char> aExtension);
ICUResult setUnicodeExtension(Span<const char> extension);
/**
* Remove any Unicode extension subtag if present.
*/
void ClearUnicodeExtension();
void clearUnicodeExtension();
/** Canonicalize the base-name (language, script, region, variant) subtags. */
Result<Ok, CanonicalizationError> CanonicalizeBaseName();
Result<Ok, CanonicalizationError> canonicalizeBaseName();
/**
* Canonicalize all extension subtags.
*/
Result<Ok, CanonicalizationError> CanonicalizeExtensions();
Result<Ok, CanonicalizationError> canonicalizeExtensions();
/**
* Canonicalizes the given structurally valid Unicode BCP 47 locale
@ -426,29 +423,29 @@ class MOZ_STACK_CLASS Locale final {
*
* Spec: ECMAScript Internationalization API Specification, 6.2.3.
*/
Result<Ok, CanonicalizationError> Canonicalize() {
MOZ_TRY(CanonicalizeBaseName());
return CanonicalizeExtensions();
Result<Ok, CanonicalizationError> canonicalize() {
MOZ_TRY(canonicalizeBaseName());
return canonicalizeExtensions();
}
/**
* Fill the buffer with a string representation of the locale.
*/
template <typename B>
ICUResult ToString(B& aBuffer) const {
ICUResult toString(B& buffer) const {
static_assert(std::is_same_v<typename B::CharType, char>);
size_t capacity = ToStringCapacity();
size_t capacity = toStringCapacity();
// Attempt to reserve needed capacity
if (!aBuffer.reserve(capacity)) {
if (!buffer.reserve(capacity)) {
return Err(ICUError::OutOfMemory);
}
size_t offset = ToStringAppend(aBuffer.data());
size_t offset = toStringAppend(buffer.data());
MOZ_ASSERT(capacity == offset);
aBuffer.written(offset);
buffer.written(offset);
return Ok();
}
@ -458,14 +455,14 @@ class MOZ_STACK_CLASS Locale final {
*
* Spec: <https://www.unicode.org/reports/tr35/#Likely_Subtags>
*/
ICUResult AddLikelySubtags();
ICUResult addLikelySubtags();
/**
* Remove likely-subtags from the locale.
*
* Spec: <https://www.unicode.org/reports/tr35/#Likely_Subtags>
*/
ICUResult RemoveLikelySubtags();
ICUResult removeLikelySubtags();
/**
* Returns the default locale as an ICU locale identifier. The returned string
@ -489,10 +486,10 @@ class MOZ_STACK_CLASS Locale final {
}
private:
static UniqueChars DuplicateStringToUniqueChars(const char* aStr);
static UniqueChars DuplicateStringToUniqueChars(Span<const char> aStr);
size_t ToStringCapacity() const;
size_t ToStringAppend(char* aBuffer) const;
static UniqueChars DuplicateStringToUniqueChars(const char* s);
static UniqueChars DuplicateStringToUniqueChars(Span<const char> s);
size_t toStringCapacity() const;
size_t toStringAppend(char* buffer) const;
};
/**
@ -520,89 +517,89 @@ class MOZ_STACK_CLASS LocaleParser final {
private:
class Token final {
size_t mIndex;
size_t mLength;
TokenKind mKind;
size_t index_;
size_t length_;
TokenKind kind_;
public:
Token(TokenKind aKind, size_t aIndex, size_t aLength)
: mIndex(aIndex), mLength(aLength), mKind(aKind) {}
Token(TokenKind kind, size_t index, size_t length)
: index_(index), length_(length), kind_(kind) {}
TokenKind Kind() const { return mKind; }
size_t Index() const { return mIndex; }
size_t Length() const { return mLength; }
TokenKind kind() const { return kind_; }
size_t index() const { return index_; }
size_t length() const { return length_; }
bool IsError() const { return mKind == TokenKind::Error; }
bool IsNone() const { return mKind == TokenKind::None; }
bool IsAlpha() const { return mKind == TokenKind::Alpha; }
bool IsDigit() const { return mKind == TokenKind::Digit; }
bool IsAlphaDigit() const { return mKind == TokenKind::AlphaDigit; }
bool isError() const { return kind_ == TokenKind::Error; }
bool isNone() const { return kind_ == TokenKind::None; }
bool isAlpha() const { return kind_ == TokenKind::Alpha; }
bool isDigit() const { return kind_ == TokenKind::Digit; }
bool isAlphaDigit() const { return kind_ == TokenKind::AlphaDigit; }
};
const char* mLocale;
size_t mLength;
size_t mIndex = 0;
const char* locale_;
size_t length_;
size_t index_ = 0;
explicit LocaleParser(Span<const char> aLocale)
: mLocale(aLocale.data()), mLength(aLocale.size()) {}
explicit LocaleParser(Span<const char> locale)
: locale_(locale.data()), length_(locale.size()) {}
char CharAt(size_t aIndex) const { return mLocale[aIndex]; }
char charAt(size_t index) const { return locale_[index]; }
// Copy the token characters into |subtag|.
template <size_t N>
void CopyChars(const Token& aTok, LanguageTagSubtag<N>& aSubtag) const {
aSubtag.Set(mozilla::Span(mLocale + aTok.Index(), aTok.Length()));
void copyChars(const Token& tok, LanguageTagSubtag<N>& subtag) const {
subtag.set(mozilla::Span(locale_ + tok.index(), tok.length()));
}
// Create a string copy of |length| characters starting at |index|.
UniqueChars Chars(size_t aIndex, size_t aLength) const;
UniqueChars chars(size_t index, size_t length) const;
// Create a string copy of the token characters.
UniqueChars Chars(const Token& aTok) const {
return Chars(aTok.Index(), aTok.Length());
UniqueChars chars(const Token& tok) const {
return chars(tok.index(), tok.length());
}
UniqueChars Extension(const Token& aStart, const Token& aEnd) const {
MOZ_ASSERT(aStart.Index() < aEnd.Index());
UniqueChars extension(const Token& start, const Token& end) const {
MOZ_ASSERT(start.index() < end.index());
size_t length = aEnd.Index() - 1 - aStart.Index();
return Chars(aStart.Index(), length);
size_t length = end.index() - 1 - start.index();
return chars(start.index(), length);
}
Token NextToken();
Token nextToken();
// unicode_language_subtag = alpha{2,3} | alpha{5,8} ;
//
// Four character language subtags are not allowed in Unicode BCP 47 locale
// identifiers. Also see the comparison to Unicode CLDR locale identifiers in
// <https://unicode.org/reports/tr35/#BCP_47_Conformance>.
bool IsLanguage(const Token& aTok) const {
return aTok.IsAlpha() && ((2 <= aTok.Length() && aTok.Length() <= 3) ||
(5 <= aTok.Length() && aTok.Length() <= 8));
bool isLanguage(const Token& tok) const {
return tok.isAlpha() && ((2 <= tok.length() && tok.length() <= 3) ||
(5 <= tok.length() && tok.length() <= 8));
}
// unicode_script_subtag = alpha{4} ;
bool IsScript(const Token& aTok) const {
return aTok.IsAlpha() && aTok.Length() == 4;
bool isScript(const Token& tok) const {
return tok.isAlpha() && tok.length() == 4;
}
// unicode_region_subtag = (alpha{2} | digit{3}) ;
bool IsRegion(const Token& aTok) const {
return (aTok.IsAlpha() && aTok.Length() == 2) ||
(aTok.IsDigit() && aTok.Length() == 3);
bool isRegion(const Token& tok) const {
return (tok.isAlpha() && tok.length() == 2) ||
(tok.isDigit() && tok.length() == 3);
}
// unicode_variant_subtag = (alphanum{5,8} | digit alphanum{3}) ;
bool IsVariant(const Token& aTok) const {
return (5 <= aTok.Length() && aTok.Length() <= 8) ||
(aTok.Length() == 4 && mozilla::IsAsciiDigit(CharAt(aTok.Index())));
bool isVariant(const Token& tok) const {
return (5 <= tok.length() && tok.length() <= 8) ||
(tok.length() == 4 && mozilla::IsAsciiDigit(charAt(tok.index())));
}
// Returns the code unit of the first character at the given singleton token.
// Always returns the lower case form of an alphabetical character.
char SingletonKey(const Token& aTok) const {
MOZ_ASSERT(aTok.Length() == 1);
return AsciiToLowerCase(CharAt(aTok.Index()));
char singletonKey(const Token& tok) const {
MOZ_ASSERT(tok.length() == 1);
return AsciiToLowerCase(charAt(tok.index()));
}
// extensions = unicode_locale_extensions |
@ -616,71 +613,70 @@ class MOZ_STACK_CLASS LocaleParser final {
// (sep tfield)+) ;
//
// other_extensions = sep [alphanum-[tTuUxX]] (sep alphanum{2,8})+ ;
bool IsExtensionStart(const Token& aTok) const {
return aTok.Length() == 1 && SingletonKey(aTok) != 'x';
bool isExtensionStart(const Token& tok) const {
return tok.length() == 1 && singletonKey(tok) != 'x';
}
// other_extensions = sep [alphanum-[tTuUxX]] (sep alphanum{2,8})+ ;
bool IsOtherExtensionPart(const Token& aTok) const {
return 2 <= aTok.Length() && aTok.Length() <= 8;
bool isOtherExtensionPart(const Token& tok) const {
return 2 <= tok.length() && tok.length() <= 8;
}
// unicode_locale_extensions = sep [uU] ((sep keyword)+ |
// (sep attribute)+ (sep keyword)*) ;
// keyword = key (sep type)? ;
bool IsUnicodeExtensionPart(const Token& aTok) const {
return IsUnicodeExtensionKey(aTok) || IsUnicodeExtensionType(aTok) ||
IsUnicodeExtensionAttribute(aTok);
bool isUnicodeExtensionPart(const Token& tok) const {
return isUnicodeExtensionKey(tok) || isUnicodeExtensionType(tok) ||
isUnicodeExtensionAttribute(tok);
}
// attribute = alphanum{3,8} ;
bool IsUnicodeExtensionAttribute(const Token& aTok) const {
return 3 <= aTok.Length() && aTok.Length() <= 8;
bool isUnicodeExtensionAttribute(const Token& tok) const {
return 3 <= tok.length() && tok.length() <= 8;
}
// key = alphanum alpha ;
bool IsUnicodeExtensionKey(const Token& aTok) const {
return aTok.Length() == 2 &&
mozilla::IsAsciiAlpha(CharAt(aTok.Index() + 1));
bool isUnicodeExtensionKey(const Token& tok) const {
return tok.length() == 2 && mozilla::IsAsciiAlpha(charAt(tok.index() + 1));
}
// type = alphanum{3,8} (sep alphanum{3,8})* ;
bool IsUnicodeExtensionType(const Token& aTok) const {
return 3 <= aTok.Length() && aTok.Length() <= 8;
bool isUnicodeExtensionType(const Token& tok) const {
return 3 <= tok.length() && tok.length() <= 8;
}
// tkey = alpha digit ;
bool IsTransformExtensionKey(const Token& aTok) const {
return aTok.Length() == 2 && mozilla::IsAsciiAlpha(CharAt(aTok.Index())) &&
mozilla::IsAsciiDigit(CharAt(aTok.Index() + 1));
bool isTransformExtensionKey(const Token& tok) const {
return tok.length() == 2 && mozilla::IsAsciiAlpha(charAt(tok.index())) &&
mozilla::IsAsciiDigit(charAt(tok.index() + 1));
}
// tvalue = (sep alphanum{3,8})+ ;
bool IsTransformExtensionPart(const Token& aTok) const {
return 3 <= aTok.Length() && aTok.Length() <= 8;
bool isTransformExtensionPart(const Token& tok) const {
return 3 <= tok.length() && tok.length() <= 8;
}
// pu_extensions = sep [xX] (sep alphanum{1,8})+ ;
bool IsPrivateUseStart(const Token& aTok) const {
return aTok.Length() == 1 && SingletonKey(aTok) == 'x';
bool isPrivateUseStart(const Token& tok) const {
return tok.length() == 1 && singletonKey(tok) == 'x';
}
// pu_extensions = sep [xX] (sep alphanum{1,8})+ ;
bool IsPrivateUsePart(const Token& aTok) const {
return 1 <= aTok.Length() && aTok.Length() <= 8;
bool isPrivateUsePart(const Token& tok) const {
return 1 <= tok.length() && tok.length() <= 8;
}
// Helper function for use in |ParseBaseName| and
// |ParseTlangInTransformExtension|. Do not use this directly!
static Result<Ok, ParserError> InternalParseBaseName(
LocaleParser& aLocaleParser, Locale& aTag, Token& aTok);
// Helper function for use in |parseBaseName| and
// |parseTlangInTransformExtension|. Do not use this directly!
static Result<Ok, ParserError> internalParseBaseName(LocaleParser& ts,
Locale& tag, Token& tok);
// Parse the `unicode_language_id` production, i.e. the
// language/script/region/variants portion of a locale, into |aTag|.
// |aTok| must be the current token.
static Result<Ok, ParserError> ParseBaseName(LocaleParser& aLocaleParser,
Locale& aTag, Token& aTok) {
return InternalParseBaseName(aLocaleParser, aTag, aTok);
// language/script/region/variants portion of a locale, into |tag|.
// |tok| must be the current token.
static Result<Ok, ParserError> parseBaseName(LocaleParser& ts, Locale& tag,
Token& tok) {
return internalParseBaseName(ts, tag, tok);
}
// Parse the `tlang` production within a parsed 't' transform extension.
@ -695,23 +691,23 @@ class MOZ_STACK_CLASS LocaleParser final {
// there was no `tlang`, then |tag.language().missing()|. But if there was a
// `tlang`, then |tag| is filled with subtags exactly as they appeared in the
// parse input.
static Result<Ok, ParserError> ParseTlangInTransformExtension(
LocaleParser& aLocaleParser, Locale& aTag, Token& aTok) {
MOZ_ASSERT(aLocaleParser.IsLanguage(aTok));
return InternalParseBaseName(aLocaleParser, aTag, aTok);
static Result<Ok, ParserError> parseTlangInTransformExtension(
LocaleParser& ts, Locale& tag, Token& tok) {
MOZ_ASSERT(ts.isLanguage(tok));
return internalParseBaseName(ts, tag, tok);
}
friend class Locale;
class Range final {
size_t mBegin;
size_t mLength;
size_t begin_;
size_t length_;
public:
Range(size_t aBegin, size_t aLength) : mBegin(aBegin), mLength(aLength) {}
Range(size_t begin, size_t length) : begin_(begin), length_(length) {}
size_t Begin() const { return mBegin; }
size_t Length() const { return mLength; }
size_t begin() const { return begin_; }
size_t length() const { return length_; }
};
using TFieldVector = Vector<Range, 8>;
@ -722,34 +718,32 @@ class MOZ_STACK_CLASS LocaleParser final {
// `transformed_extensions` subtag, and fill |tag| and |fields| from the
// `tlang` and `tfield` components. Data in |tag| is lowercase, consistent
// with |extension|.
static Result<Ok, ParserError> ParseTransformExtension(
mozilla::Span<const char> aExtension, Locale& aTag,
TFieldVector& aFields);
static Result<Ok, ParserError> parseTransformExtension(
mozilla::Span<const char> extension, Locale& tag, TFieldVector& fields);
// Parse |extension|, which must be a validated, fully lowercase
// `unicode_locale_extensions` subtag, and fill |attributes| and |keywords|
// from the `attribute` and `keyword` components.
static Result<Ok, ParserError> ParseUnicodeExtension(
mozilla::Span<const char> aExtension, AttributesVector& aAttributes,
KeywordsVector& aKeywords);
static Result<Ok, ParserError> parseUnicodeExtension(
mozilla::Span<const char> extension, AttributesVector& attributes,
KeywordsVector& keywords);
public:
// Parse the input string as a locale.
static Result<Ok, ParserError> TryParse(Span<const char> aLocale,
Locale& aTag);
static Result<Ok, ParserError> tryParse(Span<const char> locale, Locale& tag);
// Parse the input string as the base-name parts (language, script, region,
// variants) of a locale.
static Result<Ok, ParserError> TryParseBaseName(Span<const char> aLocale,
Locale& aTag);
static Result<Ok, ParserError> tryParseBaseName(Span<const char> locale,
Locale& tag);
// Return Ok() iff |extension| can be parsed as a Unicode extension subtag.
static Result<Ok, ParserError> CanParseUnicodeExtension(
Span<const char> aExtension);
static Result<Ok, ParserError> canParseUnicodeExtension(
Span<const char> extension);
// Return Ok() iff |unicodeType| can be parsed as a Unicode extension type.
static Result<Ok, ParserError> CanParseUnicodeExtensionType(
Span<const char> aUnicodeType);
static Result<Ok, ParserError> canParseUnicodeExtensionType(
Span<const char> unicodeType);
};
MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(LocaleParser::TokenKind)

View File

@ -21,10 +21,10 @@ template <size_t Length, size_t TagLength, size_t SubtagLength>
static inline bool HasReplacement(
const char (&subtags)[Length][TagLength],
const mozilla::intl::LanguageTagSubtag<SubtagLength>& subtag) {
MOZ_ASSERT(subtag.Length() == TagLength - 1,
MOZ_ASSERT(subtag.length() == TagLength - 1,
"subtag must have the same length as the list of subtags");
const char* ptr = subtag.Span().data();
const char* ptr = subtag.span().data();
return std::binary_search(std::begin(subtags), std::end(subtags), ptr,
[](const char* a, const char* b) {
return memcmp(a, b, TagLength - 1) < 0;
@ -35,10 +35,10 @@ template <size_t Length, size_t TagLength, size_t SubtagLength>
static inline const char* SearchReplacement(
const char (&subtags)[Length][TagLength], const char* (&aliases)[Length],
const mozilla::intl::LanguageTagSubtag<SubtagLength>& subtag) {
MOZ_ASSERT(subtag.Length() == TagLength - 1,
MOZ_ASSERT(subtag.length() == TagLength - 1,
"subtag must have the same length as the list of subtags");
const char* ptr = subtag.Span().data();
const char* ptr = subtag.span().data();
auto p = std::lower_bound(std::begin(subtags), std::end(subtags), ptr,
[](const char* a, const char* b) {
return memcmp(a, b, TagLength - 1) < 0;
@ -101,11 +101,11 @@ static bool IsCanonicallyCasedTransformType(mozilla::Span<const char> type) {
// Mappings from language subtags to preferred values.
// Derived from CLDR Supplemental Data, version 40.
// https://unicode.org/Public/cldr/40/core.zip
bool mozilla::intl::Locale::LanguageMapping(LanguageSubtag& language) {
MOZ_ASSERT(IsStructurallyValidLanguageTag(language.Span()));
MOZ_ASSERT(IsCanonicallyCasedLanguageTag(language.Span()));
bool mozilla::intl::Locale::languageMapping(LanguageSubtag& language) {
MOZ_ASSERT(IsStructurallyValidLanguageTag(language.span()));
MOZ_ASSERT(IsCanonicallyCasedLanguageTag(language.span()));
if (language.Length() == 2) {
if (language.length() == 2) {
static const char languages[8][3] = {
"bh", "in", "iw", "ji", "jw", "mo", "tl", "tw",
};
@ -114,13 +114,13 @@ bool mozilla::intl::Locale::LanguageMapping(LanguageSubtag& language) {
};
if (const char* replacement = SearchReplacement(languages, aliases, language)) {
language.Set(mozilla::MakeStringSpan(replacement));
language.set(mozilla::MakeStringSpan(replacement));
return true;
}
return false;
}
if (language.Length() == 3) {
if (language.length() == 3) {
static const char languages[404][4] = {
"aam", "aar", "abk", "adp", "afr", "agp", "ais", "aju", "aka", "alb",
"als", "amh", "ara", "arb", "arg", "arm", "asd", "asm", "aue", "ava",
@ -209,7 +209,7 @@ bool mozilla::intl::Locale::LanguageMapping(LanguageSubtag& language) {
};
if (const char* replacement = SearchReplacement(languages, aliases, language)) {
language.Set(mozilla::MakeStringSpan(replacement));
language.set(mozilla::MakeStringSpan(replacement));
return true;
}
return false;
@ -221,15 +221,15 @@ bool mozilla::intl::Locale::LanguageMapping(LanguageSubtag& language) {
// Language subtags with complex mappings.
// Derived from CLDR Supplemental Data, version 40.
// https://unicode.org/Public/cldr/40/core.zip
bool mozilla::intl::Locale::ComplexLanguageMapping(const LanguageSubtag& language) {
MOZ_ASSERT(IsStructurallyValidLanguageTag(language.Span()));
MOZ_ASSERT(IsCanonicallyCasedLanguageTag(language.Span()));
bool mozilla::intl::Locale::complexLanguageMapping(const LanguageSubtag& language) {
MOZ_ASSERT(IsStructurallyValidLanguageTag(language.span()));
MOZ_ASSERT(IsCanonicallyCasedLanguageTag(language.span()));
if (language.Length() == 2) {
return language.EqualTo("sh");
if (language.length() == 2) {
return language.equalTo("sh");
}
if (language.Length() == 3) {
if (language.length() == 3) {
static const char languages[6][4] = {
"cnr", "drw", "hbs", "prs", "swc", "tnf",
};
@ -243,13 +243,13 @@ bool mozilla::intl::Locale::ComplexLanguageMapping(const LanguageSubtag& languag
// Mappings from script subtags to preferred values.
// Derived from CLDR Supplemental Data, version 40.
// https://unicode.org/Public/cldr/40/core.zip
bool mozilla::intl::Locale::ScriptMapping(ScriptSubtag& script) {
MOZ_ASSERT(IsStructurallyValidScriptTag(script.Span()));
MOZ_ASSERT(IsCanonicallyCasedScriptTag(script.Span()));
bool mozilla::intl::Locale::scriptMapping(ScriptSubtag& script) {
MOZ_ASSERT(IsStructurallyValidScriptTag(script.span()));
MOZ_ASSERT(IsCanonicallyCasedScriptTag(script.span()));
{
if (script.EqualTo("Qaai")) {
script.Set(mozilla::MakeStringSpan("Zinh"));
if (script.equalTo("Qaai")) {
script.set(mozilla::MakeStringSpan("Zinh"));
return true;
}
return false;
@ -259,11 +259,11 @@ bool mozilla::intl::Locale::ScriptMapping(ScriptSubtag& script) {
// Mappings from region subtags to preferred values.
// Derived from CLDR Supplemental Data, version 40.
// https://unicode.org/Public/cldr/40/core.zip
bool mozilla::intl::Locale::RegionMapping(RegionSubtag& region) {
MOZ_ASSERT(IsStructurallyValidRegionTag(region.Span()));
MOZ_ASSERT(IsCanonicallyCasedRegionTag(region.Span()));
bool mozilla::intl::Locale::regionMapping(RegionSubtag& region) {
MOZ_ASSERT(IsStructurallyValidRegionTag(region.span()));
MOZ_ASSERT(IsCanonicallyCasedRegionTag(region.span()));
if (region.Length() == 2) {
if (region.length() == 2) {
static const char regions[23][3] = {
"BU", "CS", "CT", "DD", "DY", "FQ", "FX", "HV", "JT", "MI",
"NH", "NQ", "PU", "PZ", "QU", "RH", "TP", "UK", "VD", "WK",
@ -276,7 +276,7 @@ bool mozilla::intl::Locale::RegionMapping(RegionSubtag& region) {
};
if (const char* replacement = SearchReplacement(regions, aliases, region)) {
region.Set(mozilla::MakeStringSpan(replacement));
region.set(mozilla::MakeStringSpan(replacement));
return true;
}
return false;
@ -349,7 +349,7 @@ bool mozilla::intl::Locale::RegionMapping(RegionSubtag& region) {
};
if (const char* replacement = SearchReplacement(regions, aliases, region)) {
region.Set(mozilla::MakeStringSpan(replacement));
region.set(mozilla::MakeStringSpan(replacement));
return true;
}
return false;
@ -359,15 +359,15 @@ bool mozilla::intl::Locale::RegionMapping(RegionSubtag& region) {
// Region subtags with complex mappings.
// Derived from CLDR Supplemental Data, version 40.
// https://unicode.org/Public/cldr/40/core.zip
bool mozilla::intl::Locale::ComplexRegionMapping(const RegionSubtag& region) {
MOZ_ASSERT(IsStructurallyValidRegionTag(region.Span()));
MOZ_ASSERT(IsCanonicallyCasedRegionTag(region.Span()));
bool mozilla::intl::Locale::complexRegionMapping(const RegionSubtag& region) {
MOZ_ASSERT(IsStructurallyValidRegionTag(region.span()));
MOZ_ASSERT(IsCanonicallyCasedRegionTag(region.span()));
if (region.Length() == 2) {
return region.EqualTo("AN") ||
region.EqualTo("NT") ||
region.EqualTo("PC") ||
region.EqualTo("SU");
if (region.length() == 2) {
return region.equalTo("AN") ||
region.equalTo("NT") ||
region.equalTo("PC") ||
region.equalTo("SU");
}
{
@ -382,35 +382,35 @@ bool mozilla::intl::Locale::ComplexRegionMapping(const RegionSubtag& region) {
// Language subtags with complex mappings.
// Derived from CLDR Supplemental Data, version 40.
// https://unicode.org/Public/cldr/40/core.zip
void mozilla::intl::Locale::PerformComplexLanguageMappings() {
MOZ_ASSERT(IsStructurallyValidLanguageTag(Language().Span()));
MOZ_ASSERT(IsCanonicallyCasedLanguageTag(Language().Span()));
void mozilla::intl::Locale::performComplexLanguageMappings() {
MOZ_ASSERT(IsStructurallyValidLanguageTag(language().span()));
MOZ_ASSERT(IsCanonicallyCasedLanguageTag(language().span()));
if (Language().EqualTo("cnr")) {
SetLanguage("sr");
if (Region().Missing()) {
SetRegion("ME");
if (language().equalTo("cnr")) {
setLanguage("sr");
if (region().missing()) {
setRegion("ME");
}
}
else if (Language().EqualTo("drw") ||
Language().EqualTo("prs") ||
Language().EqualTo("tnf")) {
SetLanguage("fa");
if (Region().Missing()) {
SetRegion("AF");
else if (language().equalTo("drw") ||
language().equalTo("prs") ||
language().equalTo("tnf")) {
setLanguage("fa");
if (region().missing()) {
setRegion("AF");
}
}
else if (Language().EqualTo("hbs") ||
Language().EqualTo("sh")) {
SetLanguage("sr");
if (Script().Missing()) {
SetScript("Latn");
else if (language().equalTo("hbs") ||
language().equalTo("sh")) {
setLanguage("sr");
if (script().missing()) {
setScript("Latn");
}
}
else if (Language().EqualTo("swc")) {
SetLanguage("sw");
if (Region().Missing()) {
SetRegion("CD");
else if (language().equalTo("swc")) {
setLanguage("sw");
if (region().missing()) {
setRegion("CD");
}
}
}
@ -418,213 +418,213 @@ void mozilla::intl::Locale::PerformComplexLanguageMappings() {
// Region subtags with complex mappings.
// Derived from CLDR Supplemental Data, version 40.
// https://unicode.org/Public/cldr/40/core.zip
void mozilla::intl::Locale::PerformComplexRegionMappings() {
MOZ_ASSERT(IsStructurallyValidLanguageTag(Language().Span()));
MOZ_ASSERT(IsCanonicallyCasedLanguageTag(Language().Span()));
MOZ_ASSERT(IsStructurallyValidRegionTag(Region().Span()));
MOZ_ASSERT(IsCanonicallyCasedRegionTag(Region().Span()));
void mozilla::intl::Locale::performComplexRegionMappings() {
MOZ_ASSERT(IsStructurallyValidLanguageTag(language().span()));
MOZ_ASSERT(IsCanonicallyCasedLanguageTag(language().span()));
MOZ_ASSERT(IsStructurallyValidRegionTag(region().span()));
MOZ_ASSERT(IsCanonicallyCasedRegionTag(region().span()));
if (Region().EqualTo("062")) {
if (Language().EqualTo("oui") ||
(Language().EqualTo("und") && Script().EqualTo("Ougr"))) {
SetRegion("143");
if (region().equalTo("062")) {
if (language().equalTo("oui") ||
(language().equalTo("und") && script().equalTo("Ougr"))) {
setRegion("143");
}
else {
SetRegion("034");
setRegion("034");
}
}
else if (Region().EqualTo("172")) {
if (Language().EqualTo("hy") ||
(Language().EqualTo("und") && Script().EqualTo("Armn"))) {
SetRegion("AM");
else if (region().equalTo("172")) {
if (language().equalTo("hy") ||
(language().equalTo("und") && script().equalTo("Armn"))) {
setRegion("AM");
}
else if (Language().EqualTo("az") ||
Language().EqualTo("tkr") ||
Language().EqualTo("tly") ||
Language().EqualTo("ttt")) {
SetRegion("AZ");
else if (language().equalTo("az") ||
language().equalTo("tkr") ||
language().equalTo("tly") ||
language().equalTo("ttt")) {
setRegion("AZ");
}
else if (Language().EqualTo("be")) {
SetRegion("BY");
else if (language().equalTo("be")) {
setRegion("BY");
}
else if (Language().EqualTo("ab") ||
Language().EqualTo("ka") ||
(Language().EqualTo("ku") && Script().EqualTo("Yezi")) ||
Language().EqualTo("os") ||
(Language().EqualTo("und") && Script().EqualTo("Geor")) ||
(Language().EqualTo("und") && Script().EqualTo("Yezi")) ||
Language().EqualTo("xmf")) {
SetRegion("GE");
else if (language().equalTo("ab") ||
language().equalTo("ka") ||
(language().equalTo("ku") && script().equalTo("Yezi")) ||
language().equalTo("os") ||
(language().equalTo("und") && script().equalTo("Geor")) ||
(language().equalTo("und") && script().equalTo("Yezi")) ||
language().equalTo("xmf")) {
setRegion("GE");
}
else if (Language().EqualTo("ky")) {
SetRegion("KG");
else if (language().equalTo("ky")) {
setRegion("KG");
}
else if (Language().EqualTo("kk") ||
(Language().EqualTo("ug") && Script().EqualTo("Cyrl"))) {
SetRegion("KZ");
else if (language().equalTo("kk") ||
(language().equalTo("ug") && script().equalTo("Cyrl"))) {
setRegion("KZ");
}
else if (Language().EqualTo("gag")) {
SetRegion("MD");
else if (language().equalTo("gag")) {
setRegion("MD");
}
else if (Language().EqualTo("tg")) {
SetRegion("TJ");
else if (language().equalTo("tg")) {
setRegion("TJ");
}
else if (Language().EqualTo("tk")) {
SetRegion("TM");
else if (language().equalTo("tk")) {
setRegion("TM");
}
else if (Language().EqualTo("crh") ||
Language().EqualTo("got") ||
Language().EqualTo("ji") ||
Language().EqualTo("rue") ||
Language().EqualTo("uk") ||
(Language().EqualTo("und") && Script().EqualTo("Goth"))) {
SetRegion("UA");
else if (language().equalTo("crh") ||
language().equalTo("got") ||
language().equalTo("ji") ||
language().equalTo("rue") ||
language().equalTo("uk") ||
(language().equalTo("und") && script().equalTo("Goth"))) {
setRegion("UA");
}
else if (Language().EqualTo("kaa") ||
Language().EqualTo("sog") ||
(Language().EqualTo("und") && Script().EqualTo("Chrs")) ||
(Language().EqualTo("und") && Script().EqualTo("Sogd")) ||
(Language().EqualTo("und") && Script().EqualTo("Sogo")) ||
Language().EqualTo("uz") ||
Language().EqualTo("xco")) {
SetRegion("UZ");
else if (language().equalTo("kaa") ||
language().equalTo("sog") ||
(language().equalTo("und") && script().equalTo("Chrs")) ||
(language().equalTo("und") && script().equalTo("Sogd")) ||
(language().equalTo("und") && script().equalTo("Sogo")) ||
language().equalTo("uz") ||
language().equalTo("xco")) {
setRegion("UZ");
}
else {
SetRegion("RU");
setRegion("RU");
}
}
else if (Region().EqualTo("200")) {
if (Language().EqualTo("sk")) {
SetRegion("SK");
else if (region().equalTo("200")) {
if (language().equalTo("sk")) {
setRegion("SK");
}
else {
SetRegion("CZ");
setRegion("CZ");
}
}
else if (Region().EqualTo("530") ||
Region().EqualTo("532") ||
Region().EqualTo("AN")) {
if (Language().EqualTo("vic")) {
SetRegion("SX");
else if (region().equalTo("530") ||
region().equalTo("532") ||
region().equalTo("AN")) {
if (language().equalTo("vic")) {
setRegion("SX");
}
else {
SetRegion("CW");
setRegion("CW");
}
}
else if (Region().EqualTo("536") ||
Region().EqualTo("NT")) {
if (Language().EqualTo("akk") ||
Language().EqualTo("ckb") ||
(Language().EqualTo("ku") && Script().EqualTo("Arab")) ||
Language().EqualTo("syr") ||
(Language().EqualTo("und") && Script().EqualTo("Syrc")) ||
(Language().EqualTo("und") && Script().EqualTo("Xsux"))) {
SetRegion("IQ");
else if (region().equalTo("536") ||
region().equalTo("NT")) {
if (language().equalTo("akk") ||
language().equalTo("ckb") ||
(language().equalTo("ku") && script().equalTo("Arab")) ||
language().equalTo("syr") ||
(language().equalTo("und") && script().equalTo("Syrc")) ||
(language().equalTo("und") && script().equalTo("Xsux"))) {
setRegion("IQ");
}
else {
SetRegion("SA");
setRegion("SA");
}
}
else if (Region().EqualTo("582") ||
Region().EqualTo("PC")) {
if (Language().EqualTo("mh")) {
SetRegion("MH");
else if (region().equalTo("582") ||
region().equalTo("PC")) {
if (language().equalTo("mh")) {
setRegion("MH");
}
else if (Language().EqualTo("pau")) {
SetRegion("PW");
else if (language().equalTo("pau")) {
setRegion("PW");
}
else {
SetRegion("FM");
setRegion("FM");
}
}
else if (Region().EqualTo("810") ||
Region().EqualTo("SU")) {
if (Language().EqualTo("hy") ||
(Language().EqualTo("und") && Script().EqualTo("Armn"))) {
SetRegion("AM");
else if (region().equalTo("810") ||
region().equalTo("SU")) {
if (language().equalTo("hy") ||
(language().equalTo("und") && script().equalTo("Armn"))) {
setRegion("AM");
}
else if (Language().EqualTo("az") ||
Language().EqualTo("tkr") ||
Language().EqualTo("tly") ||
Language().EqualTo("ttt")) {
SetRegion("AZ");
else if (language().equalTo("az") ||
language().equalTo("tkr") ||
language().equalTo("tly") ||
language().equalTo("ttt")) {
setRegion("AZ");
}
else if (Language().EqualTo("be")) {
SetRegion("BY");
else if (language().equalTo("be")) {
setRegion("BY");
}
else if (Language().EqualTo("et") ||
Language().EqualTo("vro")) {
SetRegion("EE");
else if (language().equalTo("et") ||
language().equalTo("vro")) {
setRegion("EE");
}
else if (Language().EqualTo("ab") ||
Language().EqualTo("ka") ||
(Language().EqualTo("ku") && Script().EqualTo("Yezi")) ||
Language().EqualTo("os") ||
(Language().EqualTo("und") && Script().EqualTo("Geor")) ||
(Language().EqualTo("und") && Script().EqualTo("Yezi")) ||
Language().EqualTo("xmf")) {
SetRegion("GE");
else if (language().equalTo("ab") ||
language().equalTo("ka") ||
(language().equalTo("ku") && script().equalTo("Yezi")) ||
language().equalTo("os") ||
(language().equalTo("und") && script().equalTo("Geor")) ||
(language().equalTo("und") && script().equalTo("Yezi")) ||
language().equalTo("xmf")) {
setRegion("GE");
}
else if (Language().EqualTo("ky")) {
SetRegion("KG");
else if (language().equalTo("ky")) {
setRegion("KG");
}
else if (Language().EqualTo("kk") ||
(Language().EqualTo("ug") && Script().EqualTo("Cyrl"))) {
SetRegion("KZ");
else if (language().equalTo("kk") ||
(language().equalTo("ug") && script().equalTo("Cyrl"))) {
setRegion("KZ");
}
else if (Language().EqualTo("lt") ||
Language().EqualTo("sgs")) {
SetRegion("LT");
else if (language().equalTo("lt") ||
language().equalTo("sgs")) {
setRegion("LT");
}
else if (Language().EqualTo("ltg") ||
Language().EqualTo("lv")) {
SetRegion("LV");
else if (language().equalTo("ltg") ||
language().equalTo("lv")) {
setRegion("LV");
}
else if (Language().EqualTo("gag")) {
SetRegion("MD");
else if (language().equalTo("gag")) {
setRegion("MD");
}
else if (Language().EqualTo("tg")) {
SetRegion("TJ");
else if (language().equalTo("tg")) {
setRegion("TJ");
}
else if (Language().EqualTo("tk")) {
SetRegion("TM");
else if (language().equalTo("tk")) {
setRegion("TM");
}
else if (Language().EqualTo("crh") ||
Language().EqualTo("got") ||
Language().EqualTo("ji") ||
Language().EqualTo("rue") ||
Language().EqualTo("uk") ||
(Language().EqualTo("und") && Script().EqualTo("Goth"))) {
SetRegion("UA");
else if (language().equalTo("crh") ||
language().equalTo("got") ||
language().equalTo("ji") ||
language().equalTo("rue") ||
language().equalTo("uk") ||
(language().equalTo("und") && script().equalTo("Goth"))) {
setRegion("UA");
}
else if (Language().EqualTo("kaa") ||
Language().EqualTo("sog") ||
(Language().EqualTo("und") && Script().EqualTo("Chrs")) ||
(Language().EqualTo("und") && Script().EqualTo("Sogd")) ||
(Language().EqualTo("und") && Script().EqualTo("Sogo")) ||
Language().EqualTo("uz") ||
Language().EqualTo("xco")) {
SetRegion("UZ");
else if (language().equalTo("kaa") ||
language().equalTo("sog") ||
(language().equalTo("und") && script().equalTo("Chrs")) ||
(language().equalTo("und") && script().equalTo("Sogd")) ||
(language().equalTo("und") && script().equalTo("Sogo")) ||
language().equalTo("uz") ||
language().equalTo("xco")) {
setRegion("UZ");
}
else {
SetRegion("RU");
setRegion("RU");
}
}
else if (Region().EqualTo("890")) {
if (Language().EqualTo("bs")) {
SetRegion("BA");
else if (region().equalTo("890")) {
if (language().equalTo("bs")) {
setRegion("BA");
}
else if (Language().EqualTo("hr")) {
SetRegion("HR");
else if (language().equalTo("hr")) {
setRegion("HR");
}
else if (Language().EqualTo("mk")) {
SetRegion("MK");
else if (language().equalTo("mk")) {
setRegion("MK");
}
else if (Language().EqualTo("sl")) {
SetRegion("SI");
else if (language().equalTo("sl")) {
setRegion("SI");
}
else {
SetRegion("RS");
setRegion("RS");
}
}
}
@ -645,32 +645,32 @@ static bool IsLessThan(const T& a, const U& b) {
// Mappings from variant subtags to preferred values.
// Derived from CLDR Supplemental Data, version 40.
// https://unicode.org/Public/cldr/40/core.zip
bool mozilla::intl::Locale::PerformVariantMappings() {
bool mozilla::intl::Locale::performVariantMappings() {
// The variant subtags need to be sorted for binary search.
MOZ_ASSERT(std::is_sorted(mVariants.begin(), mVariants.end(),
IsLessThan<decltype(mVariants)::ElementType>));
MOZ_ASSERT(std::is_sorted(variants_.begin(), variants_.end(),
IsLessThan<decltype(variants_)::ElementType>));
auto removeVariantAt = [&](size_t index) {
mVariants.erase(mVariants.begin() + index);
variants_.erase(variants_.begin() + index);
};
auto insertVariantSortedIfNotPresent = [&](const char* variant) {
auto* p = std::lower_bound(
mVariants.begin(), mVariants.end(), variant,
IsLessThan<decltype(mVariants)::ElementType, decltype(variant)>);
variants_.begin(), variants_.end(), variant,
IsLessThan<decltype(variants_)::ElementType, decltype(variant)>);
// Don't insert the replacement when already present.
if (p != mVariants.end() && strcmp(p->get(), variant) == 0) {
if (p != variants_.end() && strcmp(p->get(), variant) == 0) {
return true;
}
// Insert the preferred variant in sort order.
auto preferred = DuplicateStringToUniqueChars(variant);
return !!mVariants.insert(p, std::move(preferred));
return !!variants_.insert(p, std::move(preferred));
};
for (size_t i = 0; i < mVariants.length();) {
const char* variant = mVariants[i].get();
for (size_t i = 0; i < variants_.length();) {
const char* variant = variants_[i].get();
MOZ_ASSERT(IsCanonicallyCasedVariantTag(mozilla::MakeStringSpan(variant)));
if (strcmp(variant, "arevela") == 0 ||
@ -685,7 +685,7 @@ bool mozilla::intl::Locale::PerformVariantMappings() {
}
else if (strcmp(variant, "aaland") == 0) {
removeVariantAt(i);
SetRegion("AX");
setRegion("AX");
}
else if (strcmp(variant, "heploc") == 0) {
removeVariantAt(i);
@ -709,7 +709,7 @@ bool mozilla::intl::Locale::PerformVariantMappings() {
// Canonicalize legacy locale identifiers.
// Derived from CLDR Supplemental Data, version 40.
// https://unicode.org/Public/cldr/40/core.zip
bool mozilla::intl::Locale::UpdateLegacyMappings() {
bool mozilla::intl::Locale::updateLegacyMappings() {
// We're mapping legacy tags to non-legacy form here.
// Other tags remain unchanged.
//
@ -717,64 +717,64 @@ bool mozilla::intl::Locale::UpdateLegacyMappings() {
// variant subtags. Therefore we can quickly exclude most tags by checking
// these two subtags.
MOZ_ASSERT(IsCanonicallyCasedLanguageTag(Language().Span()));
MOZ_ASSERT(IsCanonicallyCasedLanguageTag(language().span()));
if (!Language().EqualTo("sgn") && mVariants.length() == 0) {
if (!language().equalTo("sgn") && variants_.length() == 0) {
return true;
}
#ifdef DEBUG
for (const auto& variant : Variants()) {
for (const auto& variant : variants()) {
MOZ_ASSERT(IsStructurallyValidVariantTag(variant));
MOZ_ASSERT(IsCanonicallyCasedVariantTag(variant));
}
#endif
// The variant subtags need to be sorted for binary search.
MOZ_ASSERT(std::is_sorted(mVariants.begin(), mVariants.end(),
IsLessThan<decltype(mVariants)::ElementType>));
MOZ_ASSERT(std::is_sorted(variants_.begin(), variants_.end(),
IsLessThan<decltype(variants_)::ElementType>));
auto findVariant = [this](const char* variant) {
auto* p = std::lower_bound(mVariants.begin(), mVariants.end(), variant,
IsLessThan<decltype(mVariants)::ElementType,
auto* p = std::lower_bound(variants_.begin(), variants_.end(), variant,
IsLessThan<decltype(variants_)::ElementType,
decltype(variant)>);
if (p != mVariants.end() && strcmp(p->get(), variant) == 0) {
if (p != variants_.end() && strcmp(p->get(), variant) == 0) {
return p;
}
return static_cast<decltype(p)>(nullptr);
};
auto insertVariantSortedIfNotPresent = [&](const char* variant) {
auto* p = std::lower_bound(mVariants.begin(), mVariants.end(), variant,
IsLessThan<decltype(mVariants)::ElementType,
auto* p = std::lower_bound(variants_.begin(), variants_.end(), variant,
IsLessThan<decltype(variants_)::ElementType,
decltype(variant)>);
// Don't insert the replacement when already present.
if (p != mVariants.end() && strcmp(p->get(), variant) == 0) {
if (p != variants_.end() && strcmp(p->get(), variant) == 0) {
return true;
}
// Insert the preferred variant in sort order.
auto preferred = DuplicateStringToUniqueChars(variant);
return !!mVariants.insert(p, std::move(preferred));
return !!variants_.insert(p, std::move(preferred));
};
auto removeVariant = [&](auto* p) {
size_t index = std::distance(mVariants.begin(), p);
mVariants.erase(mVariants.begin() + index);
size_t index = std::distance(variants_.begin(), p);
variants_.erase(variants_.begin() + index);
};
auto removeVariants = [&](auto* p, auto* q) {
size_t pIndex = std::distance(mVariants.begin(), p);
size_t qIndex = std::distance(mVariants.begin(), q);
size_t pIndex = std::distance(variants_.begin(), p);
size_t qIndex = std::distance(variants_.begin(), q);
MOZ_ASSERT(pIndex < qIndex, "variant subtags are sorted");
mVariants.erase(mVariants.begin() + qIndex);
mVariants.erase(mVariants.begin() + pIndex);
variants_.erase(variants_.begin() + qIndex);
variants_.erase(variants_.begin() + pIndex);
};
if (mVariants.length() >= 2) {
if (variants_.length() >= 2) {
if (auto* hepburn = findVariant("hepburn")) {
if (auto* heploc = findVariant("heploc")) {
removeVariants(hepburn, heploc);
@ -786,78 +786,78 @@ bool mozilla::intl::Locale::UpdateLegacyMappings() {
}
}
if (Language().EqualTo("sgn")) {
if (Region().Present() && SignLanguageMapping(mLanguage, Region())) {
mRegion.Set(mozilla::MakeStringSpan(""));
if (language().equalTo("sgn")) {
if (region().present() && signLanguageMapping(language_, region())) {
region_.set(mozilla::MakeStringSpan(""));
}
}
else if (Language().EqualTo("aa") ||
Language().EqualTo("aar")) {
else if (language().equalTo("aa") ||
language().equalTo("aar")) {
if (auto* saaho = findVariant("saaho")) {
removeVariant(saaho);
SetLanguage("ssy");
setLanguage("ssy");
}
}
else if (Language().EqualTo("arm") ||
Language().EqualTo("hy") ||
Language().EqualTo("hye")) {
else if (language().equalTo("arm") ||
language().equalTo("hy") ||
language().equalTo("hye")) {
if (auto* arevmda = findVariant("arevmda")) {
removeVariant(arevmda);
SetLanguage("hyw");
setLanguage("hyw");
}
}
else if (Language().EqualTo("art")) {
else if (language().equalTo("art")) {
if (auto* lojban = findVariant("lojban")) {
removeVariant(lojban);
SetLanguage("jbo");
setLanguage("jbo");
}
}
else if (Language().EqualTo("cel")) {
else if (language().equalTo("cel")) {
if (auto* gaulish = findVariant("gaulish")) {
removeVariant(gaulish);
SetLanguage("xtg");
setLanguage("xtg");
}
}
else if (Language().EqualTo("chi") ||
Language().EqualTo("cmn") ||
Language().EqualTo("zh") ||
Language().EqualTo("zho")) {
else if (language().equalTo("chi") ||
language().equalTo("cmn") ||
language().equalTo("zh") ||
language().equalTo("zho")) {
if (auto* guoyu = findVariant("guoyu")) {
if (auto* hakka = findVariant("hakka")) {
removeVariants(guoyu, hakka);
SetLanguage("hak");
setLanguage("hak");
return true;
}
}
if (auto* guoyu = findVariant("guoyu")) {
if (auto* xiang = findVariant("xiang")) {
removeVariants(guoyu, xiang);
SetLanguage("hsn");
setLanguage("hsn");
return true;
}
}
if (auto* guoyu = findVariant("guoyu")) {
removeVariant(guoyu);
SetLanguage("zh");
setLanguage("zh");
}
else if (auto* hakka = findVariant("hakka")) {
removeVariant(hakka);
SetLanguage("hak");
setLanguage("hak");
}
else if (auto* xiang = findVariant("xiang")) {
removeVariant(xiang);
SetLanguage("hsn");
setLanguage("hsn");
}
}
else if (Language().EqualTo("no") ||
Language().EqualTo("nor")) {
else if (language().equalTo("no") ||
language().equalTo("nor")) {
if (auto* bokmal = findVariant("bokmal")) {
removeVariant(bokmal);
SetLanguage("nb");
setLanguage("nb");
}
else if (auto* nynorsk = findVariant("nynorsk")) {
removeVariant(nynorsk);
SetLanguage("nn");
setLanguage("nn");
}
}
@ -867,13 +867,13 @@ bool mozilla::intl::Locale::UpdateLegacyMappings() {
// Mappings from legacy sign languages.
// Derived from CLDR Supplemental Data, version 40.
// https://unicode.org/Public/cldr/40/core.zip
bool mozilla::intl::Locale::SignLanguageMapping(LanguageSubtag& language,
bool mozilla::intl::Locale::signLanguageMapping(LanguageSubtag& language,
const RegionSubtag& region) {
MOZ_ASSERT(language.EqualTo("sgn"));
MOZ_ASSERT(IsStructurallyValidRegionTag(region.Span()));
MOZ_ASSERT(IsCanonicallyCasedRegionTag(region.Span()));
MOZ_ASSERT(language.equalTo("sgn"));
MOZ_ASSERT(IsStructurallyValidRegionTag(region.span()));
MOZ_ASSERT(IsCanonicallyCasedRegionTag(region.span()));
if (region.Length() == 2) {
if (region.length() == 2) {
static const char regions[22][3] = {
"BR", "CO", "DD", "DE", "DK", "ES", "FR", "FX", "GB", "GR",
"IE", "IT", "JP", "MX", "NI", "NL", "NO", "PT", "SE", "UK",
@ -886,7 +886,7 @@ bool mozilla::intl::Locale::SignLanguageMapping(LanguageSubtag& language,
};
if (const char* replacement = SearchReplacement(regions, aliases, region)) {
language.Set(mozilla::MakeStringSpan(replacement));
language.set(mozilla::MakeStringSpan(replacement));
return true;
}
return false;
@ -905,7 +905,7 @@ bool mozilla::intl::Locale::SignLanguageMapping(LanguageSubtag& language,
};
if (const char* replacement = SearchReplacement(regions, aliases, region)) {
language.Set(mozilla::MakeStringSpan(replacement));
language.set(mozilla::MakeStringSpan(replacement));
return true;
}
return false;
@ -968,7 +968,7 @@ static inline const char* SearchUnicodeReplacement(
* Spec: https://www.unicode.org/reports/tr35/#Unicode_Locale_Extension_Data_Files
* Spec: https://www.unicode.org/reports/tr35/#t_Extension
*/
const char* mozilla::intl::Locale::ReplaceUnicodeExtensionType(
const char* mozilla::intl::Locale::replaceUnicodeExtensionType(
mozilla::Span<const char> key, mozilla::Span<const char> type) {
MOZ_ASSERT(key.size() == UnicodeKeyLength);
MOZ_ASSERT(IsCanonicallyCasedUnicodeKey(key));
@ -1098,7 +1098,7 @@ static inline bool IsTransformType(mozilla::Span<const char> type, const char (&
* Spec: https://www.unicode.org/reports/tr35/#Unicode_Locale_Extension_Data_Files
* Spec: https://www.unicode.org/reports/tr35/#t_Extension
*/
const char* mozilla::intl::Locale::ReplaceTransformExtensionType(
const char* mozilla::intl::Locale::replaceTransformExtensionType(
mozilla::Span<const char> key, mozilla::Span<const char> type) {
MOZ_ASSERT(key.size() == TransformKeyLength);
MOZ_ASSERT(IsCanonicallyCasedTransformKey(key));

View File

@ -304,19 +304,19 @@ LocaleService::Observe(nsISupports* aSubject, const char* aTopic,
bool LocaleService::LanguagesMatch(const nsACString& aRequested,
const nsACString& aAvailable) {
Locale requested;
auto requestedResult = LocaleParser::TryParse(aRequested, requested);
auto requestedResult = LocaleParser::tryParse(aRequested, requested);
Locale available;
auto availableResult = LocaleParser::TryParse(aAvailable, available);
auto availableResult = LocaleParser::tryParse(aAvailable, available);
if (requestedResult.isErr() || availableResult.isErr()) {
return false;
}
if (requested.Canonicalize().isErr() || available.Canonicalize().isErr()) {
if (requested.canonicalize().isErr() || available.canonicalize().isErr()) {
return false;
}
return requested.Language().Span() == available.Language().Span();
return requested.language().span() == available.language().span();
}
bool LocaleService::IsServer() { return mIsServer; }
@ -540,7 +540,7 @@ LocaleService::NegotiateLanguages(const nsTArray<nsCString>& aRequested,
#ifdef DEBUG
Locale parsedLocale;
auto result = LocaleParser::TryParse(aDefaultLocale, parsedLocale);
auto result = LocaleParser::tryParse(aDefaultLocale, parsedLocale);
MOZ_ASSERT(
aDefaultLocale.IsEmpty() || result.isOk(),

View File

@ -55,32 +55,32 @@ const Quotes* QuotesForLang(const nsAtom* aLang) {
// we can match it with region or script subtags, if present, or just the
// primary language tag.
Locale loc;
auto result = LocaleParser::TryParse(langStr, loc);
auto result = LocaleParser::tryParse(langStr, loc);
if (result.isErr()) {
return nullptr;
}
if (loc.Canonicalize().isErr()) {
if (loc.canonicalize().isErr()) {
return nullptr;
}
if (loc.Region().Present()) {
if (loc.region().present()) {
nsAutoCString langAndRegion;
langAndRegion.Append(loc.Language().Span());
langAndRegion.Append(loc.language().span());
langAndRegion.Append('-');
langAndRegion.Append(loc.Region().Span());
langAndRegion.Append(loc.region().span());
if ((entry = sQuotesForLang->Lookup(langAndRegion).DataPtrOrNull())) {
return entry;
}
}
if (loc.Script().Present()) {
if (loc.script().present()) {
nsAutoCString langAndScript;
langAndScript.Append(loc.Language().Span());
langAndScript.Append(loc.language().span());
langAndScript.Append('-');
langAndScript.Append(loc.Script().Span());
langAndScript.Append(loc.script().span());
if ((entry = sQuotesForLang->Lookup(langAndScript).DataPtrOrNull())) {
return entry;
}
}
Span<const char> langAsSpan = loc.Language().Span();
Span<const char> langAsSpan = loc.language().span();
nsAutoCString lang(langAsSpan.data(), langAsSpan.size());
if ((entry = sQuotesForLang->Lookup(lang).DataPtrOrNull())) {
return entry;

View File

@ -189,26 +189,26 @@ nsStaticAtom* nsLanguageAtomService::GetUncachedLanguageGroup(
}
Locale loc;
auto result = LocaleParser::TryParse(langStr, loc);
if (result.isOk() && loc.Canonicalize().isOk()) {
auto result = LocaleParser::tryParse(langStr, loc);
if (result.isOk() && loc.canonicalize().isOk()) {
// Fill in script subtag if not present.
if (loc.Script().Missing()) {
if (loc.AddLikelySubtags().isErr()) {
if (loc.script().missing()) {
if (loc.addLikelySubtags().isErr()) {
// Fall back to x-unicode if no match was found
return nsGkAtoms::Unicode;
}
}
// Traditional Chinese has separate prefs for Hong Kong / Taiwan;
// check the region subtag.
if (loc.Script().EqualTo("Hant")) {
if (loc.Region().EqualTo("HK")) {
if (loc.script().equalTo("Hant")) {
if (loc.region().equalTo("HK")) {
return nsGkAtoms::HongKongChinese;
}
return nsGkAtoms::Taiwanese;
}
// Search list of known script subtags that map to langGroup codes.
size_t foundIndex;
Span<const char> scriptAsSpan = loc.Script().Span();
Span<const char> scriptAsSpan = loc.script().span();
nsDependentCSubstring script(scriptAsSpan.data(), scriptAsSpan.size());
if (BinarySearchIf(
kScriptLangGroup, 0, ArrayLength(kScriptLangGroup),
@ -221,19 +221,19 @@ nsStaticAtom* nsLanguageAtomService::GetUncachedLanguageGroup(
// Script subtag was not recognized (includes "Hani"); check the language
// subtag for CJK possibilities so that we'll prefer the appropriate font
// rather than falling back to the browser's hardcoded preference.
if (loc.Language().EqualTo("zh")) {
if (loc.Region().EqualTo("HK")) {
if (loc.language().equalTo("zh")) {
if (loc.region().equalTo("HK")) {
return nsGkAtoms::HongKongChinese;
}
if (loc.Region().EqualTo("TW")) {
if (loc.region().equalTo("TW")) {
return nsGkAtoms::Taiwanese;
}
return nsGkAtoms::Chinese;
}
if (loc.Language().EqualTo("ja")) {
if (loc.language().equalTo("ja")) {
return nsGkAtoms::Japanese;
}
if (loc.Language().EqualTo("ko")) {
if (loc.language().equalTo("ko")) {
return nsGkAtoms::ko;
}
}

View File

@ -139,7 +139,7 @@ TEST(Intl_Locale_LocaleService, GetDefaultLocale)
ASSERT_FALSE(locStr.IsEmpty());
Locale loc;
ASSERT_TRUE(LocaleParser::TryParse(locStr, loc).isOk());
ASSERT_TRUE(LocaleParser::tryParse(locStr, loc).isOk());
}
TEST(Intl_Locale_LocaleService, IsAppLocaleRTL)

View File

@ -242,7 +242,7 @@ static mozilla::intl::Collator* NewIntlCollator(
if (StringEqualsLiteral(usage, "search")) {
// ICU expects search as a Unicode locale extension on locale.
mozilla::intl::Locale tag;
if (mozilla::intl::LocaleParser::TryParse(
if (mozilla::intl::LocaleParser::tryParse(
mozilla::MakeStringSpan(locale.get()), tag)
.isErr()) {
JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr,
@ -265,7 +265,7 @@ static mozilla::intl::Collator* NewIntlCollator(
}
intl::FormatBuffer<char> buffer(cx);
if (auto result = tag.ToString(buffer); result.isErr()) {
if (auto result = tag.toString(buffer); result.isErr()) {
intl::ReportInternalError(cx, result.unwrapErr());
return nullptr;
}

View File

@ -594,7 +594,7 @@ static UniqueChars DateTimeFormatLocale(
}
FormatBuffer<char> buffer(cx);
if (auto result = tag.ToString(buffer); result.isErr()) {
if (auto result = tag.toString(buffer); result.isErr()) {
intl::ReportInternalError(cx, result.unwrapErr());
return nullptr;
}

View File

@ -346,7 +346,7 @@ static bool TryParseBaseName(JSContext* cx, HandleLinearString languageStr,
return false;
}
if (LocaleParser::TryParseBaseName(chars, tag).isOk()) {
if (LocaleParser::tryParseBaseName(chars, tag).isOk()) {
return true;
}
}
@ -367,7 +367,7 @@ static JSString* GetLanguageDisplayName(
// ICU always canonicalizes the input locale, but since we know that ICU's
// canonicalization is incomplete, we need to perform our own canonicalization
// to ensure consistent result.
if (auto result = tag.CanonicalizeBaseName(); result.isErr()) {
if (auto result = tag.canonicalizeBaseName(); result.isErr()) {
if (result.unwrapErr() ==
mozilla::intl::Locale::CanonicalizationError::DuplicateVariant) {
JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr,
@ -380,7 +380,7 @@ static JSString* GetLanguageDisplayName(
}
intl::FormatBuffer<char> buffer(cx);
if (auto result = tag.ToString(buffer); result.isErr()) {
if (auto result = tag.toString(buffer); result.isErr()) {
intl::ReportInternalError(cx, result.unwrapErr());
return nullptr;
}
@ -434,18 +434,18 @@ static JSString* GetScriptDisplayName(JSContext* cx,
}
mozilla::intl::Locale tag;
tag.SetLanguage("und");
tag.SetScript(script);
tag.setLanguage("und");
tag.setScript(script);
// ICU always canonicalizes the input locale, but since we know that ICU's
// canonicalization is incomplete, we need to perform our own canonicalization
// to ensure consistent result.
if (tag.CanonicalizeBaseName().isErr()) {
if (tag.canonicalizeBaseName().isErr()) {
intl::ReportInternalError(cx);
return nullptr;
}
MOZ_ASSERT(tag.Script().Present());
MOZ_ASSERT(tag.script().present());
// |uldn_scriptDisplayName| doesn't use the stand-alone form for script
// subtags, so we're using |uloc_getDisplayScript| instead. (This only applies
@ -455,7 +455,7 @@ static JSString* GetScriptDisplayName(JSContext* cx,
if (displayStyle == DisplayNamesStyle::Long) {
// |uloc_getDisplayScript| expects a full locale identifier as its input.
intl::FormatBuffer<char> buffer(cx);
if (auto result = tag.ToString(buffer); result.isErr()) {
if (auto result = tag.toString(buffer); result.isErr()) {
intl::ReportInternalError(cx, result.unwrapErr());
return nullptr;
}
@ -485,18 +485,18 @@ static JSString* GetScriptDisplayName(JSContext* cx,
// Return the case-canonicalized input when no localized name was found.
if (str->empty() && fallback == DisplayNamesFallback::Code) {
script.ToTitleCase();
return NewStringCopy<CanGC>(cx, script.Span());
script.toTitleCase();
return NewStringCopy<CanGC>(cx, script.span());
}
return str;
}
// Note: ICU requires the script subtag to be in canonical case.
const mozilla::intl::ScriptSubtag& canonicalScript = tag.Script();
const mozilla::intl::ScriptSubtag& canonicalScript = tag.script();
char scriptChars[mozilla::intl::LanguageTagLimits::ScriptLength + 1] = {};
std::copy_n(canonicalScript.Span().data(), canonicalScript.Length(),
std::copy_n(canonicalScript.span().data(), canonicalScript.length(),
scriptChars);
ULocaleDisplayNames* ldn =
@ -523,8 +523,8 @@ static JSString* GetScriptDisplayName(JSContext* cx,
// Return the case-canonicalized input when no localized name was found.
if (str->empty() && fallback == DisplayNamesFallback::Code) {
script.ToTitleCase();
return NewStringCopy<CanGC>(cx, script.Span());
script.toTitleCase();
return NewStringCopy<CanGC>(cx, script.span());
}
return str;
@ -543,24 +543,24 @@ static JSString* GetRegionDisplayName(JSContext* cx,
}
mozilla::intl::Locale tag;
tag.SetLanguage("und");
tag.SetRegion(region);
tag.setLanguage("und");
tag.setRegion(region);
// ICU always canonicalizes the input locale, but since we know that ICU's
// canonicalization is incomplete, we need to perform our own canonicalization
// to ensure consistent result.
if (tag.CanonicalizeBaseName().isErr()) {
if (tag.canonicalizeBaseName().isErr()) {
intl::ReportInternalError(cx);
return nullptr;
}
MOZ_ASSERT(tag.Region().Present());
MOZ_ASSERT(tag.region().present());
// Note: ICU requires the region subtag to be in canonical case.
const mozilla::intl::RegionSubtag& canonicalRegion = tag.Region();
const mozilla::intl::RegionSubtag& canonicalRegion = tag.region();
char regionChars[mozilla::intl::LanguageTagLimits::RegionLength + 1] = {};
std::copy_n(canonicalRegion.Span().data(), canonicalRegion.Length(),
std::copy_n(canonicalRegion.span().data(), canonicalRegion.length(),
regionChars);
ULocaleDisplayNames* ldn =
@ -587,8 +587,8 @@ static JSString* GetRegionDisplayName(JSContext* cx,
// Return the case-canonicalized input when no localized name was found.
if (str->empty() && fallback == DisplayNamesFallback::Code) {
region.ToUpperCase();
return NewStringCopy<CanGC>(cx, region.Span());
region.toUpperCase();
return NewStringCopy<CanGC>(cx, region.span());
}
return str;
@ -666,7 +666,7 @@ static JSString* GetCalendarDisplayName(
return nullptr;
}
if (LocaleParser::CanParseUnicodeExtensionType(
if (LocaleParser::canParseUnicodeExtensionType(
mozilla::Span(calendar.get(), calendarStr->length()))
.isErr()) {
ReportInvalidOptionError(cx, "calendar", calendarStr);
@ -683,7 +683,7 @@ static JSString* GetCalendarDisplayName(
// Search if there's a replacement for the Unicode calendar keyword.
const char* canonicalCalendar = calendar.get();
if (const char* replacement =
mozilla::intl::Locale::ReplaceUnicodeExtensionType(key, type)) {
mozilla::intl::Locale::replaceUnicodeExtensionType(key, type)) {
canonicalCalendar = replacement;
}
@ -785,7 +785,7 @@ static ListObject* GetDateTimeDisplayNames(
}
mozilla::intl::Locale tag;
if (LocaleParser::TryParse(mozilla::MakeStringSpan(locale), tag).isErr()) {
if (LocaleParser::tryParse(mozilla::MakeStringSpan(locale), tag).isErr()) {
JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr,
JSMSG_INVALID_LANGUAGE_TAG, locale);
return nullptr;
@ -801,7 +801,7 @@ static ListObject* GetDateTimeDisplayNames(
}
intl::FormatBuffer<char> buffer(cx);
if (auto result = tag.ToString(buffer); result.isErr()) {
if (auto result = tag.toString(buffer); result.isErr()) {
intl::ReportInternalError(cx, result.unwrapErr());
return nullptr;
}

View File

@ -274,7 +274,7 @@ bool js::intl_BestAvailableLocale(JSContext* cx, unsigned argc, Value* vp) {
return false;
}
parse_result = mozilla::intl::LocaleParser::TryParse(chars, tag);
parse_result = mozilla::intl::LocaleParser::tryParse(chars, tag);
}
if (parse_result.isErr()) {
@ -285,10 +285,10 @@ bool js::intl_BestAvailableLocale(JSContext* cx, unsigned argc, Value* vp) {
return false;
}
MOZ_ASSERT(!tag.GetUnicodeExtension(),
MOZ_ASSERT(!tag.unicodeExtension(),
"locale must contain no Unicode extensions");
if (auto result = tag.Canonicalize(); result.isErr()) {
if (auto result = tag.canonicalize(); result.isErr()) {
MOZ_ASSERT(
result.unwrapErr() !=
mozilla::intl::Locale::CanonicalizationError::DuplicateVariant);
@ -297,7 +297,7 @@ bool js::intl_BestAvailableLocale(JSContext* cx, unsigned argc, Value* vp) {
}
intl::FormatBuffer<char, intl::INITIAL_CHAR_BUFFER_SIZE> buffer(cx);
if (auto result = tag.ToString(buffer); result.isErr()) {
if (auto result = tag.toString(buffer); result.isErr()) {
intl::ReportInternalError(cx, result.unwrapErr());
return false;
}
@ -355,8 +355,8 @@ bool js::intl_supportedLocaleOrFallback(JSContext* cx, unsigned argc,
// Tell the analysis the |tag.canonicalize()| method can't GC.
JS::AutoSuppressGCAnalysis nogc;
canParseLocale = mozilla::intl::LocaleParser::TryParse(chars, tag).isOk() &&
tag.Canonicalize().isOk();
canParseLocale = mozilla::intl::LocaleParser::tryParse(chars, tag).isOk() &&
tag.canonicalize().isOk();
}
RootedLinearString candidate(cx);
@ -369,10 +369,10 @@ bool js::intl_supportedLocaleOrFallback(JSContext* cx, unsigned argc,
// The default locale must be in [[AvailableLocales]], and that list must
// not contain any locales with Unicode extension sequences, so remove any
// present in the candidate.
tag.ClearUnicodeExtension();
tag.clearUnicodeExtension();
intl::FormatBuffer<char, intl::INITIAL_CHAR_BUFFER_SIZE> buffer(cx);
if (auto result = tag.ToString(buffer); result.isErr()) {
if (auto result = tag.toString(buffer); result.isErr()) {
intl::ReportInternalError(cx, result.unwrapErr());
return false;
}

View File

@ -26,7 +26,7 @@ namespace intl {
return false;
}
if (mozilla::intl::LocaleParser::TryParse(chars, result).isOk()) {
if (mozilla::intl::LocaleParser::tryParse(chars, result).isOk()) {
return true;
}
}
@ -48,13 +48,13 @@ bool ParseStandaloneLanguageTag(HandleLinearString str,
str->latin1Range(nogc))) {
return false;
}
result.Set<Latin1Char>(str->latin1Range(nogc));
result.set<Latin1Char>(str->latin1Range(nogc));
} else {
if (!mozilla::intl::IsStructurallyValidLanguageTag<char16_t>(
str->twoByteRange(nogc))) {
return false;
}
result.Set<char16_t>(str->twoByteRange(nogc));
result.set<char16_t>(str->twoByteRange(nogc));
}
return true;
}
@ -69,13 +69,13 @@ bool ParseStandaloneScriptTag(HandleLinearString str,
str->latin1Range(nogc))) {
return false;
}
result.Set<Latin1Char>(str->latin1Range(nogc));
result.set<Latin1Char>(str->latin1Range(nogc));
} else {
if (!mozilla::intl::IsStructurallyValidScriptTag<char16_t>(
str->twoByteRange(nogc))) {
return false;
}
result.Set<char16_t>(str->twoByteRange(nogc));
result.set<char16_t>(str->twoByteRange(nogc));
}
return true;
}
@ -90,13 +90,13 @@ bool ParseStandaloneRegionTag(HandleLinearString str,
str->latin1Range(nogc))) {
return false;
}
result.Set<Latin1Char>(str->latin1Range(nogc));
result.set<Latin1Char>(str->latin1Range(nogc));
} else {
if (!mozilla::intl::IsStructurallyValidRegionTag<char16_t>(
str->twoByteRange(nogc))) {
return false;
}
result.Set<char16_t>(str->twoByteRange(nogc));
result.set<char16_t>(str->twoByteRange(nogc));
}
return true;
}
@ -157,27 +157,27 @@ JS::Result<JSString*> ParseStandaloneISO639LanguageTag(JSContext* cx,
mozilla::intl::LanguageSubtag languageTag;
if (str->hasLatin1Chars()) {
JS::AutoCheckCannotGC nogc;
languageTag.Set<Latin1Char>(str->latin1Range(nogc));
languageTag.set<Latin1Char>(str->latin1Range(nogc));
} else {
JS::AutoCheckCannotGC nogc;
languageTag.Set<char16_t>(str->twoByteRange(nogc));
languageTag.set<char16_t>(str->twoByteRange(nogc));
}
if (!isLowerCase) {
// The language subtag is canonicalized to lower case.
languageTag.ToLowerCase();
languageTag.toLowerCase();
}
// Reject the input if the canonical tag contains more than just a single
// language subtag.
if (mozilla::intl::Locale::ComplexLanguageMapping(languageTag)) {
if (mozilla::intl::Locale::complexLanguageMapping(languageTag)) {
return nullptr;
}
// Take care to replace deprecated subtags with their preferred values.
JSString* result;
if (mozilla::intl::Locale::LanguageMapping(languageTag) || !isLowerCase) {
result = NewStringCopy<CanGC>(cx, languageTag.Span());
if (mozilla::intl::Locale::languageMapping(languageTag) || !isLowerCase) {
result = NewStringCopy<CanGC>(cx, languageTag.span());
} else {
result = str;
}

View File

@ -61,14 +61,14 @@ static inline bool IsLocale(HandleValue v) {
// Return the length of the base-name subtags.
static size_t BaseNameLength(const mozilla::intl::Locale& tag) {
size_t baseNameLength = tag.Language().Length();
if (tag.Script().Present()) {
baseNameLength += 1 + tag.Script().Length();
size_t baseNameLength = tag.language().length();
if (tag.script().present()) {
baseNameLength += 1 + tag.script().length();
}
if (tag.Region().Present()) {
baseNameLength += 1 + tag.Region().Length();
if (tag.region().present()) {
baseNameLength += 1 + tag.region().length();
}
for (const auto& variant : tag.Variants()) {
for (const auto& variant : tag.variants()) {
baseNameLength += 1 + variant.size();
}
return baseNameLength;
@ -90,7 +90,7 @@ struct IndexAndLength {
static mozilla::Maybe<IndexAndLength> UnicodeExtensionPosition(
const mozilla::intl::Locale& tag) {
size_t index = 0;
for (const auto& extension : tag.Extensions()) {
for (const auto& extension : tag.extensions()) {
MOZ_ASSERT(!mozilla::IsAsciiUppercaseAlpha(extension[0]),
"extensions are case normalized to lowercase");
@ -108,7 +108,7 @@ static mozilla::Maybe<IndexAndLength> UnicodeExtensionPosition(
static LocaleObject* CreateLocaleObject(JSContext* cx, HandleObject prototype,
const mozilla::intl::Locale& tag) {
intl::FormatBuffer<char, intl::INITIAL_CHAR_BUFFER_SIZE> buffer(cx);
if (auto result = tag.ToString(buffer); result.isErr()) {
if (auto result = tag.toString(buffer); result.isErr()) {
intl::ReportInternalError(cx, result.unwrapErr());
return nullptr;
}
@ -167,7 +167,7 @@ static inline bool IsValidUnicodeExtensionValue(JSContext* cx,
}
*isValid =
mozilla::intl::LocaleParser::CanParseUnicodeExtensionType(chars).isOk();
mozilla::intl::LocaleParser::canParseUnicodeExtensionType(chars).isOk();
return true;
}
@ -355,26 +355,26 @@ static bool ApplyOptionsToTag(JSContext* cx, mozilla::intl::Locale& tag,
// Step 9 (Already performed in caller).
// Skip steps 10-13 when no subtags were modified.
if (language.Present() || script.Present() || region.Present()) {
if (language.present() || script.present() || region.present()) {
// Step 10.
if (language.Present()) {
tag.SetLanguage(language);
if (language.present()) {
tag.setLanguage(language);
}
// Step 11.
if (script.Present()) {
tag.SetScript(script);
if (script.present()) {
tag.setScript(script);
}
// Step 12.
if (region.Present()) {
tag.SetRegion(region);
if (region.present()) {
tag.setRegion(region);
}
// Step 13.
// Optimized to only canonicalize the base-name subtags. All other
// canonicalization steps will happen later.
auto result = tag.CanonicalizeBaseName();
auto result = tag.canonicalizeBaseName();
if (result.isErr()) {
if (result.unwrapErr() ==
mozilla::intl::Locale::CanonicalizationError::DuplicateVariant) {
@ -411,7 +411,7 @@ bool js::intl::ApplyUnicodeExtensionToTag(
const char* unicodeExtensionEnd = nullptr;
const char* unicodeExtensionKeywords = nullptr;
if (auto unicodeExtension = tag.GetUnicodeExtension()) {
if (auto unicodeExtension = tag.unicodeExtension()) {
const char* unicodeExtensionBegin = unicodeExtension->data();
unicodeExtensionEnd = unicodeExtensionBegin + unicodeExtension->size();
@ -465,7 +465,7 @@ bool js::intl::ApplyUnicodeExtensionToTag(
}
}
if (auto res = tag.SetUnicodeExtension(newExtension); res.isErr()) {
if (auto res = tag.setUnicodeExtension(newExtension); res.isErr()) {
intl::ReportInternalError(cx, res.unwrapErr());
return false;
}
@ -554,7 +554,7 @@ static bool Locale(JSContext* cx, unsigned argc, Value* vp) {
return false;
}
if (auto result = tag.CanonicalizeBaseName(); result.isErr()) {
if (auto result = tag.canonicalizeBaseName(); result.isErr()) {
if (result.unwrapErr() ==
mozilla::intl::Locale::CanonicalizationError::DuplicateVariant) {
JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr,
@ -725,7 +725,7 @@ static bool Locale(JSContext* cx, unsigned argc, Value* vp) {
// ApplyOptionsToTag, steps 9 and 13.
// ApplyUnicodeExtensionToTag, step 9.
if (auto result = tag.CanonicalizeExtensions(); result.isErr()) {
if (auto result = tag.canonicalizeExtensions(); result.isErr()) {
if (result.unwrapErr() ==
mozilla::intl::Locale::CanonicalizationError::DuplicateVariant) {
JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr,
@ -943,7 +943,7 @@ static bool Locale_maximize(JSContext* cx, const CallArgs& args) {
return false;
}
if (auto result = tag.AddLikelySubtags(); result.isErr()) {
if (auto result = tag.addLikelySubtags(); result.isErr()) {
intl::ReportInternalError(cx, result.unwrapErr());
return false;
}
@ -980,7 +980,7 @@ static bool Locale_minimize(JSContext* cx, const CallArgs& args) {
return false;
}
if (auto result = tag.RemoveLikelySubtags(); result.isErr()) {
if (auto result = tag.removeLikelySubtags(); result.isErr()) {
intl::ReportInternalError(cx, result.unwrapErr());
return false;
}
@ -1349,7 +1349,7 @@ bool js::intl_ValidateAndCanonicalizeLanguageTag(JSContext* cx, unsigned argc,
return false;
}
auto result = tag.Canonicalize();
auto result = tag.canonicalize();
if (result.isErr()) {
if (result.unwrapErr() ==
mozilla::intl::Locale::CanonicalizationError::DuplicateVariant) {
@ -1362,7 +1362,7 @@ bool js::intl_ValidateAndCanonicalizeLanguageTag(JSContext* cx, unsigned argc,
}
intl::FormatBuffer<char, intl::INITIAL_CHAR_BUFFER_SIZE> buffer(cx);
if (auto result = tag.ToString(buffer); result.isErr()) {
if (auto result = tag.toString(buffer); result.isErr()) {
intl::ReportInternalError(cx, result.unwrapErr());
return false;
}
@ -1399,14 +1399,14 @@ bool js::intl_TryValidateAndCanonicalizeLanguageTag(JSContext* cx,
return false;
}
if (mozilla::intl::LocaleParser::TryParse(chars, tag).isErr()) {
if (mozilla::intl::LocaleParser::tryParse(chars, tag).isErr()) {
// The caller handles invalid inputs.
args.rval().setNull();
return true;
}
}
auto result = tag.Canonicalize();
auto result = tag.canonicalize();
if (result.isErr()) {
if (result.unwrapErr() ==
mozilla::intl::Locale::CanonicalizationError::DuplicateVariant) {
@ -1419,7 +1419,7 @@ bool js::intl_TryValidateAndCanonicalizeLanguageTag(JSContext* cx,
}
intl::FormatBuffer<char, intl::INITIAL_CHAR_BUFFER_SIZE> buffer(cx);
if (auto result = tag.ToString(buffer); result.isErr()) {
if (auto result = tag.toString(buffer); result.isErr()) {
intl::ReportInternalError(cx, result.unwrapErr());
return false;
}
@ -1506,7 +1506,7 @@ bool js::intl_ValidateAndCanonicalizeUnicodeExtensionType(JSContext* cx,
// Search if there's a replacement for the current Unicode keyword.
JSString* result;
if (const char* replacement =
mozilla::intl::Locale::ReplaceUnicodeExtensionType(key, type)) {
mozilla::intl::Locale::replaceUnicodeExtensionType(key, type)) {
result = NewStringCopyZ<CanGC>(cx, replacement);
} else {
result = StringToLowerCase(cx, unicodeType);

View File

@ -327,7 +327,7 @@ static UniqueChars NumberFormatLocale(JSContext* cx, HandleObject internals) {
}
intl::FormatBuffer<char> buffer(cx);
if (auto result = tag.ToString(buffer); result.isErr()) {
if (auto result = tag.toString(buffer); result.isErr()) {
intl::ReportInternalError(cx, result.unwrapErr());
return nullptr;
}

View File

@ -204,7 +204,7 @@ static mozilla::intl::RelativeTimeFormat* NewRelativeTimeFormatter(
}
intl::FormatBuffer<char> buffer(cx);
if (auto result = tag.ToString(buffer); result.isErr()) {
if (auto result = tag.toString(buffer); result.isErr()) {
intl::ReportInternalError(cx, result.unwrapErr());
return nullptr;
}

View File

@ -126,8 +126,8 @@ def writeMappingsBinarySearch(
println(
"""
bool mozilla::intl::Locale::{0}({1} {2}) {{
MOZ_ASSERT({3}({2}.Span()));
MOZ_ASSERT({4}({2}.Span()));
MOZ_ASSERT({3}({2}.span()));
MOZ_ASSERT({4}({2}.span()));
""".format(
fn_name, type_name, name, validate_fn, validate_case_fn
).strip()
@ -177,7 +177,7 @@ def writeMappingsBinarySearchBody(
if length != tag_maxlength:
println(
"""
if ({}.Length() == {}) {{
if ({}.length() == {}) {{
""".format(
source_name, length
).rstrip(
@ -198,7 +198,7 @@ def writeMappingsBinarySearchBody(
subtags = sorted(subtags)
def equals(subtag):
return """{}.EqualTo("{}")""".format(source_name, subtag)
return """{}.equalTo("{}")""".format(source_name, subtag)
# Don't emit a binary search for short lists.
if len(subtags) == 1:
@ -206,7 +206,7 @@ def writeMappingsBinarySearchBody(
println(
"""
if ({}) {{
{}.Set(mozilla::MakeStringSpan("{}"));
{}.set(mozilla::MakeStringSpan("{}"));
return true;
}}
return false;
@ -232,7 +232,7 @@ def writeMappingsBinarySearchBody(
println(
"""
if ({}) {{
{}.Set("{}");
{}.set("{}");
return true;
}}
""".format(
@ -270,7 +270,7 @@ def writeMappingsBinarySearchBody(
println(
"""
if (const char* replacement = SearchReplacement({0}s, aliases, {0})) {{
{1}.Set(mozilla::MakeStringSpan(replacement));
{1}.set(mozilla::MakeStringSpan(replacement));
return true;
}}
return false;
@ -309,9 +309,9 @@ def writeComplexLanguageTagMappings(
writeMappingHeader(println, description, source, url)
println(
"""
void mozilla::intl::Locale::PerformComplexLanguageMappings() {
MOZ_ASSERT(IsStructurallyValidLanguageTag(Language().Span()));
MOZ_ASSERT(IsCanonicallyCasedLanguageTag(Language().Span()));
void mozilla::intl::Locale::performComplexLanguageMappings() {
MOZ_ASSERT(IsStructurallyValidLanguageTag(language().span()));
MOZ_ASSERT(IsCanonicallyCasedLanguageTag(language().span()));
""".lstrip()
)
@ -338,7 +338,7 @@ void mozilla::intl::Locale::PerformComplexLanguageMappings() {
first_language = False
cond = (
'Language().EqualTo("{}")'.format(lang)
'language().equalTo("{}")'.format(lang)
for lang in [deprecated_language] + language_aliases[key]
)
cond = (" ||\n" + " " * (2 + len(if_kind) + 2)).join(cond)
@ -354,7 +354,7 @@ void mozilla::intl::Locale::PerformComplexLanguageMappings() {
println(
"""
SetLanguage("{}");""".format(
setLanguage("{}");""".format(
language
).strip(
"\n"
@ -364,8 +364,8 @@ void mozilla::intl::Locale::PerformComplexLanguageMappings() {
if script is not None:
println(
"""
if (Script().Missing()) {{
SetScript("{}");
if (script().missing()) {{
setScript("{}");
}}""".format(
script
).strip(
@ -375,8 +375,8 @@ void mozilla::intl::Locale::PerformComplexLanguageMappings() {
if region is not None:
println(
"""
if (Region().Missing()) {{
SetRegion("{}");
if (region().missing()) {{
setRegion("{}");
}}""".format(
region
).strip(
@ -406,11 +406,11 @@ def writeComplexRegionTagMappings(
writeMappingHeader(println, description, source, url)
println(
"""
void mozilla::intl::Locale::PerformComplexRegionMappings() {
MOZ_ASSERT(IsStructurallyValidLanguageTag(Language().Span()));
MOZ_ASSERT(IsCanonicallyCasedLanguageTag(Language().Span()));
MOZ_ASSERT(IsStructurallyValidRegionTag(Region().Span()));
MOZ_ASSERT(IsCanonicallyCasedRegionTag(Region().Span()));
void mozilla::intl::Locale::performComplexRegionMappings() {
MOZ_ASSERT(IsStructurallyValidLanguageTag(language().span()));
MOZ_ASSERT(IsCanonicallyCasedLanguageTag(language().span()));
MOZ_ASSERT(IsStructurallyValidRegionTag(region().span()));
MOZ_ASSERT(IsCanonicallyCasedRegionTag(region().span()));
""".lstrip()
)
@ -442,7 +442,7 @@ void mozilla::intl::Locale::PerformComplexRegionMappings() {
first_region = False
cond = (
'Region().EqualTo("{}")'.format(region)
'region().equalTo("{}")'.format(region)
for region in [deprecated_region] + region_aliases[key]
)
cond = (" ||\n" + " " * (2 + len(if_kind) + 2)).join(cond)
@ -473,8 +473,8 @@ void mozilla::intl::Locale::PerformComplexRegionMappings() {
def compare_tags(language, script):
if script is None:
return 'Language().EqualTo("{}")'.format(language)
return '(Language().EqualTo("{}") && Script().EqualTo("{}"))'.format(
return 'language().equalTo("{}")'.format(language)
return '(language().equalTo("{}") && script().equalTo("{}"))'.format(
language, script
)
@ -487,7 +487,7 @@ void mozilla::intl::Locale::PerformComplexRegionMappings() {
println(
"""
{} ({}) {{
SetRegion("{}");
setRegion("{}");
}}""".format(
if_kind, cond, replacement_region
)
@ -498,7 +498,7 @@ void mozilla::intl::Locale::PerformComplexRegionMappings() {
println(
"""
else {{
SetRegion("{}");
setRegion("{}");
}}
}}""".format(
default
@ -537,32 +537,32 @@ static bool IsLessThan(const T& a, const U& b) {
writeMappingHeader(println, description, source, url)
println(
"""
bool mozilla::intl::Locale::PerformVariantMappings() {
bool mozilla::intl::Locale::performVariantMappings() {
// The variant subtags need to be sorted for binary search.
MOZ_ASSERT(std::is_sorted(mVariants.begin(), mVariants.end(),
IsLessThan<decltype(mVariants)::ElementType>));
MOZ_ASSERT(std::is_sorted(variants_.begin(), variants_.end(),
IsLessThan<decltype(variants_)::ElementType>));
auto removeVariantAt = [&](size_t index) {
mVariants.erase(mVariants.begin() + index);
variants_.erase(variants_.begin() + index);
};
auto insertVariantSortedIfNotPresent = [&](const char* variant) {
auto* p = std::lower_bound(
mVariants.begin(), mVariants.end(), variant,
IsLessThan<decltype(mVariants)::ElementType, decltype(variant)>);
variants_.begin(), variants_.end(), variant,
IsLessThan<decltype(variants_)::ElementType, decltype(variant)>);
// Don't insert the replacement when already present.
if (p != mVariants.end() && strcmp(p->get(), variant) == 0) {
if (p != variants_.end() && strcmp(p->get(), variant) == 0) {
return true;
}
// Insert the preferred variant in sort order.
auto preferred = DuplicateStringToUniqueChars(variant);
return !!mVariants.insert(p, std::move(preferred));
return !!variants_.insert(p, std::move(preferred));
};
for (size_t i = 0; i < mVariants.length();) {
const char* variant = mVariants[i].get();
for (size_t i = 0; i < variants_.length();) {
const char* variant = variants_[i].get();
MOZ_ASSERT(IsCanonicallyCasedVariantTag(mozilla::MakeStringSpan(variant)));
""".lstrip()
)
@ -601,7 +601,7 @@ bool mozilla::intl::Locale::PerformVariantMappings() {
if type == "language":
println(
f"""
SetLanguage("{replacement}");
setLanguage("{replacement}");
""".strip(
"\n"
)
@ -609,7 +609,7 @@ bool mozilla::intl::Locale::PerformVariantMappings() {
elif type == "region":
println(
f"""
SetRegion("{replacement}");
setRegion("{replacement}");
""".strip(
"\n"
)
@ -654,7 +654,7 @@ def writeLegacyMappingsFunction(println, legacy_mappings, description, source, u
writeMappingHeader(println, description, source, url)
println(
"""\
bool mozilla::intl::Locale::UpdateLegacyMappings() {
bool mozilla::intl::Locale::updateLegacyMappings() {
// We're mapping legacy tags to non-legacy form here.
// Other tags remain unchanged.
//
@ -662,61 +662,61 @@ bool mozilla::intl::Locale::UpdateLegacyMappings() {
// variant subtags. Therefore we can quickly exclude most tags by checking
// these two subtags.
MOZ_ASSERT(IsCanonicallyCasedLanguageTag(Language().Span()));
MOZ_ASSERT(IsCanonicallyCasedLanguageTag(language().span()));
if (!Language().EqualTo("sgn") && mVariants.length() == 0) {
if (!language().equalTo("sgn") && variants_.length() == 0) {
return true;
}
#ifdef DEBUG
for (const auto& variant : Variants()) {
for (const auto& variant : variants()) {
MOZ_ASSERT(IsStructurallyValidVariantTag(variant));
MOZ_ASSERT(IsCanonicallyCasedVariantTag(variant));
}
#endif
// The variant subtags need to be sorted for binary search.
MOZ_ASSERT(std::is_sorted(mVariants.begin(), mVariants.end(),
IsLessThan<decltype(mVariants)::ElementType>));
MOZ_ASSERT(std::is_sorted(variants_.begin(), variants_.end(),
IsLessThan<decltype(variants_)::ElementType>));
auto findVariant = [this](const char* variant) {
auto* p = std::lower_bound(mVariants.begin(), mVariants.end(), variant,
IsLessThan<decltype(mVariants)::ElementType,
auto* p = std::lower_bound(variants_.begin(), variants_.end(), variant,
IsLessThan<decltype(variants_)::ElementType,
decltype(variant)>);
if (p != mVariants.end() && strcmp(p->get(), variant) == 0) {
if (p != variants_.end() && strcmp(p->get(), variant) == 0) {
return p;
}
return static_cast<decltype(p)>(nullptr);
};
auto insertVariantSortedIfNotPresent = [&](const char* variant) {
auto* p = std::lower_bound(mVariants.begin(), mVariants.end(), variant,
IsLessThan<decltype(mVariants)::ElementType,
auto* p = std::lower_bound(variants_.begin(), variants_.end(), variant,
IsLessThan<decltype(variants_)::ElementType,
decltype(variant)>);
// Don't insert the replacement when already present.
if (p != mVariants.end() && strcmp(p->get(), variant) == 0) {
if (p != variants_.end() && strcmp(p->get(), variant) == 0) {
return true;
}
// Insert the preferred variant in sort order.
auto preferred = DuplicateStringToUniqueChars(variant);
return !!mVariants.insert(p, std::move(preferred));
return !!variants_.insert(p, std::move(preferred));
};
auto removeVariant = [&](auto* p) {
size_t index = std::distance(mVariants.begin(), p);
mVariants.erase(mVariants.begin() + index);
size_t index = std::distance(variants_.begin(), p);
variants_.erase(variants_.begin() + index);
};
auto removeVariants = [&](auto* p, auto* q) {
size_t pIndex = std::distance(mVariants.begin(), p);
size_t qIndex = std::distance(mVariants.begin(), q);
size_t pIndex = std::distance(variants_.begin(), p);
size_t qIndex = std::distance(variants_.begin(), q);
MOZ_ASSERT(pIndex < qIndex, "variant subtags are sorted");
mVariants.erase(mVariants.begin() + qIndex);
mVariants.erase(mVariants.begin() + pIndex);
variants_.erase(variants_.begin() + qIndex);
variants_.erase(variants_.begin() + pIndex);
};"""
)
@ -748,7 +748,7 @@ bool mozilla::intl::Locale::UpdateLegacyMappings() {
println(
"""
if (mVariants.length() >= 2) {
if (variants_.length() >= 2) {
if (auto* hepburn = findVariant("hepburn")) {
if (auto* heploc = findVariant("heploc")) {
removeVariants(hepburn, heploc);
@ -777,9 +777,9 @@ bool mozilla::intl::Locale::UpdateLegacyMappings() {
println(
"""
if (Language().EqualTo("sgn")) {
if (Region().Present() && SignLanguageMapping(mLanguage, Region())) {
mRegion.Set(mozilla::MakeStringSpan(""));
if (language().equalTo("sgn")) {
if (region().present() && signLanguageMapping(language_, region())) {
region_.set(mozilla::MakeStringSpan(""));
}
}
""".rstrip().lstrip(
@ -827,7 +827,7 @@ bool mozilla::intl::Locale::UpdateLegacyMappings() {
for langs in legacy_mappings_compact.values():
language_equal_to = (
f"""Language().EqualTo("{lang}")""" for lang in sorted(langs)
f"""language().equalTo("{lang}")""" for lang in sorted(langs)
)
cond = f""" ||\n{" " * len(" else if (")}""".join(language_equal_to)
@ -881,7 +881,7 @@ bool mozilla::intl::Locale::UpdateLegacyMappings() {
println(
f"""
{indent}removeVariant{"s" if len_variants > 1 else ""}({", ".join(sorted_variants)});
{indent}SetLanguage("{r_language}");
{indent}setLanguage("{r_language}");
{indent}{"return true;" if not chain_if else ""}
""".rstrip().lstrip(
"\n"
@ -920,11 +920,11 @@ def writeSignLanguageMappingsFunction(
writeMappingHeader(println, description, source, url)
println(
"""\
bool mozilla::intl::Locale::SignLanguageMapping(LanguageSubtag& language,
bool mozilla::intl::Locale::signLanguageMapping(LanguageSubtag& language,
const RegionSubtag& region) {
MOZ_ASSERT(language.EqualTo("sgn"));
MOZ_ASSERT(IsStructurallyValidRegionTag(region.Span()));
MOZ_ASSERT(IsCanonicallyCasedRegionTag(region.Span()));
MOZ_ASSERT(language.equalTo("sgn"));
MOZ_ASSERT(IsStructurallyValidRegionTag(region.span()));
MOZ_ASSERT(IsCanonicallyCasedRegionTag(region.span()));
""".rstrip()
)
@ -1650,10 +1650,10 @@ template <size_t Length, size_t TagLength, size_t SubtagLength>
static inline bool HasReplacement(
const char (&subtags)[Length][TagLength],
const mozilla::intl::LanguageTagSubtag<SubtagLength>& subtag) {
MOZ_ASSERT(subtag.Length() == TagLength - 1,
MOZ_ASSERT(subtag.length() == TagLength - 1,
"subtag must have the same length as the list of subtags");
const char* ptr = subtag.Span().data();
const char* ptr = subtag.span().data();
return std::binary_search(std::begin(subtags), std::end(subtags), ptr,
[](const char* a, const char* b) {
return memcmp(a, b, TagLength - 1) < 0;
@ -1664,10 +1664,10 @@ template <size_t Length, size_t TagLength, size_t SubtagLength>
static inline const char* SearchReplacement(
const char (&subtags)[Length][TagLength], const char* (&aliases)[Length],
const mozilla::intl::LanguageTagSubtag<SubtagLength>& subtag) {
MOZ_ASSERT(subtag.Length() == TagLength - 1,
MOZ_ASSERT(subtag.length() == TagLength - 1,
"subtag must have the same length as the list of subtags");
const char* ptr = subtag.Span().data();
const char* ptr = subtag.span().data();
auto p = std::lower_bound(std::begin(subtags), std::end(subtags), ptr,
[](const char* a, const char* b) {
return memcmp(a, b, TagLength - 1) < 0;
@ -1751,7 +1751,7 @@ static bool IsCanonicallyCasedTransformType(mozilla::Span<const char> type) {
writeMappingsBinarySearch(
println,
"LanguageMapping",
"languageMapping",
"LanguageSubtag&",
"language",
"IsStructurallyValidLanguageTag",
@ -1764,7 +1764,7 @@ static bool IsCanonicallyCasedTransformType(mozilla::Span<const char> type) {
)
writeMappingsBinarySearch(
println,
"ComplexLanguageMapping",
"complexLanguageMapping",
"const LanguageSubtag&",
"language",
"IsStructurallyValidLanguageTag",
@ -1777,7 +1777,7 @@ static bool IsCanonicallyCasedTransformType(mozilla::Span<const char> type) {
)
writeMappingsBinarySearch(
println,
"ScriptMapping",
"scriptMapping",
"ScriptSubtag&",
"script",
"IsStructurallyValidScriptTag",
@ -1790,7 +1790,7 @@ static bool IsCanonicallyCasedTransformType(mozilla::Span<const char> type) {
)
writeMappingsBinarySearch(
println,
"RegionMapping",
"regionMapping",
"RegionSubtag&",
"region",
"IsStructurallyValidRegionTag",
@ -1803,7 +1803,7 @@ static bool IsCanonicallyCasedTransformType(mozilla::Span<const char> type) {
)
writeMappingsBinarySearch(
println,
"ComplexRegionMapping",
"complexRegionMapping",
"const RegionSubtag&",
"region",
"IsStructurallyValidRegionTag",
@ -3269,7 +3269,7 @@ static inline const char* Search{0}Replacement(
* Spec: https://www.unicode.org/reports/tr35/#Unicode_Locale_Extension_Data_Files
* Spec: https://www.unicode.org/reports/tr35/#t_Extension
*/
const char* mozilla::intl::Locale::Replace{0}ExtensionType(
const char* mozilla::intl::Locale::replace{0}ExtensionType(
mozilla::Span<const char> key, mozilla::Span<const char> type) {{
MOZ_ASSERT(key.size() == {0}KeyLength);
MOZ_ASSERT(IsCanonicallyCased{0}Key(key));