2021-09-02 08:32:43 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								/*
  
						 
					
						
							
								
									
										
										
										
											2022-07-05 12:10:24 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								 *  Copyright  ( c )  2021 - 2022 ,  Tim  Flynn  < trflynn89 @ serenityos . org > 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-02 08:32:43 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  SPDX - License - Identifier :  BSD - 2 - Clause 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-07-05 12:10:24 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# include  <LibJS/Runtime/Array.h> 
  
						 
					
						
							
								
									
										
										
										
											2021-09-02 08:32:43 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								# include  <LibJS/Runtime/GlobalObject.h> 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# include  <LibJS/Runtime/Intl/Locale.h> 
  
						 
					
						
							
								
									
										
										
										
											2021-09-02 18:23:39 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# include  <LibUnicode/Locale.h> 
  
						 
					
						
							
								
									
										
										
										
											2021-09-02 08:32:43 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								namespace  JS : : Intl  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-09-02 18:23:39 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Locale *  Locale : : create ( GlobalObject &  global_object ,  Unicode : : LocaleID  const &  locale_id )  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return  global_object . heap ( ) . allocate < Locale > ( global_object ,  locale_id ,  * global_object . intl_locale_prototype ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-09-02 08:32:43 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								// 14 Locale Objects, https://tc39.es/ecma402/#locale-objects
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Locale : : Locale ( Object &  prototype )  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    :  Object ( prototype ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-09-02 18:23:39 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Locale : : Locale ( Unicode : : LocaleID  const &  locale_id ,  Object &  prototype )  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    :  Object ( prototype ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    set_locale ( locale_id . to_string ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    for  ( auto  const &  extension  :  locale_id . extensions )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( ! extension . has < Unicode : : LocaleExtension > ( ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            continue ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        for  ( auto  const &  keyword  :  extension . get < Unicode : : LocaleExtension > ( ) . keywords )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  ( keyword . key  = =  " ca " sv )  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-08 15:25:35 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                set_calendar ( keyword . value ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-02 18:23:39 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            }  else  if  ( keyword . key  = =  " co " sv )  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-08 15:25:35 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                set_collation ( keyword . value ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-02 18:23:39 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            }  else  if  ( keyword . key  = =  " hc " sv )  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-08 15:25:35 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                set_hour_cycle ( keyword . value ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-02 18:23:39 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            }  else  if  ( keyword . key  = =  " kf " sv )  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-08 15:25:35 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                set_case_first ( keyword . value ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-02 18:23:39 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            }  else  if  ( keyword . key  = =  " kn " sv )  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-08 15:25:35 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                set_numeric ( keyword . value . is_empty ( ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-02 18:23:39 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            }  else  if  ( keyword . key  = =  " nu " sv )  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-08 15:25:35 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                set_numbering_system ( keyword . value ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-02 18:23:39 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-07-05 12:10:24 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// 1.1.1 CreateArrayFromListOrRestricted ( list , restricted )
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								static  Array *  create_array_from_list_or_restricted ( GlobalObject &  global_object ,  Vector < StringView >  list ,  Optional < String >  restricted )  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    auto &  vm  =  global_object . vm ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // 1. If restricted is not undefined, then
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( restricted . has_value ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // a. Set list to « restricted ».
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        list  =  {  * restricted  } ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // 2. Return ! CreateArrayFromList( list ).
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return  Array : : create_from < StringView > ( global_object ,  list ,  [ & vm ] ( auto  value )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return  js_string ( vm ,  value ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 1.1.2 CalendarsOfLocale ( loc ), https://tc39.es/proposal-intl-locale-info/#sec-calendars-of-locale
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Array *  calendars_of_locale ( GlobalObject &  global_object ,  Locale  const &  locale_object )  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // 1. Let restricted be loc.[[Calendar]].
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    Optional < String >  restricted  =  locale_object . has_calendar ( )  ?  locale_object . calendar ( )  :  Optional < String >  { } ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // 2. Let locale be loc.[[Locale]].
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    auto  const &  locale  =  locale_object . locale ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // 3. Assert: locale matches the unicode_locale_id production.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    VERIFY ( Unicode : : parse_unicode_locale_id ( locale ) . has_value ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // 4. Let list be a List of 1 or more unique canonical calendar identifiers, which must be lower case String values conforming to the type sequence from UTS 35 Unicode Locale Identifier, section 3.2, sorted in descending preference of those in common use for date and time formatting in locale.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    auto  list  =  Unicode : : get_keywords_for_locale ( locale ,  " ca " sv ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // 5. Return ! CreateArrayFromListOrRestricted( list, restricted ).
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return  create_array_from_list_or_restricted ( global_object ,  move ( list ) ,  move ( restricted ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-07-05 12:28:21 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// 1.1.3 CollationsOfLocale ( loc ), https://tc39.es/proposal-intl-locale-info/#sec-collations-of-locale
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Array *  collations_of_locale ( GlobalObject &  global_object ,  Locale  const &  locale_object )  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // 1. Let restricted be loc.[[Collation]].
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    Optional < String >  restricted  =  locale_object . has_collation ( )  ?  locale_object . collation ( )  :  Optional < String >  { } ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // 2. Let locale be loc.[[Locale]].
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    auto  const &  locale  =  locale_object . locale ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // 3. Assert: locale matches the unicode_locale_id production.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    VERIFY ( Unicode : : parse_unicode_locale_id ( locale ) . has_value ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // 4. Let list be a List of 1 or more unique canonical collation identifiers, which must be lower case String values conforming to the type sequence from UTS 35 Unicode Locale Identifier, section 3.2, sorted in descending preference of those in common use for string comparison in locale. The values "standard" and "search" must be excluded from list.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // FIXME: Retrieve this data from the CLDR when we fully support collation. This matches Intl.supportedValuesOf.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    Vector < StringView >  list  {  " default " sv  } ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // 5. Return ! CreateArrayFromListOrRestricted( list, restricted ).
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return  create_array_from_list_or_restricted ( global_object ,  move ( list ) ,  move ( restricted ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-07-05 13:41:08 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// 1.1.4 HourCyclesOfLocale ( loc ), https://tc39.es/proposal-intl-locale-info/#sec-hour-cycles-of-locale
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Array *  hour_cycles_of_locale ( GlobalObject &  global_object ,  Locale  const &  locale_object )  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // 1. Let restricted be loc.[[HourCycle]].
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    Optional < String >  restricted  =  locale_object . has_hour_cycle ( )  ?  locale_object . hour_cycle ( )  :  Optional < String >  { } ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // 2. Let locale be loc.[[Locale]].
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    auto  const &  locale  =  locale_object . locale ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // 3. Assert: locale matches the unicode_locale_id production.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    VERIFY ( Unicode : : parse_unicode_locale_id ( locale ) . has_value ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // 4. Let list be a List of 1 or more unique hour cycle identifiers, which must be lower case String values indicating either the 12-hour format ("h11", "h12") or the 24-hour format ("h23", "h24"), sorted in descending preference of those in common use for date and time formatting in locale.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    auto  list  =  Unicode : : get_keywords_for_locale ( locale ,  " hc " sv ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // 5. Return ! CreateArrayFromListOrRestricted( list, restricted ).
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return  create_array_from_list_or_restricted ( global_object ,  move ( list ) ,  move ( restricted ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-07-05 14:19:23 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// 1.1.5 NumberingSystemsOfLocale ( loc ), https://tc39.es/proposal-intl-locale-info/#sec-numbering-systems-of-locale
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Array *  numbering_systems_of_locale ( GlobalObject &  global_object ,  Locale  const &  locale_object )  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // 1. Let restricted be loc.[[NumberingSystem]].
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    Optional < String >  restricted  =  locale_object . has_numbering_system ( )  ?  locale_object . numbering_system ( )  :  Optional < String >  { } ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // 2. Let locale be loc.[[Locale]].
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    auto  const &  locale  =  locale_object . locale ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // 3. Assert: locale matches the unicode_locale_id production.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    VERIFY ( Unicode : : parse_unicode_locale_id ( locale ) . has_value ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // 4. Let list be a List of 1 or more unique canonical numbering system identifiers, which must be lower case String values conforming to the type sequence from UTS 35 Unicode Locale Identifier, section 3.2, sorted in descending preference of those in common use for formatting numeric values in locale.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    auto  list  =  Unicode : : get_keywords_for_locale ( locale ,  " nu " sv ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // 5. Return ! CreateArrayFromListOrRestricted( list, restricted ).
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return  create_array_from_list_or_restricted ( global_object ,  move ( list ) ,  move ( restricted ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-09-02 08:32:43 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}