1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 13:57:35 +00:00

LibJS: Port Intl locale resolution to String

This commit is contained in:
Timothy Flynn 2023-01-19 13:13:57 -05:00 committed by Linus Groh
parent 2f1184ccdb
commit bb4b6d8ce3
20 changed files with 208 additions and 205 deletions

View file

@ -7,8 +7,8 @@
#pragma once
#include <AK/Array.h>
#include <AK/DeprecatedString.h>
#include <AK/Optional.h>
#include <AK/String.h>
#include <AK/Vector.h>
#include <LibJS/Runtime/Completion.h>
#include <LibJS/Runtime/Object.h>
@ -21,7 +21,7 @@ class Locale final : public Object {
JS_OBJECT(Locale, Object);
public:
static NonnullGCPtr<Locale> create(Realm&, ::Locale::LocaleID const&);
static ThrowCompletionOr<NonnullGCPtr<Locale>> create(Realm&, ::Locale::LocaleID);
static constexpr auto relevant_extension_keys()
{
@ -36,43 +36,42 @@ public:
virtual ~Locale() override = default;
DeprecatedString const& locale() const { return m_locale; }
void set_locale(DeprecatedString locale) { m_locale = move(locale); }
String const& locale() const { return m_locale; }
void set_locale(String locale) { m_locale = move(locale); }
bool has_calendar() const { return m_calendar.has_value(); }
DeprecatedString const& calendar() const { return m_calendar.value(); }
void set_calendar(DeprecatedString calendar) { m_calendar = move(calendar); }
String const& calendar() const { return m_calendar.value(); }
void set_calendar(String calendar) { m_calendar = move(calendar); }
bool has_case_first() const { return m_case_first.has_value(); }
DeprecatedString const& case_first() const { return m_case_first.value(); }
void set_case_first(DeprecatedString case_first) { m_case_first = move(case_first); }
String const& case_first() const { return m_case_first.value(); }
void set_case_first(String case_first) { m_case_first = move(case_first); }
bool has_collation() const { return m_collation.has_value(); }
DeprecatedString const& collation() const { return m_collation.value(); }
void set_collation(DeprecatedString collation) { m_collation = move(collation); }
String const& collation() const { return m_collation.value(); }
void set_collation(String collation) { m_collation = move(collation); }
bool has_hour_cycle() const { return m_hour_cycle.has_value(); }
DeprecatedString const& hour_cycle() const { return m_hour_cycle.value(); }
void set_hour_cycle(DeprecatedString hour_cycle) { m_hour_cycle = move(hour_cycle); }
String const& hour_cycle() const { return m_hour_cycle.value(); }
void set_hour_cycle(String hour_cycle) { m_hour_cycle = move(hour_cycle); }
bool has_numbering_system() const { return m_numbering_system.has_value(); }
DeprecatedString const& numbering_system() const { return m_numbering_system.value(); }
void set_numbering_system(DeprecatedString numbering_system) { m_numbering_system = move(numbering_system); }
String const& numbering_system() const { return m_numbering_system.value(); }
void set_numbering_system(String numbering_system) { m_numbering_system = move(numbering_system); }
bool numeric() const { return m_numeric; }
void set_numeric(bool numeric) { m_numeric = numeric; }
private:
explicit Locale(Object& prototype);
Locale(::Locale::LocaleID const&, Object& prototype);
DeprecatedString m_locale; // [[Locale]]
Optional<DeprecatedString> m_calendar; // [[Calendar]]
Optional<DeprecatedString> m_case_first; // [[CaseFirst]]
Optional<DeprecatedString> m_collation; // [[Collation]]
Optional<DeprecatedString> m_hour_cycle; // [[HourCycle]]
Optional<DeprecatedString> m_numbering_system; // [[NumberingSystem]]
bool m_numeric { false }; // [[Numeric]]
String m_locale; // [[Locale]]
Optional<String> m_calendar; // [[Calendar]]
Optional<String> m_case_first; // [[CaseFirst]]
Optional<String> m_collation; // [[Collation]]
Optional<String> m_hour_cycle; // [[HourCycle]]
Optional<String> m_numbering_system; // [[NumberingSystem]]
bool m_numeric { false }; // [[Numeric]]
};
// Table 1: WeekInfo Record Fields, https://tc39.es/proposal-intl-locale-info/#table-locale-weekinfo-record