mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 11:58:12 +00:00
LibJS: Implement a nearly empty Intl.ListFormat object
This adds plumbing for the Intl.ListFormat object, constructor, and prototype.
This commit is contained in:
parent
4ad2159812
commit
8e75e5fabb
12 changed files with 279 additions and 0 deletions
71
Userland/Libraries/LibJS/Runtime/Intl/ListFormat.cpp
Normal file
71
Userland/Libraries/LibJS/Runtime/Intl/ListFormat.cpp
Normal file
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* Copyright (c) 2021, Tim Flynn <trflynn89@pm.me>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibJS/Runtime/Intl/ListFormat.h>
|
||||
|
||||
namespace JS::Intl {
|
||||
|
||||
// 13 ListFomat Objects, https://tc39.es/ecma402/#listformat-objects
|
||||
ListFormat::ListFormat(Object& prototype)
|
||||
: Object(prototype)
|
||||
{
|
||||
}
|
||||
|
||||
void ListFormat::set_type(StringView type)
|
||||
{
|
||||
if (type == "conjunction"sv) {
|
||||
m_type = Type::Conjunction;
|
||||
} else if (type == "disjunction"sv) {
|
||||
m_type = Type::Disjunction;
|
||||
} else if (type == "unit"sv) {
|
||||
m_type = Type::Unit;
|
||||
} else {
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
}
|
||||
|
||||
StringView ListFormat::type_string() const
|
||||
{
|
||||
switch (m_type) {
|
||||
case Type::Conjunction:
|
||||
return "conjunction"sv;
|
||||
case Type::Disjunction:
|
||||
return "disjunction"sv;
|
||||
case Type::Unit:
|
||||
return "unit"sv;
|
||||
default:
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
}
|
||||
|
||||
void ListFormat::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 ListFormat::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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue