| 
									
										
										
										
											2021-08-24 22:27:05 -04:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2022-01-12 13:52:51 -05:00
										 |  |  |  * Copyright (c) 2021-2022, Tim Flynn <trflynn89@pm.me> | 
					
						
							| 
									
										
										
										
											2021-08-24 22:27:05 -04:00
										 |  |  |  * | 
					
						
							|  |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-12 13:52:51 -05:00
										 |  |  | #include <AK/Optional.h>
 | 
					
						
							| 
									
										
										
										
											2021-08-24 22:27:05 -04:00
										 |  |  | #include <AK/String.h>
 | 
					
						
							|  |  |  | #include <AK/StringView.h>
 | 
					
						
							|  |  |  | #include <LibJS/Runtime/Object.h>
 | 
					
						
							| 
									
										
										
										
											2022-01-25 11:43:07 -05:00
										 |  |  | #include <LibUnicode/Locale.h>
 | 
					
						
							| 
									
										
										
										
											2021-08-24 22:27:05 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace JS::Intl { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class DisplayNames final : public Object { | 
					
						
							|  |  |  |     JS_OBJECT(DisplayNames, Object); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     enum class Type { | 
					
						
							|  |  |  |         Invalid, | 
					
						
							|  |  |  |         Language, | 
					
						
							|  |  |  |         Region, | 
					
						
							|  |  |  |         Script, | 
					
						
							|  |  |  |         Currency, | 
					
						
							| 
									
										
										
										
											2022-01-12 13:52:51 -05:00
										 |  |  |         Calendar, | 
					
						
							|  |  |  |         DateTimeField, | 
					
						
							| 
									
										
										
										
											2021-08-24 22:27:05 -04:00
										 |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     enum class Fallback { | 
					
						
							|  |  |  |         Invalid, | 
					
						
							|  |  |  |         None, | 
					
						
							|  |  |  |         Code, | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-12 13:52:51 -05:00
										 |  |  |     enum class LanguageDisplay { | 
					
						
							|  |  |  |         Dialect, | 
					
						
							|  |  |  |         Standard, | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-24 22:27:05 -04:00
										 |  |  | public: | 
					
						
							|  |  |  |     DisplayNames(Object& prototype); | 
					
						
							|  |  |  |     virtual ~DisplayNames() override = default; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     String const& locale() const { return m_locale; } | 
					
						
							|  |  |  |     void set_locale(String locale) { m_locale = move(locale); } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-25 11:43:07 -05:00
										 |  |  |     Unicode::Style style() const { return m_style; } | 
					
						
							|  |  |  |     void set_style(StringView style) { m_style = Unicode::style_from_string(style); } | 
					
						
							|  |  |  |     StringView style_string() const { return Unicode::style_to_string(m_style); } | 
					
						
							| 
									
										
										
										
											2021-08-24 22:27:05 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     Type type() const { return m_type; } | 
					
						
							|  |  |  |     void set_type(StringView type); | 
					
						
							|  |  |  |     StringView type_string() const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     Fallback fallback() const { return m_fallback; } | 
					
						
							|  |  |  |     void set_fallback(StringView fallback); | 
					
						
							|  |  |  |     StringView fallback_string() const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-12 13:52:51 -05:00
										 |  |  |     bool has_language_display() const { return m_language_display.has_value(); } | 
					
						
							|  |  |  |     LanguageDisplay language_display() const { return *m_language_display; } | 
					
						
							|  |  |  |     void set_language_display(StringView language_display); | 
					
						
							|  |  |  |     StringView language_display_string() const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-24 22:27:05 -04:00
										 |  |  | private: | 
					
						
							| 
									
										
										
										
											2022-01-12 13:52:51 -05:00
										 |  |  |     String m_locale;                                 // [[Locale]]
 | 
					
						
							| 
									
										
										
										
											2022-01-25 11:43:07 -05:00
										 |  |  |     Unicode::Style m_style { Unicode::Style::Long }; // [[Style]]
 | 
					
						
							| 
									
										
										
										
											2022-01-12 13:52:51 -05:00
										 |  |  |     Type m_type { Type::Invalid };                   // [[Type]]
 | 
					
						
							|  |  |  |     Fallback m_fallback { Fallback::Invalid };       // [[Fallback]]
 | 
					
						
							|  |  |  |     Optional<LanguageDisplay> m_language_display {}; // [[LanguageDisplay]]
 | 
					
						
							| 
									
										
										
										
											2021-08-24 22:27:05 -04:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-18 19:41:25 +03:00
										 |  |  | ThrowCompletionOr<Value> canonical_code_for_display_names(GlobalObject& global_object, DisplayNames::Type type, StringView code); | 
					
						
							| 
									
										
										
										
											2022-01-12 17:55:45 -05:00
										 |  |  | bool is_valid_date_time_field_code(StringView field); | 
					
						
							| 
									
										
										
										
											2021-09-11 07:50:54 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-24 22:27:05 -04:00
										 |  |  | } |