summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Runtime
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2022-01-25 11:43:07 -0500
committerLinus Groh <mail@linusgroh.de>2022-01-25 19:02:59 +0000
commit25e67f63a24d6d80c7a93ebfd162a889b50951ce (patch)
tree448c99ce6d03f3098a7d32c2bf6bca9f7631a6d5 /Userland/Libraries/LibJS/Runtime
parentbced4e93240afc93294f5a12b3ecd65d4e7789e4 (diff)
downloadserenity-25e67f63a24d6d80c7a93ebfd162a889b50951ce.zip
LibJS: Convert Intl.DisplayNames to use Unicode::Style
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime')
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/DisplayNames.cpp27
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/DisplayNames.h16
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/DisplayNamesPrototype.cpp12
3 files changed, 11 insertions, 44 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/DisplayNames.cpp b/Userland/Libraries/LibJS/Runtime/Intl/DisplayNames.cpp
index 1fafd3f488..f5c4831cfc 100644
--- a/Userland/Libraries/LibJS/Runtime/Intl/DisplayNames.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Intl/DisplayNames.cpp
@@ -7,7 +7,6 @@
#include <LibJS/Runtime/GlobalObject.h>
#include <LibJS/Runtime/Intl/AbstractOperations.h>
#include <LibJS/Runtime/Intl/DisplayNames.h>
-#include <LibUnicode/Locale.h>
namespace JS::Intl {
@@ -17,32 +16,6 @@ DisplayNames::DisplayNames(Object& prototype)
{
}
-void DisplayNames::set_style(StringView style)
-{
- if (style == "narrow"sv)
- m_style = Style::Narrow;
- else if (style == "short"sv)
- m_style = Style::Short;
- else if (style == "long"sv)
- m_style = Style::Long;
- else
- VERIFY_NOT_REACHED();
-}
-
-StringView DisplayNames::style_string() const
-{
- switch (m_style) {
- case Style::Narrow:
- return "narrow"sv;
- case Style::Short:
- return "short"sv;
- case Style::Long:
- return "long"sv;
- default:
- VERIFY_NOT_REACHED();
- }
-}
-
void DisplayNames::set_type(StringView type)
{
if (type == "language"sv)
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/DisplayNames.h b/Userland/Libraries/LibJS/Runtime/Intl/DisplayNames.h
index db59a242ce..a90d0c3ac7 100644
--- a/Userland/Libraries/LibJS/Runtime/Intl/DisplayNames.h
+++ b/Userland/Libraries/LibJS/Runtime/Intl/DisplayNames.h
@@ -10,19 +10,13 @@
#include <AK/String.h>
#include <AK/StringView.h>
#include <LibJS/Runtime/Object.h>
+#include <LibUnicode/Locale.h>
namespace JS::Intl {
class DisplayNames final : public Object {
JS_OBJECT(DisplayNames, Object);
- enum class Style {
- Invalid,
- Narrow,
- Short,
- Long,
- };
-
enum class Type {
Invalid,
Language,
@@ -51,9 +45,9 @@ public:
String const& locale() const { return m_locale; }
void set_locale(String locale) { m_locale = move(locale); }
- Style style() const { return m_style; }
- void set_style(StringView style);
- StringView style_string() const;
+ 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); }
Type type() const { return m_type; }
void set_type(StringView type);
@@ -70,7 +64,7 @@ public:
private:
String m_locale; // [[Locale]]
- Style m_style { Style::Invalid }; // [[Style]]
+ Unicode::Style m_style { Unicode::Style::Long }; // [[Style]]
Type m_type { Type::Invalid }; // [[Type]]
Fallback m_fallback { Fallback::Invalid }; // [[Fallback]]
Optional<LanguageDisplay> m_language_display {}; // [[LanguageDisplay]]
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/DisplayNamesPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Intl/DisplayNamesPrototype.cpp
index f10fcc8771..5f8865ad06 100644
--- a/Userland/Libraries/LibJS/Runtime/Intl/DisplayNamesPrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Intl/DisplayNamesPrototype.cpp
@@ -73,13 +73,13 @@ JS_DEFINE_NATIVE_FUNCTION(DisplayNamesPrototype::of)
break;
case DisplayNames::Type::Currency:
switch (display_names->style()) {
- case DisplayNames::Style::Long:
+ case Unicode::Style::Long:
result = Unicode::get_locale_long_currency_mapping(display_names->locale(), code.as_string().string());
break;
- case DisplayNames::Style::Short:
+ case Unicode::Style::Short:
result = Unicode::get_locale_short_currency_mapping(display_names->locale(), code.as_string().string());
break;
- case DisplayNames::Style::Narrow:
+ case Unicode::Style::Narrow:
result = Unicode::get_locale_narrow_currency_mapping(display_names->locale(), code.as_string().string());
break;
default:
@@ -91,13 +91,13 @@ JS_DEFINE_NATIVE_FUNCTION(DisplayNamesPrototype::of)
break;
case DisplayNames::Type::DateTimeField:
switch (display_names->style()) {
- case DisplayNames::Style::Long:
+ case Unicode::Style::Long:
result = Unicode::get_locale_long_date_field_mapping(display_names->locale(), code.as_string().string());
break;
- case DisplayNames::Style::Short:
+ case Unicode::Style::Short:
result = Unicode::get_locale_short_date_field_mapping(display_names->locale(), code.as_string().string());
break;
- case DisplayNames::Style::Narrow:
+ case Unicode::Style::Narrow:
result = Unicode::get_locale_narrow_date_field_mapping(display_names->locale(), code.as_string().string());
break;
default: