commit d5b1706ccdd68e1eaa4b82bb02ba826392506ca7
parent d279a1a33369eba32098730d701043c1417f090c
Author: Jonathan Kew <jkew@mozilla.com>
Date: Sat, 6 Dec 2025 00:21:52 +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:
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;
}