
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 :^)
60 lines
1.9 KiB
C++
60 lines
1.9 KiB
C++
/*
|
|
* Copyright (c) 2021, Tim Flynn <trflynn89@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/DeprecatedString.h>
|
|
#include <AK/HashMap.h>
|
|
#include <AK/StringView.h>
|
|
#include <AK/Variant.h>
|
|
#include <AK/Vector.h>
|
|
#include <LibJS/Runtime/Intl/AbstractOperations.h>
|
|
#include <LibJS/Runtime/Object.h>
|
|
#include <LibLocale/Locale.h>
|
|
|
|
namespace JS::Intl {
|
|
|
|
class ListFormat final : public Object {
|
|
JS_OBJECT(ListFormat, Object);
|
|
|
|
public:
|
|
enum class Type {
|
|
Invalid,
|
|
Conjunction,
|
|
Disjunction,
|
|
Unit,
|
|
};
|
|
|
|
virtual ~ListFormat() override = default;
|
|
|
|
DeprecatedString const& locale() const { return m_locale; }
|
|
void set_locale(DeprecatedString locale) { m_locale = move(locale); }
|
|
|
|
Type type() const { return m_type; }
|
|
void set_type(StringView type);
|
|
StringView type_string() const;
|
|
|
|
::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); }
|
|
|
|
private:
|
|
explicit ListFormat(Object& prototype);
|
|
|
|
DeprecatedString m_locale; // [[Locale]]
|
|
Type m_type { Type::Invalid }; // [[Type]]
|
|
::Locale::Style m_style { ::Locale::Style::Long }; // [[Style]]
|
|
};
|
|
|
|
using Placeables = HashMap<StringView, Variant<PatternPartition, Vector<PatternPartition>>>;
|
|
|
|
Vector<PatternPartition> deconstruct_pattern(StringView pattern, Placeables);
|
|
Vector<PatternPartition> create_parts_from_list(ListFormat const&, Vector<DeprecatedString> const& list);
|
|
DeprecatedString format_list(ListFormat const&, Vector<DeprecatedString> const& list);
|
|
Array* format_list_to_parts(VM&, ListFormat const&, Vector<DeprecatedString> const& list);
|
|
ThrowCompletionOr<Vector<DeprecatedString>> string_list_from_iterable(VM&, Value iterable);
|
|
|
|
}
|