2021-08-24 22:58:45 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								/*
  
						 
					
						
							
								
									
										
										
										
											2023-01-12 10:22:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								 *  Copyright  ( c )  2021 - 2023 ,  Tim  Flynn  < trflynn89 @ serenityos . org > 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 22:58:45 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  SPDX - License - Identifier :  BSD - 2 - Clause 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# include  <AK/AllOf.h> 
  
						 
					
						
							
								
									
										
										
										
											2021-08-28 16:04:55 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# include  <AK/AnyOf.h> 
  
						 
					
						
							
								
									
										
										
										
											2021-08-24 22:58:45 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								# include  <AK/CharacterTypes.h> 
  
						 
					
						
							
								
									
										
										
										
											2021-09-10 11:04:54 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# include  <AK/Find.h> 
  
						 
					
						
							
								
									
										
										
										
											2021-09-04 17:08:57 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# include  <AK/Function.h> 
  
						 
					
						
							
								
									
										
										
										
											2021-08-24 22:58:45 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								# include  <AK/QuickSort.h> 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# include  <AK/TypeCasts.h> 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# include  <LibJS/Runtime/Array.h> 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# include  <LibJS/Runtime/GlobalObject.h> 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# include  <LibJS/Runtime/Intl/AbstractOperations.h> 
  
						 
					
						
							
								
									
										
										
										
											2021-09-01 22:26:06 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# include  <LibJS/Runtime/Intl/Locale.h> 
  
						 
					
						
							
								
									
										
										
										
											2022-09-02 12:11:30 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# include  <LibLocale/Locale.h> 
  
						 
					
						
							
								
									
										
										
										
											2021-08-24 22:58:45 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								namespace  JS : : Intl  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 6.2.2 IsStructurallyValidLanguageTag ( locale ), https://tc39.es/ecma402/#sec-isstructurallyvalidlanguagetag
  
						 
					
						
							
								
									
										
										
										
											2022-09-02 12:01:10 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Optional < : : Locale : : LocaleID >  is_structurally_valid_language_tag ( StringView  locale )  
						 
					
						
							
								
									
										
										
										
											2021-08-24 22:58:45 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
									
										
										
										
											2021-08-30 14:31:48 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    auto  contains_duplicate_variant  =  [ ] ( auto &  variants )  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-28 14:46:36 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        if  ( variants . is_empty ( ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        quick_sort ( variants ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        for  ( size_t  i  =  0 ;  i  <  variants . size ( )  -  1 ;  + + i )  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-01 18:54:30 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            if  ( variants [ i ] . equals_ignoring_case ( variants [ i  +  1 ] ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-28 14:46:36 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                return  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 22:58:45 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    // IsStructurallyValidLanguageTag returns true if all of the following conditions hold, false otherwise:
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // locale can be generated from the EBNF grammar for unicode_locale_id in Unicode Technical Standard #35 LDML § 3.2 Unicode Locale Identifier;
 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-02 12:01:10 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    auto  locale_id  =  : : Locale : : parse_unicode_locale_id ( locale ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 22:58:45 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    if  ( ! locale_id . has_value ( ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return  { } ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // locale does not use any of the backwards compatibility syntax described in Unicode Technical Standard #35 LDML § 3.3 BCP 47 Conformance;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // https://unicode.org/reports/tr35/#BCP_47_Conformance
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( locale . contains ( ' _ ' )  | |  locale_id - > language_id . is_root  | |  ! locale_id - > language_id . language . has_value ( ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return  { } ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // the unicode_language_id within locale contains no duplicate unicode_variant_subtag subtags; and
 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-28 14:46:36 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    if  ( contains_duplicate_variant ( locale_id - > language_id . variants ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return  { } ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 22:58:45 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-08-28 14:46:36 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    // if locale contains an extensions* component, that component
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    Vector < char >  unique_keys ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    for  ( auto &  extension  :  locale_id - > extensions )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // does not contain any other_extensions components with duplicate [alphanum-[tTuUxX]] subtags,
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // contains at most one unicode_locale_extensions component,
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // contains at most one transformed_extensions component, and
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        char  key  =  extension . visit ( 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-02 12:01:10 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            [ ] ( : : Locale : : LocaleExtension  const & )  {  return  ' u ' ;  } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            [ ] ( : : Locale : : TransformedExtension  const & )  {  return  ' t ' ;  } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            [ ] ( : : Locale : : OtherExtension  const &  ext )  {  return  static_cast < char > ( to_ascii_lowercase ( ext . key ) ) ;  } ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-28 14:46:36 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( unique_keys . contains_slow ( key ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            return  { } ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        unique_keys . append ( key ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // if a transformed_extensions component that contains a tlang component is present, then
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // the tlang component contains no duplicate unicode_variant_subtag subtags.
 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-02 12:01:10 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        if  ( auto *  transformed  =  extension . get_pointer < : : Locale : : TransformedExtension > ( ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-28 14:46:36 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            auto &  language  =  transformed - > language ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  ( language . has_value ( )  & &  contains_duplicate_variant ( language - > variants ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 22:58:45 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								                return  { } ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return  locale_id ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 6.2.3 CanonicalizeUnicodeLocaleId ( locale ), https://tc39.es/ecma402/#sec-canonicalizeunicodelocaleid
  
						 
					
						
							
								
									
										
										
										
											2022-12-04 18:02:33 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								DeprecatedString  canonicalize_unicode_locale_id ( : : Locale : : LocaleID &  locale )  
						 
					
						
							
								
									
										
										
										
											2021-08-24 22:58:45 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
									
										
										
										
											2021-08-28 16:04:55 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    // Note: This implementation differs from the spec in how Step 3 is implemented. The spec assumes
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // the input to this method is a string, and is written such that operations are performed on parts
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // of that string. LibUnicode gives us the parsed locale in a structure, so we can mutate that
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // structure directly. From a footnote in the spec:
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    //
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // The third step of this algorithm ensures that a Unicode locale extension sequence in the
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // returned language tag contains:
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    //     * only the first instance of any attribute duplicated in the input, and
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    //     * only the first keyword for a given key in the input.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    for  ( auto &  extension  :  locale . extensions )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-02 12:01:10 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        if  ( ! extension . has < : : Locale : : LocaleExtension > ( ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-28 16:04:55 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            continue ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-09-02 12:01:10 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        auto &  locale_extension  =  extension . get < : : Locale : : LocaleExtension > ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-28 16:04:55 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        auto  attributes  =  move ( locale_extension . attributes ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        for  ( auto &  attribute  :  attributes )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  ( ! locale_extension . attributes . contains_slow ( attribute ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                locale_extension . attributes . append ( move ( attribute ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        auto  keywords  =  move ( locale_extension . keywords ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        for  ( auto &  keyword  :  keywords )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  ( ! any_of ( locale_extension . keywords ,  [ & ] ( auto  const &  k )  {  return  k . key  = =  keyword . key ;  } ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                locale_extension . keywords . append ( move ( keyword ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 22:58:45 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    // 1. Let localeId be the string locale after performing the algorithm to transform it to canonical syntax per Unicode Technical Standard #35 LDML § 3.2.1 Canonical Unicode Locale Identifiers.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // 2. Let localeId be the string localeId after performing the algorithm to transform it to canonical form.
 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-02 12:01:10 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    auto  locale_id  =  : : Locale : : canonicalize_unicode_locale_id ( locale ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 22:58:45 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    VERIFY ( locale_id . has_value ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // 4. Return localeId.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return  locale_id . release_value ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-03-28 09:53:06 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// 6.3.1 IsWellFormedCurrencyCode ( currency ), https://tc39.es/ecma402/#sec-iswellformedcurrencycode
  
						 
					
						
							
								
									
										
										
										
											2021-09-10 11:04:54 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								bool  is_well_formed_currency_code ( StringView  currency )  
						 
					
						
							
								
									
										
										
										
											2021-08-24 22:58:45 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
									
										
										
										
											2022-03-28 09:53:06 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    // 1. If the length of currency is not 3, return false.
 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 22:58:45 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    if  ( currency . length ( )  ! =  3 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-03-28 09:53:06 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    // 2. Let normalized be the ASCII-uppercase of currency.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // 3. If normalized contains any code unit outside of 0x0041 through 0x005A (corresponding to Unicode characters LATIN CAPITAL LETTER A through LATIN CAPITAL LETTER Z), return false.
 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 22:58:45 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    if  ( ! all_of ( currency ,  is_ascii_alpha ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // 4. Return true.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-09-10 11:04:54 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// 6.5.1 IsWellFormedUnitIdentifier ( unitIdentifier ), https://tc39.es/ecma402/#sec-iswellformedunitidentifier
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								bool  is_well_formed_unit_identifier ( StringView  unit_identifier )  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
									
										
										
										
											2022-03-28 12:05:18 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    // 6.5.2 IsSanctionedSingleUnitIdentifier ( unitIdentifier ), https://tc39.es/ecma402/#sec-issanctionedsingleunitidentifier
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    constexpr  auto  is_sanctioned_single_unit_identifier  =  [ ] ( StringView  unit_identifier )  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-10 11:04:54 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        // 1. If unitIdentifier is listed in Table 2 below, return true.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // 2. Else, return false.
 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-28 12:05:18 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        static  constexpr  auto  sanctioned_units  =  sanctioned_single_unit_identifiers ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-10 11:04:54 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        return  find ( sanctioned_units . begin ( ) ,  sanctioned_units . end ( ) ,  unit_identifier )  ! =  sanctioned_units . end ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-03-28 12:05:18 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    // 1. If ! IsSanctionedSingleUnitIdentifier(unitIdentifier) is true, then
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( is_sanctioned_single_unit_identifier ( unit_identifier ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-10 11:04:54 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        // a. Return true.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-05-02 20:54:39 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    // 2. Let i be StringIndexOf(unitIdentifier, "-per-", 0).
 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-10 11:04:54 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    auto  indices  =  unit_identifier . find_all ( " -per- " sv ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-05-02 20:54:39 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    // 3. If i is -1 or StringIndexOf(unitIdentifier, "-per-", i + 1) is not -1, then
 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-10 11:04:54 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    if  ( indices . size ( )  ! =  1 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // a. Return false.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-03-28 12:05:18 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    // 4. Assert: The five-character substring "-per-" occurs exactly once in unitIdentifier, at index i.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // NOTE: We skip this because the indices vector being of size 1 already verifies this invariant.
 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-10 11:04:54 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-03-28 12:05:18 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    // 5. Let numerator be the substring of unitIdentifier from 0 to i.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    auto  numerator  =  unit_identifier . substring_view ( 0 ,  indices [ 0 ] ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-10 11:04:54 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-03-28 12:05:18 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    // 6. Let denominator be the substring of unitIdentifier from i + 5.
 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-10 11:04:54 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    auto  denominator  =  unit_identifier . substring_view ( indices [ 0 ]  +  5 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-03-28 12:05:18 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    // 7. If ! IsSanctionedSingleUnitIdentifier(numerator) and ! IsSanctionedSingleUnitIdentifier(denominator) are both true, then
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( is_sanctioned_single_unit_identifier ( numerator )  & &  is_sanctioned_single_unit_identifier ( denominator ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // a. Return true.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return  true ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-10 11:04:54 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-03-28 12:05:18 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    // 8. Return false.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return  false ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-10 11:04:54 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 22:58:45 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								// 9.2.1 CanonicalizeLocaleList ( locales ), https://tc39.es/ecma402/#sec-canonicalizelocalelist
  
						 
					
						
							
								
									
										
										
										
											2022-12-04 18:02:33 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								ThrowCompletionOr < Vector < DeprecatedString > >  canonicalize_locale_list ( VM &  vm ,  Value  locales )  
						 
					
						
							
								
									
										
										
										
											2021-08-24 22:58:45 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
									
										
										
										
											2022-08-20 08:25:24 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    auto &  realm  =  * vm . current_realm ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 22:58:45 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // 1. If locales is undefined, then
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( locales . is_undefined ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // a. Return a new empty List.
 
							 
						 
					
						
							
								
									
										
										
										
											2022-12-04 18:02:33 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        return  Vector < DeprecatedString >  { } ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 22:58:45 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // 2. Let seen be a new empty List.
 
							 
						 
					
						
							
								
									
										
										
										
											2022-12-04 18:02:33 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    Vector < DeprecatedString >  seen ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 22:58:45 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    Object *  object  =  nullptr ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // 3. If Type(locales) is String or Type(locales) is Object and locales has an [[InitializedLocale]] internal slot, then
 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-01 22:26:06 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    if  ( locales . is_string ( )  | |  ( locales . is_object ( )  & &  is < Locale > ( locales . as_object ( ) ) ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-05-02 20:54:39 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        // a. Let O be CreateArrayFromList(« locales »).
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-16 00:20:49 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        object  =  Array : : create_from ( realm ,  {  locales  } ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 22:58:45 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // 4. Else,
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // a. Let O be ? ToObject(locales).
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-21 14:00:56 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        object  =  TRY ( locales . to_object ( vm ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 22:58:45 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // 5. Let len be ? ToLength(? Get(O, "length")).
 
							 
						 
					
						
							
								
									
										
										
										
											2021-10-17 23:57:37 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    auto  length_value  =  TRY ( object - > get ( vm . names . length ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-21 14:00:56 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    auto  length  =  TRY ( length_value . to_length ( vm ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 22:58:45 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // 6. Let k be 0.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // 7. Repeat, while k < len,
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    for  ( size_t  k  =  0 ;  k  <  length ;  + + k )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // a. Let Pk be ToString(k).
 
							 
						 
					
						
							
								
									
										
										
										
											2021-10-24 16:01:24 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        auto  property_key  =  PropertyKey  {  k  } ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 22:58:45 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // b. Let kPresent be ? HasProperty(O, Pk).
 
							 
						 
					
						
							
								
									
										
										
										
											2021-10-03 02:00:39 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        auto  key_present  =  TRY ( object - > has_property ( property_key ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 22:58:45 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // c. If kPresent is true, then
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( key_present )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            // i. Let kValue be ? Get(O, Pk).
 
							 
						 
					
						
							
								
									
										
										
										
											2021-10-02 23:52:27 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            auto  key_value  =  TRY ( object - > get ( property_key ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 22:58:45 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            // ii. If Type(kValue) is not String or Object, throw a TypeError exception.
 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-18 19:24:28 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            if  ( ! key_value . is_string ( )  & &  ! key_value . is_object ( ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-16 20:33:17 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                return  vm . throw_completion < TypeError > ( ErrorType : : NotAnObjectOrString ,  key_value . to_string_without_side_effects ( ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 22:58:45 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-12-04 18:02:33 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            DeprecatedString  tag ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-01 22:26:06 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 22:58:45 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								            // iii. If Type(kValue) is Object and kValue has an [[InitializedLocale]] internal slot, then
 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-01 22:26:06 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            if  ( key_value . is_object ( )  & &  is < Locale > ( key_value . as_object ( ) ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                // 1. Let tag be kValue.[[Locale]].
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                tag  =  static_cast < Locale  const & > ( key_value . as_object ( ) ) . locale ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 22:58:45 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								            // iv. Else,
 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-01 22:26:06 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                // 1. Let tag be ? ToString(kValue).
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-21 14:00:56 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                tag  =  TRY ( key_value . to_string ( vm ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-01 22:26:06 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 22:58:45 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-03-28 08:30:48 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            // v. If ! IsStructurallyValidLanguageTag(tag) is false, throw a RangeError exception.
 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 22:58:45 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								            auto  locale_id  =  is_structurally_valid_language_tag ( tag ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-18 19:24:28 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            if  ( ! locale_id . has_value ( ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-16 20:33:17 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                return  vm . throw_completion < RangeError > ( ErrorType : : IntlInvalidLanguageTag ,  tag ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 22:58:45 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-03-28 08:30:48 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            // vi. Let canonicalizedTag be ! CanonicalizeUnicodeLocaleId(tag).
 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 22:58:45 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								            auto  canonicalized_tag  =  JS : : Intl : : canonicalize_unicode_locale_id ( * locale_id ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            // vii. If canonicalizedTag is not an element of seen, append canonicalizedTag as the last element of seen.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  ( ! seen . contains_slow ( canonicalized_tag ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                seen . append ( move ( canonicalized_tag ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // d. Increase k by 1.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return  seen ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 9.2.2 BestAvailableLocale ( availableLocales, locale ), https://tc39.es/ecma402/#sec-bestavailablelocale
  
						 
					
						
							
								
									
										
										
										
											2022-12-04 18:02:33 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Optional < DeprecatedString >  best_available_locale ( StringView  locale )  
						 
					
						
							
								
									
										
										
										
											2021-08-24 22:58:45 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // 1. Let candidate be locale.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    StringView  candidate  =  locale ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // 2. Repeat,
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    while  ( true )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // a. If availableLocales contains an element equal to candidate, return candidate.
 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-02 12:01:10 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        if  ( : : Locale : : is_locale_available ( candidate ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 22:58:45 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								            return  candidate ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // b. Let pos be the character index of the last occurrence of "-" (U+002D) within candidate. If that character does not occur, return undefined.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        auto  pos  =  candidate . find_last ( ' - ' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( ! pos . has_value ( ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            return  { } ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // c. If pos ≥ 2 and the character "-" occurs at index pos-2 of candidate, decrease pos by 2.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( ( * pos  > =  2 )  & &  ( candidate [ * pos  -  2 ]  = =  ' - ' ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            pos  =  * pos  -  2 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // d. Let candidate be the substring of candidate from position 0, inclusive, to position pos, exclusive.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        candidate  =  candidate . substring_view ( 0 ,  * pos ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-08-30 08:51:52 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								struct  MatcherResult  {  
						 
					
						
							
								
									
										
										
										
											2022-12-04 18:02:33 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    DeprecatedString  locale ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-02 12:01:10 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    Vector < : : Locale : : Extension >  extensions  { } ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-30 08:51:52 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 22:58:45 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								// 9.2.3 LookupMatcher ( availableLocales, requestedLocales ), https://tc39.es/ecma402/#sec-lookupmatcher
  
						 
					
						
							
								
									
										
										
										
											2022-12-04 18:02:33 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								static  MatcherResult  lookup_matcher ( Vector < DeprecatedString >  const &  requested_locales )  
						 
					
						
							
								
									
										
										
										
											2021-08-24 22:58:45 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // 1. Let result be a new Record.
 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-30 08:51:52 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    MatcherResult  result  { } ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 22:58:45 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // 2. For each element locale of requestedLocales, do
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    for  ( auto  const &  locale  :  requested_locales )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-02 12:01:10 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        auto  locale_id  =  : : Locale : : parse_unicode_locale_id ( locale ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-30 08:51:52 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        VERIFY ( locale_id . has_value ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 22:58:45 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        // a. Let noExtensionsLocale be the String value that is locale with any Unicode locale extension sequences removed.
 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-02 12:01:10 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        auto  extensions  =  locale_id - > remove_extension_type < : : Locale : : LocaleExtension > ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-12-06 01:12:49 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        auto  no_extensions_locale  =  locale_id - > to_deprecated_string ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 22:58:45 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-03-28 08:30:48 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        // b. Let availableLocale be ! BestAvailableLocale(availableLocales, noExtensionsLocale).
 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 22:58:45 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        auto  available_locale  =  best_available_locale ( no_extensions_locale ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // c. If availableLocale is not undefined, then
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( available_locale . has_value ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            // i. Set result.[[locale]] to availableLocale.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            result . locale  =  available_locale . release_value ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            // ii. If locale and noExtensionsLocale are not the same String value, then
 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-30 08:51:52 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            if  ( locale  ! =  no_extensions_locale )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                // 1. Let extension be the String value consisting of the substring of the Unicode locale extension sequence within locale.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                // 2. Set result.[[extension]] to extension.
 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-05 18:31:22 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                result . extensions . extend ( move ( extensions ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-30 08:51:52 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 22:58:45 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            // iii. Return result.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            return  result ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-03-28 08:30:48 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    // 3. Let defLocale be ! DefaultLocale().
 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 22:58:45 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    // 4. Set result.[[locale]] to defLocale.
 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-02 12:01:10 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    result . locale  =  : : Locale : : default_locale ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 22:58:45 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // 5. Return result.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return  result ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 9.2.4 BestFitMatcher ( availableLocales, requestedLocales ), https://tc39.es/ecma402/#sec-bestfitmatcher
  
						 
					
						
							
								
									
										
										
										
											2022-12-04 18:02:33 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								static  MatcherResult  best_fit_matcher ( Vector < DeprecatedString >  const &  requested_locales )  
						 
					
						
							
								
									
										
										
										
											2021-08-24 22:58:45 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // The algorithm is implementation dependent, but should produce results that a typical user of the requested locales would
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // perceive as at least as good as those produced by the LookupMatcher abstract operation.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return  lookup_matcher ( requested_locales ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-09-01 22:08:15 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// 9.2.6 InsertUnicodeExtensionAndCanonicalize ( locale, extension ), https://tc39.es/ecma402/#sec-insert-unicode-extension-and-canonicalize
  
						 
					
						
							
								
									
										
										
										
											2022-12-04 18:02:33 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								DeprecatedString  insert_unicode_extension_and_canonicalize ( : : Locale : : LocaleID  locale ,  : : Locale : : LocaleExtension  extension )  
						 
					
						
							
								
									
										
										
										
											2021-09-01 22:08:15 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // Note: This implementation differs from the spec in how the extension is inserted. The spec assumes
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // the input to this method is a string, and is written such that operations are performed on parts
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // of that string. LibUnicode gives us the parsed locale in a structure, so we can mutate that
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // structure directly.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    locale . extensions . append ( move ( extension ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return  JS : : Intl : : canonicalize_unicode_locale_id ( locale ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-09-10 10:01:41 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								template < typename  T >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								static  auto &  find_key_in_value ( T &  value ,  StringView  key )  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
									
										
										
										
											2021-11-28 17:55:47 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    if  ( key  = =  " ca " sv ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return  value . ca ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-29 11:30:46 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    if  ( key  = =  " co " sv ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return  value . co ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-11-28 17:55:47 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    if  ( key  = =  " hc " sv ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return  value . hc ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-29 11:30:46 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    if  ( key  = =  " kf " sv ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return  value . kf ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( key  = =  " kn " sv ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return  value . kn ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-10 11:04:54 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    if  ( key  = =  " nu " sv ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return  value . nu ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-09-10 10:01:41 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    // If you hit this point, you must add any missing keys from [[RelevantExtensionKeys]] to LocaleOptions and LocaleResult.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    VERIFY_NOT_REACHED ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 22:58:45 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								// 9.2.7 ResolveLocale ( availableLocales, requestedLocales, options, relevantExtensionKeys, localeData ), https://tc39.es/ecma402/#sec-resolvelocale
  
						 
					
						
							
								
									
										
										
										
											2023-01-07 12:24:05 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								ThrowCompletionOr < LocaleResult >  resolve_locale ( Vector < DeprecatedString >  const &  requested_locales ,  LocaleOptions  const &  options ,  Span < StringView  const >  relevant_extension_keys )  
						 
					
						
							
								
									
										
										
										
											2021-08-24 22:58:45 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // 1. Let matcher be options.[[localeMatcher]].
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    auto  const &  matcher  =  options . locale_matcher ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-30 08:51:52 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    MatcherResult  matcher_result ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 22:58:45 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // 2. If matcher is "lookup", then
 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-07 12:24:05 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    if  ( matcher . is_string ( )  & &  ( TRY ( matcher . as_string ( ) . deprecated_string ( ) )  = =  " lookup " sv ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-28 08:30:48 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        // a. Let r be ! LookupMatcher(availableLocales, requestedLocales).
 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-30 08:51:52 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        matcher_result  =  lookup_matcher ( requested_locales ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 22:58:45 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // 3. Else,
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    else  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-28 08:30:48 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        // a. Let r be ! BestFitMatcher(availableLocales, requestedLocales).
 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-30 08:51:52 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        matcher_result  =  best_fit_matcher ( requested_locales ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 22:58:45 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-30 08:51:52 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 22:58:45 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    // 4. Let foundLocale be r.[[locale]].
 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-30 08:51:52 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    auto  found_locale  =  move ( matcher_result . locale ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 22:58:45 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    // 5. Let result be a new Record.
 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-30 08:51:52 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    LocaleResult  result  { } ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 22:58:45 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    // 6. Set result.[[dataLocale]] to foundLocale.
 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-10 10:01:41 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    result . data_locale  =  found_locale ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 22:58:45 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // 7. If r has an [[extension]] field, then
 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-02 12:01:10 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    Vector < : : Locale : : Keyword >  keywords ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-10 10:01:41 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    for  ( auto &  extension  :  matcher_result . extensions )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-02 12:01:10 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        if  ( ! extension . has < : : Locale : : LocaleExtension > ( ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-10 10:01:41 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            continue ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // a. Let components be ! UnicodeExtensionComponents(r.[[extension]]).
 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-02 12:01:10 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        auto &  components  =  extension . get < : : Locale : : LocaleExtension > ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-10 10:01:41 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        // b. Let keywords be components.[[Keywords]].
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        keywords  =  move ( components . keywords ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 22:58:45 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    // 8. Let supportedExtension be "-u".
 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-02 12:01:10 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    : : Locale : : LocaleExtension  supported_extension  { } ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-10 10:01:41 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 22:58:45 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    // 9. For each element key of relevantExtensionKeys, do
 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-10 10:01:41 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    for  ( auto  const &  key  :  relevant_extension_keys )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // a. Let foundLocaleData be localeData.[[<foundLocale>]].
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // b. Assert: Type(foundLocaleData) is Record.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // c. Let keyLocaleData be foundLocaleData.[[<key>]].
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // d. Assert: Type(keyLocaleData) is List.
 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-02 12:01:10 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        auto  key_locale_data  =  : : Locale : : get_available_keyword_values ( key ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-10 10:01:41 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // e. Let value be keyLocaleData[0].
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // f. Assert: Type(value) is either String or Null.
 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-14 13:55:13 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        // NOTE: ECMA-402 assumes keyLocaleData is sorted by locale preference. Our list is sorted
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        //       alphabetically, so we get the locale's preferred value from LibUnicode.
 
							 
						 
					
						
							
								
									
										
										
										
											2022-12-04 18:02:33 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Optional < DeprecatedString >  value ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-02 12:01:10 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        if  ( auto  preference  =  : : Locale : : get_preferred_keyword_value_for_locale ( found_locale ,  key ) ;  preference . has_value ( ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-14 13:55:13 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            value  =  * preference ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-10 10:01:41 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // g. Let supportedExtensionAddition be "".
 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-02 12:01:10 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Optional < : : Locale : : Keyword >  supported_extension_addition  { } ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-10 10:01:41 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // h. If r has an [[extension]] field, then
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        for  ( auto &  entry  :  keywords )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            // i. If keywords contains an element whose [[Key]] is the same as key, then
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  ( entry . key  ! =  key ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                continue ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            // 1. Let entry be the element of keywords whose [[Key]] is the same as key.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            // 2. Let requestedValue be entry.[[Value]].
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            auto  requested_value  =  entry . value ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            // 3. If requestedValue is not the empty String, then
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  ( ! requested_value . is_empty ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                // a. If keyLocaleData contains requestedValue, then
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                if  ( key_locale_data . contains_slow ( requested_value ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    // i. Let value be requestedValue.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    value  =  move ( requested_value ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    // ii. Let supportedExtensionAddition be the string-concatenation of "-", key, "-", and value.
 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-02 12:01:10 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                    supported_extension_addition  =  : : Locale : : Keyword  {  key ,  move ( entry . value )  } ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-10 10:01:41 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            // 4. Else if keyLocaleData contains "true", then
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            else  if  ( key_locale_data . contains_slow ( " true " sv ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                // a. Let value be "true".
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                value  =  " true " sv ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                // b. Let supportedExtensionAddition be the string-concatenation of "-" and key.
 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-02 12:01:10 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                supported_extension_addition  =  : : Locale : : Keyword  {  key ,  { }  } ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-10 10:01:41 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // i. If options has a field [[<key>]], then
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // i. Let optionsValue be options.[[<key>]].
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // ii. Assert: Type(optionsValue) is either String, Undefined, or Null.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        auto  options_value  =  find_key_in_value ( options ,  key ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // iii. If Type(optionsValue) is String, then
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( options_value . has_value ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            // 1. Let optionsValue be the string optionsValue after performing the algorithm steps to transform Unicode extension values to canonical syntax per Unicode Technical Standard #35 LDML § 3.2.1 Canonical Unicode Locale Identifiers, treating key as ukey and optionsValue as uvalue productions.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            // 2. Let optionsValue be the string optionsValue after performing the algorithm steps to replace Unicode extension values with their canonical form per Unicode Technical Standard #35 LDML § 3.2.1 Canonical Unicode Locale Identifiers, treating key as ukey and optionsValue as uvalue productions.
 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-02 12:01:10 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            : : Locale : : canonicalize_unicode_extension_values ( key ,  * options_value ,  true ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-10 10:01:41 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            // 3. If optionsValue is the empty String, then
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  ( options_value - > is_empty ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                // a. Let optionsValue be "true".
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                options_value  =  " true " sv ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // iv. If keyLocaleData contains optionsValue, then
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( options_value . has_value ( )  & &  key_locale_data . contains_slow ( * options_value ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            // 1. If SameValue(optionsValue, value) is false, then
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  ( options_value  ! =  value )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                // a. Let value be optionsValue.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                value  =  move ( options_value ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                // b. Let supportedExtensionAddition be "".
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                supported_extension_addition . clear ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // j. Set result.[[<key>]] to value.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        find_key_in_value ( result ,  key )  =  move ( value ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // k. Append supportedExtensionAddition to supportedExtension.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( supported_extension_addition . has_value ( ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            supported_extension . keywords . append ( supported_extension_addition . release_value ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 22:58:45 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    // 10. If the number of elements in supportedExtension is greater than 2, then
 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-10 10:01:41 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    if  ( ! supported_extension . keywords . is_empty ( ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-02 12:01:10 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        auto  locale_id  =  : : Locale : : parse_unicode_locale_id ( found_locale ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-10 10:01:41 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        VERIFY ( locale_id . has_value ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // a. Let foundLocale be InsertUnicodeExtensionAndCanonicalize(foundLocale, supportedExtension).
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        found_locale  =  insert_unicode_extension_and_canonicalize ( locale_id . release_value ( ) ,  move ( supported_extension ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-30 08:51:52 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 22:58:45 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    // 11. Set result.[[locale]] to foundLocale.
 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-30 08:51:52 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    result . locale  =  move ( found_locale ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 22:58:45 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // 12. Return result.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return  result ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-09-04 17:08:57 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// 9.2.8 LookupSupportedLocales ( availableLocales, requestedLocales ), https://tc39.es/ecma402/#sec-lookupsupportedlocales
  
						 
					
						
							
								
									
										
										
										
											2022-12-04 18:02:33 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Vector < DeprecatedString >  lookup_supported_locales ( Vector < DeprecatedString >  const &  requested_locales )  
						 
					
						
							
								
									
										
										
										
											2021-09-04 17:08:57 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // 1. Let subset be a new empty List.
 
							 
						 
					
						
							
								
									
										
										
										
											2022-12-04 18:02:33 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    Vector < DeprecatedString >  subset ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-04 17:08:57 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // 2. For each element locale of requestedLocales, do
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    for  ( auto  const &  locale  :  requested_locales )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-02 12:01:10 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        auto  locale_id  =  : : Locale : : parse_unicode_locale_id ( locale ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-04 17:08:57 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        VERIFY ( locale_id . has_value ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // a. Let noExtensionsLocale be the String value that is locale with any Unicode locale extension sequences removed.
 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-02 12:01:10 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        locale_id - > remove_extension_type < : : Locale : : LocaleExtension > ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-12-06 01:12:49 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        auto  no_extensions_locale  =  locale_id - > to_deprecated_string ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-04 17:08:57 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-03-28 08:30:48 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        // b. Let availableLocale be ! BestAvailableLocale(availableLocales, noExtensionsLocale).
 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-04 17:08:57 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        auto  available_locale  =  best_available_locale ( no_extensions_locale ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // c. If availableLocale is not undefined, append locale to the end of subset.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( available_locale . has_value ( ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            subset . append ( locale ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // 3. Return subset.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return  subset ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 9.2.9 BestFitSupportedLocales ( availableLocales, requestedLocales ), https://tc39.es/ecma402/#sec-bestfitsupportedlocales
  
						 
					
						
							
								
									
										
										
										
											2022-12-04 18:02:33 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Vector < DeprecatedString >  best_fit_supported_locales ( Vector < DeprecatedString >  const &  requested_locales )  
						 
					
						
							
								
									
										
										
										
											2021-09-04 17:08:57 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // The BestFitSupportedLocales abstract operation returns the subset of the provided BCP 47
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // language priority list requestedLocales for which availableLocales has a matching locale
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // when using the Best Fit Matcher algorithm. Locales appear in the same order in the returned
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // list as in requestedLocales. The steps taken are implementation dependent.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // :yakbrain:
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return  lookup_supported_locales ( requested_locales ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 9.2.10 SupportedLocales ( availableLocales, requestedLocales, options ), https://tc39.es/ecma402/#sec-supportedlocales
  
						 
					
						
							
								
									
										
										
										
											2022-12-04 18:02:33 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								ThrowCompletionOr < Array * >  supported_locales ( VM &  vm ,  Vector < DeprecatedString >  const &  requested_locales ,  Value  options )  
						 
					
						
							
								
									
										
										
										
											2021-09-04 17:08:57 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
									
										
										
										
											2022-08-20 08:25:24 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    auto &  realm  =  * vm . current_realm ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-04 17:08:57 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // 1. Set options to ? CoerceOptionsToObject(options).
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-20 08:25:24 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    auto *  options_object  =  TRY ( coerce_options_to_object ( vm ,  options ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-04 17:08:57 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-01-12 10:22:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    // 2. Let matcher be ? GetOption(options, "localeMatcher", string, « "lookup", "best fit" », "best fit").
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-20 08:52:42 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    auto  matcher  =  TRY ( get_option ( vm ,  * options_object ,  vm . names . localeMatcher ,  OptionType : : String ,  {  " lookup " sv ,  " best fit " sv  } ,  " best fit " sv ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-04 17:08:57 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-12-04 18:02:33 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    Vector < DeprecatedString >  supported_locales ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-04 17:08:57 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // 3. If matcher is "best fit", then
 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-07 12:24:05 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    if  ( TRY ( matcher . as_string ( ) . deprecated_string ( ) )  = =  " best fit " sv )  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-04 17:08:57 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        // a. Let supportedLocales be BestFitSupportedLocales(availableLocales, requestedLocales).
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        supported_locales  =  best_fit_supported_locales ( requested_locales ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // 4. Else,
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // a. Let supportedLocales be LookupSupportedLocales(availableLocales, requestedLocales).
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        supported_locales  =  lookup_supported_locales ( requested_locales ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-05-02 20:54:39 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    // 5. Return CreateArrayFromList(supportedLocales).
 
							 
						 
					
						
							
								
									
										
										
										
											2022-12-13 20:49:49 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    return  Array : : create_from < DeprecatedString > ( realm ,  supported_locales ,  [ & vm ] ( auto &  locale )  {  return  PrimitiveString : : create ( vm ,  locale ) ;  } ) . ptr ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-04 17:08:57 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-09-01 22:08:15 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// 9.2.12 CoerceOptionsToObject ( options ), https://tc39.es/ecma402/#sec-coerceoptionstoobject
  
						 
					
						
							
								
									
										
										
										
											2022-08-20 08:25:24 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								ThrowCompletionOr < Object * >  coerce_options_to_object ( VM &  vm ,  Value  options )  
						 
					
						
							
								
									
										
										
										
											2021-09-01 22:08:15 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
									
										
										
										
											2022-08-20 08:25:24 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    auto &  realm  =  * vm . current_realm ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-16 00:20:49 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-09-01 22:08:15 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    // 1. If options is undefined, then
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( options . is_undefined ( ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-05-02 20:54:39 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        // a. Return OrdinaryObjectCreate(null).
 
							 
						 
					
						
							
								
									
										
										
										
											2022-12-13 20:49:50 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        return  Object : : create ( realm ,  nullptr ) . ptr ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-01 22:08:15 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // 2. Return ? ToObject(options).
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-21 14:00:56 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    return  TRY ( options . to_object ( vm ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-01 22:08:15 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-06-14 23:03:25 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// NOTE: 9.2.13 GetOption has been removed and is being pulled in from ECMA-262 in the Temporal proposal.
  
						 
					
						
							
								
									
										
										
										
											2021-08-24 22:58:45 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-07-12 13:18:23 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// 1.2.12 GetStringOrBooleanOption ( options, property, values, trueValue, falsyValue, fallback ), https://tc39.es/proposal-intl-numberformat-v3/out/negotiation/proposed.html#sec-getstringorbooleanoption
  
						 
					
						
							
								
									
										
										
										
											2022-08-20 08:25:24 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								ThrowCompletionOr < StringOrBoolean >  get_string_or_boolean_option ( VM &  vm ,  Object  const &  options ,  PropertyKey  const &  property ,  Span < StringView  const >  values ,  StringOrBoolean  true_value ,  StringOrBoolean  falsy_value ,  StringOrBoolean  fallback )  
						 
					
						
							
								
									
										
										
										
											2022-07-12 13:18:23 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // 1. Let value be ? Get(options, property).
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    auto  value  =  TRY ( options . get ( property ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // 2. If value is undefined, return fallback.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( value . is_undefined ( ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return  fallback ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // 3. If value is true, return trueValue.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( value . is_boolean ( )  & &  value . as_bool ( ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return  true_value ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // 4. Let valueBoolean be ToBoolean(value).
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    auto  value_boolean  =  value . to_boolean ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // 5. If valueBoolean is false, return falsyValue.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( ! value_boolean ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return  falsy_value ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // 6. Let value be ? ToString(value).
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-21 14:00:56 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    auto  value_string  =  TRY ( value . to_string ( vm ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-12 13:18:23 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-09-13 11:00:58 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    // 7. NOTE: For historical reasons, the strings "true" and "false" are treated the same as the boolean value true.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // 8. If value is "true" or "false", return fallback.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( value_string . is_one_of ( " true " sv ,  " false " sv ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return  fallback ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // 9. If values does not contain an element equal to value, throw a RangeError exception.
 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-12 13:18:23 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    auto  it  =  find ( values . begin ( ) ,  values . end ( ) ,  value_string ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( it  = =  values . end ( ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-13 11:00:58 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        return  vm . throw_completion < RangeError > ( ErrorType : : OptionIsNotValidValue ,  value_string ,  property . as_string ( ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-12 13:18:23 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-09-13 11:00:58 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    // 10. Return value.
 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-12 13:18:23 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    return  StringOrBoolean  {  * it  } ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-09-10 11:04:54 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// 9.2.14 DefaultNumberOption ( value, minimum, maximum, fallback ), https://tc39.es/ecma402/#sec-defaultnumberoption
  
						 
					
						
							
								
									
										
										
										
											2022-08-20 08:25:24 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								ThrowCompletionOr < Optional < int > >  default_number_option ( VM &  vm ,  Value  value ,  int  minimum ,  int  maximum ,  Optional < int >  fallback )  
						 
					
						
							
								
									
										
										
										
											2021-09-10 11:04:54 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // 1. If value is undefined, return fallback.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( value . is_undefined ( ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return  fallback ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-11-24 08:51:03 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    // 2. Set value to ? ToNumber(value).
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-21 14:00:56 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    value  =  TRY ( value . to_number ( vm ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-10 11:04:54 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // 3. If value is NaN or less than minimum or greater than maximum, throw a RangeError exception.
 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-18 19:37:39 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    if  ( value . is_nan ( )  | |  ( value . as_double ( )  <  minimum )  | |  ( value . as_double ( )  >  maximum ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-16 20:33:17 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        return  vm . throw_completion < RangeError > ( ErrorType : : IntlNumberIsNaNOrOutOfRange ,  value ,  minimum ,  maximum ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-10 11:04:54 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // 4. Return floor(value).
 
							 
						 
					
						
							
								
									
										
										
										
											2021-10-20 19:17:45 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    return  floor ( value . as_double ( ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-10 11:04:54 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 9.2.15 GetNumberOption ( options, property, minimum, maximum, fallback ), https://tc39.es/ecma402/#sec-getnumberoption
  
						 
					
						
							
								
									
										
										
										
											2022-08-20 08:25:24 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								ThrowCompletionOr < Optional < int > >  get_number_option ( VM &  vm ,  Object  const &  options ,  PropertyKey  const &  property ,  int  minimum ,  int  maximum ,  Optional < int >  fallback )  
						 
					
						
							
								
									
										
										
										
											2021-09-10 11:04:54 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // 1. Assert: Type(options) is Object.
 
							 
						 
					
						
							
								
									
										
										
										
											2021-10-02 23:52:27 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-09-10 11:04:54 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    // 2. Let value be ? Get(options, property).
 
							 
						 
					
						
							
								
									
										
										
										
											2021-10-02 23:52:27 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    auto  value  =  TRY ( options . get ( property ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-10 11:04:54 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // 3. Return ? DefaultNumberOption(value, minimum, maximum, fallback).
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-20 08:25:24 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    return  default_number_option ( vm ,  value ,  minimum ,  maximum ,  move ( fallback ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-10 11:04:54 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-09-06 14:37:23 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// 9.2.16 PartitionPattern ( pattern ), https://tc39.es/ecma402/#sec-partitionpattern
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Vector < PatternPartition >  partition_pattern ( StringView  pattern )  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // 1. Let result be a new empty List.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    Vector < PatternPartition >  result ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-05-02 20:54:39 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    // 2. Let beginIndex be StringIndexOf(pattern, "{", 0).
 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-06 14:37:23 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    auto  begin_index  =  pattern . find ( ' { ' ,  0 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // 3. Let endIndex be 0.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    size_t  end_index  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // 4. Let nextIndex be 0.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    size_t  next_index  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // 5. Let length be the number of code units in pattern.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // 6. Repeat, while beginIndex is an integer index into pattern,
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    while  ( begin_index . has_value ( ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-05-02 20:54:39 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        // a. Set endIndex to StringIndexOf(pattern, "}", beginIndex).
 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-06 14:37:23 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        end_index  =  pattern . find ( ' } ' ,  * begin_index ) . value ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // b. Assert: endIndex is greater than beginIndex.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        VERIFY ( end_index  >  * begin_index ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // c. If beginIndex is greater than nextIndex, then
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( * begin_index  >  next_index )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            // i. Let literal be a substring of pattern from position nextIndex, inclusive, to position beginIndex, exclusive.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            auto  literal  =  pattern . substring_view ( next_index ,  * begin_index  -  next_index ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            // ii. Append a new Record { [[Type]]: "literal", [[Value]]: literal } as the last element of the list result.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            result . append ( {  " literal " sv ,  literal  } ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // d. Let p be the substring of pattern from position beginIndex, exclusive, to position endIndex, exclusive.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        auto  partition  =  pattern . substring_view ( * begin_index  +  1 ,  end_index  -  * begin_index  -  1 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // e. Append a new Record { [[Type]]: p, [[Value]]: undefined } as the last element of the list result.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        result . append ( {  partition ,  { }  } ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // f. Set nextIndex to endIndex + 1.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        next_index  =  end_index  +  1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-05-02 20:54:39 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        // g. Set beginIndex to StringIndexOf(pattern, "{", nextIndex).
 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-06 14:37:23 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        begin_index  =  pattern . find ( ' { ' ,  next_index ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // 7. If nextIndex is less than length, then
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( next_index  <  pattern . length ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // a. Let literal be the substring of pattern from position nextIndex, inclusive, to position length, exclusive.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        auto  literal  =  pattern . substring_view ( next_index ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // b. Append a new Record { [[Type]]: "literal", [[Value]]: literal } as the last element of the list result.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        result . append ( {  " literal " sv ,  literal  } ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // 8. Return result.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return  result ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 22:58:45 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}