From 596126f7ff4147e53bd50f394fffbd86efd63a24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Bargull?= Date: Mon, 5 Aug 2024 11:09:29 +0200 Subject: [PATCH] Editorial: Add GetLocaleBaseName abstract operation Add `GetLocaleBaseName` to avoid repeating the same steps to extract the `unicode_language_id` parts of a `unicode_locale_id`. The abstract operation is named to `GetLocaleBaseName` to match the accessor property `Intl.Locale.prototype.baseName`. --- spec/locale.html | 68 +++++++++++++++++++-------------- spec/locales-currencies-tz.html | 6 +-- 2 files changed, 42 insertions(+), 32 deletions(-) diff --git a/spec/locale.html b/spec/locale.html index 0ec91d87..a6f2de87 100644 --- a/spec/locale.html +++ b/spec/locale.html @@ -82,21 +82,22 @@

It updates the unicode_language_id subtags in _tag_ from the corresponding properties of _options_ and returns the structurally valid but non-canonicalized result.
- 1. Let _languageId_ be the longest prefix of _tag_ matched by the unicode_language_id Unicode locale nonterminal. - 1. Let _language_ be ? GetOption(_options_, *"language"*, ~string~, ~empty~, GetLocaleLanguage(_languageId_)). + 1. Let _baseName_ be GetLocaleBaseName(_tag_). + 1. Let _language_ be ? GetOption(_options_, *"language"*, ~string~, ~empty~, GetLocaleLanguage(_baseName_)). 1. If _language_ cannot be matched by the unicode_language_subtag Unicode locale nonterminal, throw a *RangeError* exception. - 1. Let _script_ be ? GetOption(_options_, *"script"*, ~string~, ~empty~, GetLocaleScript(_languageId_)). + 1. Let _script_ be ? GetOption(_options_, *"script"*, ~string~, ~empty~, GetLocaleScript(_baseName_)). 1. If _script_ is not *undefined*, then 1. If _script_ cannot be matched by the unicode_script_subtag Unicode locale nonterminal, throw a *RangeError* exception. - 1. Let _region_ be ? GetOption(_options_, *"region"*, ~string~, ~empty~, GetLocaleRegion(_languageId_)). + 1. Let _region_ be ? GetOption(_options_, *"region"*, ~string~, ~empty~, GetLocaleRegion(_baseName_)). 1. If _region_ is not *undefined*, then 1. If _region_ cannot be matched by the unicode_region_subtag Unicode locale nonterminal, throw a *RangeError* exception. - 1. Let _variants_ be GetLocaleVariants(_languageId_). - 1. Let _newLanguageId_ be _language_. - 1. If _script_ is not *undefined*, set _newLanguageId_ to the string-concatenation of _newLanguageId_, *"-"*, and _script_. - 1. If _region_ is not *undefined*, set _newLanguageId_ to the string-concatenation of _newLanguageId_, *"-"*, and _region_. - 1. If _variants_ is not *undefined*, set _newLanguageId_ to the string-concatenation of _newLanguageId_, *"-"*, and _variants_. - 1. Let _newTag_ be _tag_ with the substring matched by the unicode_language_id Unicode locale nonterminal replaced by the string _newLanguageId_. + 1. Let _variants_ be GetLocaleVariants(_baseName_). + 1. Let _allExtensions_ be the suffix of _tag_ following _baseName_. + 1. Let _newTag_ be _language_. + 1. If _script_ is not *undefined*, set _newTag_ to the string-concatenation of _newTag_, *"-"*, and _script_. + 1. If _region_ is not *undefined*, set _newTag_ to the string-concatenation of _newTag_, *"-"*, and _region_. + 1. If _variants_ is not *undefined*, set _newTag_ to the string-concatenation of _newTag_, *"-"*, and _variants_. + 1. Set _newTag_ to the string-concatenation of _newTag_ and _allExtensions_. 1. Return _newTag_. @@ -241,8 +242,7 @@

get Intl.Locale.prototype.baseName

1. Let _loc_ be the *this* value. 1. Perform ? RequireInternalSlot(_loc_, [[InitializedLocale]]). - 1. Let _locale_ be _loc_.[[Locale]]. - 1. Return the longest prefix of _locale_ matched by the unicode_language_id Unicode locale nonterminal. + 1. Return GetLocaleBaseName(_loc_.[[Locale]]). @@ -368,6 +368,20 @@

Properties of Intl.Locale Instances

Abstract Operations for Locale Objects

+ +

+ GetLocaleBaseName ( + _locale_: a String, + ): a String +

+
+
+ + 1. Assert: _locale_ can be matched by the unicode_locale_id Unicode locale nonterminal. + 1. Return the longest prefix of _locale_ matched by the unicode_language_id Unicode locale nonterminal. + +
+

GetLocaleLanguage ( @@ -377,10 +391,9 @@

- 1. Assert: _locale_ can be matched by the unicode_locale_id Unicode locale nonterminal. - 1. Let _languageId_ be the longest prefix of _locale_ matched by the unicode_language_id Unicode locale nonterminal. - 1. Assert: The first subtag of _languageId_ can be matched by the unicode_language_subtag Unicode locale nonterminal. - 1. Return the first subtag of _languageId_. + 1. Let _baseName_ be GetLocaleBaseName(_locale_). + 1. Assert: The first subtag of _baseName_ can be matched by the unicode_language_subtag Unicode locale nonterminal. + 1. Return the first subtag of _baseName_. @@ -393,10 +406,9 @@

- 1. Assert: _locale_ can be matched by the unicode_locale_id Unicode locale nonterminal. - 1. Let _languageId_ be the longest prefix of _locale_ matched by the unicode_language_id Unicode locale nonterminal. - 1. Assert: _languageId_ contains at most one subtag that can be matched by the unicode_script_subtag Unicode locale nonterminal. - 1. If _languageId_ contains a subtag matched by the unicode_script_subtag Unicode locale nonterminal, return that subtag. + 1. Let _baseName_ be GetLocaleBaseName(_locale_). + 1. Assert: _baseName_ contains at most one subtag that can be matched by the unicode_script_subtag Unicode locale nonterminal. + 1. If _baseName_ contains a subtag matched by the unicode_script_subtag Unicode locale nonterminal, return that subtag. 1. Return *undefined*. @@ -410,13 +422,12 @@

- 1. Assert: _locale_ can be matched by the unicode_locale_id Unicode locale nonterminal. - 1. Let _languageId_ be the longest prefix of _locale_ matched by the unicode_language_id Unicode locale nonterminal. + 1. Let _baseName_ be GetLocaleBaseName(_locale_). 1. NOTE: A unicode_region_subtag subtag is only valid immediately after an initial unicode_language_subtag subtag, optionally with a single unicode_script_subtag subtag between them. In that position, unicode_region_subtag cannot be confused with any other valid subtag because all their productions are disjoint. - 1. Assert: The first subtag of _languageId_ can be matched by the unicode_language_subtag Unicode locale nonterminal. - 1. Let _languageIdTail_ be the suffix of _languageId_ following the first subtag. - 1. Assert: _languageIdTail_ contains at most one subtag that can be matched by the unicode_region_subtag Unicode locale nonterminal. - 1. If _languageIdTail_ contains a subtag matched by the unicode_region_subtag Unicode locale nonterminal, return that subtag. + 1. Assert: The first subtag of _baseName_ can be matched by the unicode_language_subtag Unicode locale nonterminal. + 1. Let _baseNameTail_ be the suffix of _baseName_ following the first subtag. + 1. Assert: _baseNameTail_ contains at most one subtag that can be matched by the unicode_region_subtag Unicode locale nonterminal. + 1. If _baseNameTail_ contains a subtag matched by the unicode_region_subtag Unicode locale nonterminal, return that subtag. 1. Return *undefined*. @@ -430,9 +441,8 @@

- 1. Assert: _locale_ can be matched by the unicode_locale_id Unicode locale nonterminal. - 1. Let _languageId_ be the longest prefix of _locale_ matched by the unicode_language_id Unicode locale nonterminal. - 1. If there is a non-empty suffix of _languageId_ that is a consecutive sequence of substrings in which each element is a *"-"* followed by a substring that is matched by the unicode_variant_subtag Unicode locale nonterminal, then + 1. Let _baseName_ be GetLocaleBaseName(_locale_). + 1. If there is a non-empty suffix of _baseName_ that is a consecutive sequence of substrings in which each element is a *"-"* followed by a substring that is matched by the unicode_variant_subtag Unicode locale nonterminal, then 1. Let _variants_ be the longest such suffix. 1. Return the substring of _variants_ from 1. 1. Return *undefined*. diff --git a/spec/locales-currencies-tz.html b/spec/locales-currencies-tz.html index 99be4b58..faec8dc2 100644 --- a/spec/locales-currencies-tz.html +++ b/spec/locales-currencies-tz.html @@ -57,11 +57,11 @@

1. Let _lowerLocale_ be the ASCII-lowercase of _locale_. 1. If _lowerLocale_ cannot be matched by the unicode_locale_id Unicode locale nonterminal, return *false*. 1. If _lowerLocale_ uses any of the backwards compatibility syntax described in Unicode Technical Standard #35 Part 1 Core, Section 3.3 BCP 47 Conformance, return *false*. - 1. Let _languageId_ be the longest prefix of _lowerLocale_ matched by the unicode_language_id Unicode locale nonterminal. - 1. Let _variants_ be GetLocaleVariants(_languageId_). + 1. Let _baseName_ be GetLocaleBaseName(_lowerLocale_). + 1. Let _variants_ be GetLocaleVariants(_baseName_). 1. If _variants_ is not *undefined*, then 1. If _variants_ contains any duplicate subtags, return *false*. - 1. Let _allExtensions_ be the suffix of _lowerLocale_ following _languageId_. + 1. Let _allExtensions_ be the suffix of _lowerLocale_ following _baseName_. 1. If _allExtensions_ contains a substring matched by the pu_extensions Unicode locale nonterminal, let _extensions_ be the prefix of _allExtensions_ preceding the longest such substring. Otherwise, let _extensions_ be _allExtensions_. 1. If _extensions_ is not the empty String, then 1. If _extensions_ contains any duplicate singleton subtags, return *false*.