tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit a876179e45510f1f23b1b0ecedb4867e15831bb0
parent c6b00b95bb76d771d396c4ae511810eedd525d2b
Author: Jonathan Kew <jkew@mozilla.com>
Date:   Fri,  5 Dec 2025 18:22:48 +0000

Bug 2003721 - Slightly simplify intl::QuotesForLang, now that the lang tag in nsStyleFont is known to be canonicalized. r=layout-reviewers,emilio

Differential Revision: https://phabricator.services.mozilla.com/D275271

Diffstat:
Mintl/locale/Quotes.cpp | 38++++++++++++++++++++------------------
1 file changed, 20 insertions(+), 18 deletions(-)

diff --git a/intl/locale/Quotes.cpp b/intl/locale/Quotes.cpp @@ -51,37 +51,39 @@ const Quotes* QuotesForLang(const nsAtom* aLang) { return entry; } - // Try parsing lang as a Locale and canonicalizing the subtags, then see if - // we can match it with region or script subtags, if present, or just the - // primary language tag. + // Try parsing lang as a Locale, then see if we can match it with region or + // script subtags, if present, or just the primary language tag. + // Note that the locale code (if well-formed) will have been canonicalized by + // the attribute-mapping code, so we can rely on the expected casing for each + // type of subtag. Locale loc; auto result = LocaleParser::TryParse(langStr, loc); if (result.isErr()) { return nullptr; } - if (loc.Canonicalize().isErr()) { - return nullptr; - } + // Extract the primary language tag. + const Span<const char> langAsSpan = loc.Language().Span(); + nsAutoCString lang(langAsSpan.data(), langAsSpan.size()); + const auto langLen = lang.Length(); + // See if we can match language + region. if (loc.Region().Present()) { - nsAutoCString langAndRegion; - langAndRegion.Append(loc.Language().Span()); - langAndRegion.Append('-'); - langAndRegion.Append(loc.Region().Span()); - if ((entry = sQuotesForLang->Lookup(langAndRegion).DataPtrOrNull())) { + lang.Append('-'); + lang.Append(loc.Region().Span()); + if ((entry = sQuotesForLang->Lookup(lang).DataPtrOrNull())) { return entry; } + lang.Truncate(langLen); } + // See if we can match language + script. if (loc.Script().Present()) { - nsAutoCString langAndScript; - langAndScript.Append(loc.Language().Span()); - langAndScript.Append('-'); - langAndScript.Append(loc.Script().Span()); - if ((entry = sQuotesForLang->Lookup(langAndScript).DataPtrOrNull())) { + lang.Append('-'); + lang.Append(loc.Script().Span()); + if ((entry = sQuotesForLang->Lookup(lang).DataPtrOrNull())) { return entry; } + lang.Truncate(langLen); } - Span<const char> langAsSpan = loc.Language().Span(); - nsAutoCString lang(langAsSpan.data(), langAsSpan.size()); + // OK, just try the primary language tag alone. if ((entry = sQuotesForLang->Lookup(lang).DataPtrOrNull())) { return entry; }