1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-17 13:05:07 +00:00
serenity/Userland/Libraries/LibJS/Runtime/Intl/DisplayNames.h
Linus Groh 6e19ab2bbc AK+Everywhere: Rename String to DeprecatedString
We have a new, improved string type coming up in AK (OOM aware, no null
state), and while it's going to use UTF-8, the name UTF8String is a
mouthful - so let's free up the String name by renaming the existing
class.
Making the old one have an annoying name will hopefully also help with
quick adoption :^)
2022-12-06 08:54:33 +01:00

77 lines
2.1 KiB
C++

/*
* Copyright (c) 2021-2022, Tim Flynn <trflynn89@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/DeprecatedString.h>
#include <AK/Optional.h>
#include <AK/StringView.h>
#include <LibJS/Runtime/Object.h>
#include <LibLocale/Locale.h>
namespace JS::Intl {
class DisplayNames final : public Object {
JS_OBJECT(DisplayNames, Object);
enum class Type {
Invalid,
Language,
Region,
Script,
Currency,
Calendar,
DateTimeField,
};
enum class Fallback {
Invalid,
None,
Code,
};
enum class LanguageDisplay {
Dialect,
Standard,
};
public:
virtual ~DisplayNames() override = default;
DeprecatedString const& locale() const { return m_locale; }
void set_locale(DeprecatedString locale) { m_locale = move(locale); }
::Locale::Style style() const { return m_style; }
void set_style(StringView style) { m_style = ::Locale::style_from_string(style); }
StringView style_string() const { return ::Locale::style_to_string(m_style); }
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;
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;
private:
DisplayNames(Object& prototype);
DeprecatedString m_locale; // [[Locale]]
::Locale::Style m_style { ::Locale::Style::Long }; // [[Style]]
Type m_type { Type::Invalid }; // [[Type]]
Fallback m_fallback { Fallback::Invalid }; // [[Fallback]]
Optional<LanguageDisplay> m_language_display {}; // [[LanguageDisplay]]
};
ThrowCompletionOr<Value> canonical_code_for_display_names(VM&, DisplayNames::Type, StringView code);
bool is_valid_date_time_field_code(StringView field);
}