mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 22:47:44 +00:00
LibJS: Port ListFormat and PatternPartition to String
This commit is contained in:
parent
20536897e4
commit
1bcde5d216
10 changed files with 53 additions and 54 deletions
|
@ -705,7 +705,7 @@ ThrowCompletionOr<Vector<PatternPartition>> partition_pattern(VM& vm, StringView
|
|||
auto literal = pattern.substring_view(next_index, *begin_index - next_index);
|
||||
|
||||
// ii. Append a new Record { [[Type]]: "literal", [[Value]]: literal } as the last element of the list result.
|
||||
TRY_OR_THROW_OOM(vm, result.try_append({ "literal"sv, literal }));
|
||||
TRY_OR_THROW_OOM(vm, result.try_append({ "literal"sv, TRY_OR_THROW_OOM(vm, String::from_utf8(literal)) }));
|
||||
}
|
||||
|
||||
// d. Let p be the substring of pattern from position beginIndex, exclusive, to position endIndex, exclusive.
|
||||
|
@ -727,7 +727,7 @@ ThrowCompletionOr<Vector<PatternPartition>> partition_pattern(VM& vm, StringView
|
|||
auto literal = pattern.substring_view(next_index);
|
||||
|
||||
// b. Append a new Record { [[Type]]: "literal", [[Value]]: literal } as the last element of the list result.
|
||||
TRY_OR_THROW_OOM(vm, result.try_append({ "literal"sv, literal }));
|
||||
TRY_OR_THROW_OOM(vm, result.try_append({ "literal"sv, TRY_OR_THROW_OOM(vm, String::from_utf8(literal)) }));
|
||||
}
|
||||
|
||||
// 8. Return result.
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/DeprecatedString.h>
|
||||
#include <AK/Span.h>
|
||||
#include <AK/String.h>
|
||||
#include <AK/Variant.h>
|
||||
|
@ -44,14 +43,14 @@ struct LocaleResult {
|
|||
struct PatternPartition {
|
||||
PatternPartition() = default;
|
||||
|
||||
PatternPartition(StringView type_string, DeprecatedString value_string)
|
||||
PatternPartition(StringView type_string, String value_string)
|
||||
: type(type_string)
|
||||
, value(move(value_string))
|
||||
{
|
||||
}
|
||||
|
||||
StringView type;
|
||||
DeprecatedString value;
|
||||
String value;
|
||||
};
|
||||
|
||||
struct PatternPartitionWithSource : public PatternPartition {
|
||||
|
|
|
@ -624,7 +624,7 @@ ThrowCompletionOr<Vector<PatternPartition>> format_date_time_pattern(VM& vm, Dat
|
|||
auto formatted_value = MUST_OR_THROW_OOM(format_numeric(vm, *number_format3, Value(value)));
|
||||
|
||||
// iv. Append a new Record { [[Type]]: "fractionalSecond", [[Value]]: fv } as the last element of result.
|
||||
result.append({ "fractionalSecond"sv, move(formatted_value) });
|
||||
result.append({ "fractionalSecond"sv, TRY_OR_THROW_OOM(vm, String::from_deprecated_string(formatted_value)) });
|
||||
}
|
||||
|
||||
// d. Else if p is equal to "dayPeriod", then
|
||||
|
@ -640,7 +640,7 @@ ThrowCompletionOr<Vector<PatternPartition>> format_date_time_pattern(VM& vm, Dat
|
|||
formatted_value = *symbol;
|
||||
|
||||
// iii. Append a new Record { [[Type]]: p, [[Value]]: fv } as the last element of the list result.
|
||||
result.append({ "dayPeriod"sv, move(formatted_value) });
|
||||
result.append({ "dayPeriod"sv, TRY_OR_THROW_OOM(vm, String::from_deprecated_string(formatted_value)) });
|
||||
}
|
||||
|
||||
// e. Else if p is equal to "timeZoneName", then
|
||||
|
@ -657,7 +657,7 @@ ThrowCompletionOr<Vector<PatternPartition>> format_date_time_pattern(VM& vm, Dat
|
|||
auto formatted_value = ::Locale::format_time_zone(data_locale, value, style, local_time.time_since_epoch());
|
||||
|
||||
// iv. Append a new Record { [[Type]]: p, [[Value]]: fv } as the last element of the list result.
|
||||
result.append({ "timeZoneName"sv, move(formatted_value) });
|
||||
result.append({ "timeZoneName"sv, TRY_OR_THROW_OOM(vm, String::from_deprecated_string(formatted_value)) });
|
||||
}
|
||||
|
||||
// f. Else if p matches a Property column of the row in Table 6, then
|
||||
|
@ -750,7 +750,7 @@ ThrowCompletionOr<Vector<PatternPartition>> format_date_time_pattern(VM& vm, Dat
|
|||
}
|
||||
|
||||
// xi. Append a new Record { [[Type]]: p, [[Value]]: fv } as the last element of the list result.
|
||||
result.append({ style_and_value->name, move(formatted_value) });
|
||||
result.append({ style_and_value->name, TRY_OR_THROW_OOM(vm, String::from_deprecated_string(formatted_value)) });
|
||||
}
|
||||
|
||||
// g. Else if p is equal to "ampm", then
|
||||
|
@ -774,7 +774,7 @@ ThrowCompletionOr<Vector<PatternPartition>> format_date_time_pattern(VM& vm, Dat
|
|||
}
|
||||
|
||||
// iv. Append a new Record { [[Type]]: "dayPeriod", [[Value]]: fv } as the last element of the list result.
|
||||
result.append({ "dayPeriod"sv, move(formatted_value) });
|
||||
result.append({ "dayPeriod"sv, TRY_OR_THROW_OOM(vm, String::from_deprecated_string(formatted_value)) });
|
||||
}
|
||||
|
||||
// h. Else if p is equal to "relatedYear", then
|
||||
|
@ -799,7 +799,7 @@ ThrowCompletionOr<Vector<PatternPartition>> format_date_time_pattern(VM& vm, Dat
|
|||
// to adhere to the selected locale. This depends on other generated data, so it is deferred to here.
|
||||
else if (part == "decimal"sv) {
|
||||
auto decimal_symbol = ::Locale::get_number_system_symbol(data_locale, date_time_format.numbering_system(), ::Locale::NumericSymbol::Decimal).value_or("."sv);
|
||||
result.append({ "literal"sv, decimal_symbol });
|
||||
result.append({ "literal"sv, TRY_OR_THROW_OOM(vm, String::from_utf8(decimal_symbol)) });
|
||||
}
|
||||
|
||||
// j. Else,
|
||||
|
|
|
@ -448,7 +448,7 @@ ThrowCompletionOr<Vector<PatternPartition>> partition_duration_format_pattern(VM
|
|||
auto number = MUST_OR_THROW_OOM(format_numeric(vm, *number_format, MathematicalValue(value)));
|
||||
|
||||
// 5. Append the new Record { [[Type]]: unit, [[Value]]: num} to the end of result.
|
||||
result.append({ unit, number });
|
||||
result.append({ unit, TRY_OR_THROW_OOM(vm, String::from_deprecated_string(number)) });
|
||||
|
||||
// 6. If unit is "hours" or "minutes", then
|
||||
if (unit.is_one_of("hours"sv, "minutes"sv)) {
|
||||
|
@ -484,7 +484,7 @@ ThrowCompletionOr<Vector<PatternPartition>> partition_duration_format_pattern(VM
|
|||
auto separator = ::Locale::get_number_system_symbol(data_locale, duration_format.numbering_system(), ::Locale::NumericSymbol::TimeSeparator).value_or(":"sv);
|
||||
|
||||
// ii. Append the new Record { [[Type]]: "literal", [[Value]]: separator} to the end of result.
|
||||
result.append({ "literal"sv, separator });
|
||||
result.append({ "literal"sv, TRY_OR_THROW_OOM(vm, String::from_utf8(separator)) });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -516,7 +516,7 @@ ThrowCompletionOr<Vector<PatternPartition>> partition_duration_format_pattern(VM
|
|||
}
|
||||
|
||||
// 8. Append the new Record { [[Type]]: unit, [[Value]]: concat } to the end of result.
|
||||
result.append({ unit, concat.build() });
|
||||
result.append({ unit, TRY_OR_THROW_OOM(vm, concat.to_string()) });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -546,17 +546,17 @@ ThrowCompletionOr<Vector<PatternPartition>> partition_duration_format_pattern(VM
|
|||
|
||||
// FIXME: CreatePartsFromList expects a list of strings and creates a list of Pattern Partition records, but we already created a list of Pattern Partition records
|
||||
// so we try to hack something together from it that looks mostly right
|
||||
Vector<DeprecatedString> string_result;
|
||||
Vector<String> string_result;
|
||||
bool merge = false;
|
||||
for (size_t i = 0; i < result.size(); ++i) {
|
||||
auto const& part = result[i];
|
||||
if (part.type == "literal") {
|
||||
string_result.last() = DeprecatedString::formatted("{}{}", string_result.last(), part.value);
|
||||
string_result.last() = TRY_OR_THROW_OOM(vm, String::formatted("{}{}", string_result.last(), part.value));
|
||||
merge = true;
|
||||
continue;
|
||||
}
|
||||
if (merge) {
|
||||
string_result.last() = DeprecatedString::formatted("{}{}", string_result.last(), part.value);
|
||||
string_result.last() = TRY_OR_THROW_OOM(vm, String::formatted("{}{}", string_result.last(), part.value));
|
||||
merge = false;
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -93,7 +93,7 @@ ThrowCompletionOr<Vector<PatternPartition>> deconstruct_pattern(VM& vm, StringVi
|
|||
}
|
||||
|
||||
// 13.5.2 CreatePartsFromList ( listFormat, list ), https://tc39.es/ecma402/#sec-createpartsfromlist
|
||||
ThrowCompletionOr<Vector<PatternPartition>> create_parts_from_list(VM& vm, ListFormat const& list_format, Vector<DeprecatedString> const& list)
|
||||
ThrowCompletionOr<Vector<PatternPartition>> create_parts_from_list(VM& vm, ListFormat const& list_format, Vector<String> const& list)
|
||||
{
|
||||
auto list_patterns = ::Locale::get_locale_list_patterns(list_format.locale(), list_format.type_string(), list_format.style());
|
||||
if (!list_patterns.has_value())
|
||||
|
@ -182,7 +182,7 @@ ThrowCompletionOr<Vector<PatternPartition>> create_parts_from_list(VM& vm, ListF
|
|||
}
|
||||
|
||||
// 13.5.3 FormatList ( listFormat, list ), https://tc39.es/ecma402/#sec-formatlist
|
||||
ThrowCompletionOr<DeprecatedString> format_list(VM& vm, ListFormat const& list_format, Vector<DeprecatedString> const& list)
|
||||
ThrowCompletionOr<String> format_list(VM& vm, ListFormat const& list_format, Vector<String> const& list)
|
||||
{
|
||||
// 1. Let parts be ! CreatePartsFromList(listFormat, list).
|
||||
auto parts = MUST_OR_THROW_OOM(create_parts_from_list(vm, list_format, list));
|
||||
|
@ -193,15 +193,15 @@ ThrowCompletionOr<DeprecatedString> format_list(VM& vm, ListFormat const& list_f
|
|||
// 3. For each Record { [[Type]], [[Value]] } part in parts, do
|
||||
for (auto& part : parts) {
|
||||
// a. Set result to the string-concatenation of result and part.[[Value]].
|
||||
result.append(move(part.value));
|
||||
result.append(part.value);
|
||||
}
|
||||
|
||||
// 4. Return result.
|
||||
return result.build();
|
||||
return TRY_OR_THROW_OOM(vm, result.to_string());
|
||||
}
|
||||
|
||||
// 13.5.4 FormatListToParts ( listFormat, list ), https://tc39.es/ecma402/#sec-formatlisttoparts
|
||||
ThrowCompletionOr<Array*> format_list_to_parts(VM& vm, ListFormat const& list_format, Vector<DeprecatedString> const& list)
|
||||
ThrowCompletionOr<Array*> format_list_to_parts(VM& vm, ListFormat const& list_format, Vector<String> const& list)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
|
||||
|
@ -237,19 +237,19 @@ ThrowCompletionOr<Array*> format_list_to_parts(VM& vm, ListFormat const& list_fo
|
|||
}
|
||||
|
||||
// 13.5.5 StringListFromIterable ( iterable ), https://tc39.es/ecma402/#sec-createstringlistfromiterable
|
||||
ThrowCompletionOr<Vector<DeprecatedString>> string_list_from_iterable(VM& vm, Value iterable)
|
||||
ThrowCompletionOr<Vector<String>> string_list_from_iterable(VM& vm, Value iterable)
|
||||
{
|
||||
// 1. If iterable is undefined, then
|
||||
if (iterable.is_undefined()) {
|
||||
// a. Return a new empty List.
|
||||
return Vector<DeprecatedString> {};
|
||||
return Vector<String> {};
|
||||
}
|
||||
|
||||
// 2. Let iteratorRecord be ? GetIterator(iterable).
|
||||
auto iterator_record = TRY(get_iterator(vm, iterable));
|
||||
|
||||
// 3. Let list be a new empty List.
|
||||
Vector<DeprecatedString> list;
|
||||
Vector<String> list;
|
||||
|
||||
// 4. Let next be true.
|
||||
Object* next = nullptr;
|
||||
|
@ -274,7 +274,7 @@ ThrowCompletionOr<Vector<DeprecatedString>> string_list_from_iterable(VM& vm, Va
|
|||
}
|
||||
|
||||
// iii. Append nextValue to the end of the List list.
|
||||
list.append(TRY(next_value.as_string().deprecated_string()));
|
||||
list.append(TRY(next_value.as_string().utf8_string()));
|
||||
}
|
||||
} while (next != nullptr);
|
||||
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/DeprecatedString.h>
|
||||
#include <AK/HashMap.h>
|
||||
#include <AK/String.h>
|
||||
#include <AK/StringView.h>
|
||||
|
@ -53,9 +52,9 @@ private:
|
|||
using Placeables = HashMap<StringView, Variant<PatternPartition, Vector<PatternPartition>>>;
|
||||
|
||||
ThrowCompletionOr<Vector<PatternPartition>> deconstruct_pattern(VM&, StringView pattern, Placeables);
|
||||
ThrowCompletionOr<Vector<PatternPartition>> create_parts_from_list(VM&, ListFormat const&, Vector<DeprecatedString> const& list);
|
||||
ThrowCompletionOr<DeprecatedString> format_list(VM&, ListFormat const&, Vector<DeprecatedString> const& list);
|
||||
ThrowCompletionOr<Array*> format_list_to_parts(VM&, ListFormat const&, Vector<DeprecatedString> const& list);
|
||||
ThrowCompletionOr<Vector<DeprecatedString>> string_list_from_iterable(VM&, Value iterable);
|
||||
ThrowCompletionOr<Vector<PatternPartition>> create_parts_from_list(VM&, ListFormat const&, Vector<String> const& list);
|
||||
ThrowCompletionOr<String> format_list(VM&, ListFormat const&, Vector<String> const& list);
|
||||
ThrowCompletionOr<Array*> format_list_to_parts(VM&, ListFormat const&, Vector<String> const& list);
|
||||
ThrowCompletionOr<Vector<String>> string_list_from_iterable(VM&, Value iterable);
|
||||
|
||||
}
|
||||
|
|
|
@ -607,7 +607,7 @@ ThrowCompletionOr<Vector<PatternPartition>> partition_number_pattern(VM& vm, Num
|
|||
// i. Let plusSignSymbol be the ILND String representing the plus sign.
|
||||
auto plus_sign_symbol = ::Locale::get_number_system_symbol(number_format.data_locale(), number_format.numbering_system(), ::Locale::NumericSymbol::PlusSign).value_or("+"sv);
|
||||
// ii. Append a new Record { [[Type]]: "plusSign", [[Value]]: plusSignSymbol } as the last element of result.
|
||||
result.append({ "plusSign"sv, plus_sign_symbol });
|
||||
result.append({ "plusSign"sv, TRY_OR_THROW_OOM(vm, String::from_utf8(plus_sign_symbol)) });
|
||||
}
|
||||
|
||||
// e. Else if p is equal to "minusSign", then
|
||||
|
@ -615,7 +615,7 @@ ThrowCompletionOr<Vector<PatternPartition>> partition_number_pattern(VM& vm, Num
|
|||
// i. Let minusSignSymbol be the ILND String representing the minus sign.
|
||||
auto minus_sign_symbol = ::Locale::get_number_system_symbol(number_format.data_locale(), number_format.numbering_system(), ::Locale::NumericSymbol::MinusSign).value_or("-"sv);
|
||||
// ii. Append a new Record { [[Type]]: "minusSign", [[Value]]: minusSignSymbol } as the last element of result.
|
||||
result.append({ "minusSign"sv, minus_sign_symbol });
|
||||
result.append({ "minusSign"sv, TRY_OR_THROW_OOM(vm, String::from_utf8(minus_sign_symbol)) });
|
||||
}
|
||||
|
||||
// f. Else if p is equal to "percentSign" and numberFormat.[[Style]] is "percent", then
|
||||
|
@ -623,7 +623,7 @@ ThrowCompletionOr<Vector<PatternPartition>> partition_number_pattern(VM& vm, Num
|
|||
// i. Let percentSignSymbol be the ILND String representing the percent sign.
|
||||
auto percent_sign_symbol = ::Locale::get_number_system_symbol(number_format.data_locale(), number_format.numbering_system(), ::Locale::NumericSymbol::PercentSign).value_or("%"sv);
|
||||
// ii. Append a new Record { [[Type]]: "percentSign", [[Value]]: percentSignSymbol } as the last element of result.
|
||||
result.append({ "percentSign"sv, percent_sign_symbol });
|
||||
result.append({ "percentSign"sv, TRY_OR_THROW_OOM(vm, String::from_utf8(percent_sign_symbol)) });
|
||||
}
|
||||
|
||||
// g. Else if p is equal to "unitPrefix" and numberFormat.[[Style]] is "unit", then
|
||||
|
@ -640,7 +640,7 @@ ThrowCompletionOr<Vector<PatternPartition>> partition_number_pattern(VM& vm, Num
|
|||
auto unit_identifier = found_pattern.identifiers[*identifier_index];
|
||||
|
||||
// iv. Append a new Record { [[Type]]: "unit", [[Value]]: mu } as the last element of result.
|
||||
result.append({ "unit"sv, unit_identifier });
|
||||
result.append({ "unit"sv, TRY_OR_THROW_OOM(vm, String::from_utf8(unit_identifier)) });
|
||||
}
|
||||
|
||||
// i. Else if p is equal to "currencyCode" and numberFormat.[[Style]] is "currency", then
|
||||
|
@ -651,7 +651,8 @@ ThrowCompletionOr<Vector<PatternPartition>> partition_number_pattern(VM& vm, Num
|
|||
// currency code during GetNumberFormatPattern so that we do not have to do currency
|
||||
// display / plurality lookups more than once.
|
||||
else if ((part == "currency"sv) && (number_format.style() == NumberFormat::Style::Currency)) {
|
||||
result.append({ "currency"sv, number_format.resolve_currency_display() });
|
||||
auto currency = number_format.resolve_currency_display();
|
||||
result.append({ "currency"sv, TRY_OR_THROW_OOM(vm, String::from_utf8(currency)) });
|
||||
}
|
||||
|
||||
// l. Else,
|
||||
|
@ -727,12 +728,12 @@ ThrowCompletionOr<Vector<PatternPartition>> partition_notation_sub_pattern(VM& v
|
|||
// 2. If x is NaN, then
|
||||
if (number.is_nan()) {
|
||||
// a. Append a new Record { [[Type]]: "nan", [[Value]]: n } as the last element of result.
|
||||
result.append({ "nan"sv, move(formatted_string) });
|
||||
result.append({ "nan"sv, TRY_OR_THROW_OOM(vm, String::from_deprecated_string(formatted_string)) });
|
||||
}
|
||||
// 3. Else if x is a non-finite Number, then
|
||||
else if (number.is_positive_infinity() || number.is_negative_infinity()) {
|
||||
// a. Append a new Record { [[Type]]: "infinity", [[Value]]: n } as the last element of result.
|
||||
result.append({ "infinity"sv, move(formatted_string) });
|
||||
result.append({ "infinity"sv, TRY_OR_THROW_OOM(vm, String::from_deprecated_string(formatted_string)) });
|
||||
}
|
||||
// 4. Else,
|
||||
else {
|
||||
|
@ -797,7 +798,7 @@ ThrowCompletionOr<Vector<PatternPartition>> partition_notation_sub_pattern(VM& v
|
|||
// 6. If the numberFormat.[[UseGrouping]] is false, then
|
||||
if (number_format.use_grouping() == NumberFormat::UseGrouping::False) {
|
||||
// a. Append a new Record { [[Type]]: "integer", [[Value]]: integer } as the last element of result.
|
||||
result.append({ "integer"sv, integer });
|
||||
result.append({ "integer"sv, TRY_OR_THROW_OOM(vm, String::from_utf8(integer)) });
|
||||
}
|
||||
// 7. Else,
|
||||
else {
|
||||
|
@ -816,12 +817,12 @@ ThrowCompletionOr<Vector<PatternPartition>> partition_notation_sub_pattern(VM& v
|
|||
auto integer_group = groups.take_first();
|
||||
|
||||
// ii. Append a new Record { [[Type]]: "integer", [[Value]]: integerGroup } as the last element of result.
|
||||
result.append({ "integer"sv, integer_group });
|
||||
result.append({ "integer"sv, TRY_OR_THROW_OOM(vm, String::from_utf8(integer_group)) });
|
||||
|
||||
// iii. If groups List is not empty, then
|
||||
if (!groups.is_empty()) {
|
||||
// i. Append a new Record { [[Type]]: "group", [[Value]]: groupSepSymbol } as the last element of result.
|
||||
result.append({ "group"sv, group_sep_symbol });
|
||||
result.append({ "group"sv, TRY_OR_THROW_OOM(vm, String::from_utf8(group_sep_symbol)) });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -831,9 +832,9 @@ ThrowCompletionOr<Vector<PatternPartition>> partition_notation_sub_pattern(VM& v
|
|||
// a. Let decimalSepSymbol be the ILND String representing the decimal separator.
|
||||
auto decimal_sep_symbol = ::Locale::get_number_system_symbol(number_format.data_locale(), number_format.numbering_system(), ::Locale::NumericSymbol::Decimal).value_or("."sv);
|
||||
// b. Append a new Record { [[Type]]: "decimal", [[Value]]: decimalSepSymbol } as the last element of result.
|
||||
result.append({ "decimal"sv, decimal_sep_symbol });
|
||||
result.append({ "decimal"sv, TRY_OR_THROW_OOM(vm, String::from_utf8(decimal_sep_symbol)) });
|
||||
// c. Append a new Record { [[Type]]: "fraction", [[Value]]: fraction } as the last element of result.
|
||||
result.append({ "fraction"sv, fraction.release_value() });
|
||||
result.append({ "fraction"sv, TRY_OR_THROW_OOM(vm, String::from_utf8(*fraction)) });
|
||||
}
|
||||
}
|
||||
// iv. Else if p is equal to "compactSymbol", then
|
||||
|
@ -848,14 +849,14 @@ ThrowCompletionOr<Vector<PatternPartition>> partition_notation_sub_pattern(VM& v
|
|||
auto compact_identifier = number_format.compact_format().identifiers[*identifier_index];
|
||||
|
||||
// 2. Append a new Record { [[Type]]: "compact", [[Value]]: compactSymbol } as the last element of result.
|
||||
result.append({ "compact"sv, compact_identifier });
|
||||
result.append({ "compact"sv, TRY_OR_THROW_OOM(vm, String::from_utf8(compact_identifier)) });
|
||||
}
|
||||
// vi. Else if p is equal to "scientificSeparator", then
|
||||
else if (part == "scientificSeparator"sv) {
|
||||
// 1. Let scientificSeparator be the ILND String representing the exponent separator.
|
||||
auto scientific_separator = ::Locale::get_number_system_symbol(number_format.data_locale(), number_format.numbering_system(), ::Locale::NumericSymbol::Exponential).value_or("E"sv);
|
||||
// 2. Append a new Record { [[Type]]: "exponentSeparator", [[Value]]: scientificSeparator } as the last element of result.
|
||||
result.append({ "exponentSeparator"sv, scientific_separator });
|
||||
result.append({ "exponentSeparator"sv, TRY_OR_THROW_OOM(vm, String::from_utf8(scientific_separator)) });
|
||||
}
|
||||
// vii. Else if p is equal to "scientificExponent", then
|
||||
else if (part == "scientificExponent"sv) {
|
||||
|
@ -865,7 +866,7 @@ ThrowCompletionOr<Vector<PatternPartition>> partition_notation_sub_pattern(VM& v
|
|||
auto minus_sign_symbol = ::Locale::get_number_system_symbol(number_format.data_locale(), number_format.numbering_system(), ::Locale::NumericSymbol::MinusSign).value_or("-"sv);
|
||||
|
||||
// b. Append a new Record { [[Type]]: "exponentMinusSign", [[Value]]: minusSignSymbol } as the last element of result.
|
||||
result.append({ "exponentMinusSign"sv, minus_sign_symbol });
|
||||
result.append({ "exponentMinusSign"sv, TRY_OR_THROW_OOM(vm, String::from_utf8(minus_sign_symbol)) });
|
||||
|
||||
// c. Let exponent be -exponent.
|
||||
exponent *= -1;
|
||||
|
@ -880,7 +881,7 @@ ThrowCompletionOr<Vector<PatternPartition>> partition_notation_sub_pattern(VM& v
|
|||
exponent_result.formatted_string = ::Locale::replace_digits_for_number_system(number_format.numbering_system(), exponent_result.formatted_string);
|
||||
|
||||
// 3. Append a new Record { [[Type]]: "exponentInteger", [[Value]]: exponentResult.[[FormattedString]] } as the last element of result.
|
||||
result.append({ "exponentInteger"sv, move(exponent_result.formatted_string) });
|
||||
result.append({ "exponentInteger"sv, TRY_OR_THROW_OOM(vm, String::from_deprecated_string(exponent_result.formatted_string)) });
|
||||
}
|
||||
// viii. Else,
|
||||
else {
|
||||
|
@ -1746,7 +1747,7 @@ ThrowCompletionOr<Vector<PatternPartitionWithSource>> partition_number_range_pat
|
|||
// 5. If xResult is equal to yResult, then
|
||||
if (start_result == end_result) {
|
||||
// a. Let appxResult be ? FormatApproximately(numberFormat, xResult).
|
||||
auto approximate_result = format_approximately(number_format, move(start_result));
|
||||
auto approximate_result = TRY(format_approximately(vm, number_format, move(start_result)));
|
||||
|
||||
// b. For each r in appxResult, do
|
||||
for (auto& result : approximate_result) {
|
||||
|
@ -1774,7 +1775,7 @@ ThrowCompletionOr<Vector<PatternPartitionWithSource>> partition_number_range_pat
|
|||
// 9. Append a new Record { [[Type]]: "literal", [[Value]]: rangeSeparator, [[Source]]: "shared" } element to result.
|
||||
PatternPartitionWithSource part;
|
||||
part.type = "literal"sv;
|
||||
part.value = range_separator.value_or(range_separator_symbol);
|
||||
part.value = TRY_OR_THROW_OOM(vm, String::from_deprecated_string(range_separator.value_or(range_separator_symbol)));
|
||||
part.source = "shared"sv;
|
||||
result.append(move(part));
|
||||
|
||||
|
@ -1792,7 +1793,7 @@ ThrowCompletionOr<Vector<PatternPartitionWithSource>> partition_number_range_pat
|
|||
}
|
||||
|
||||
// 1.5.20 FormatApproximately ( numberFormat, result ), https://tc39.es/proposal-intl-numberformat-v3/out/numberformat/proposed.html#sec-formatapproximately
|
||||
Vector<PatternPartitionWithSource> format_approximately(NumberFormat& number_format, Vector<PatternPartitionWithSource> result)
|
||||
ThrowCompletionOr<Vector<PatternPartitionWithSource>> format_approximately(VM& vm, NumberFormat& number_format, Vector<PatternPartitionWithSource> result)
|
||||
{
|
||||
// 1. Let i be an index into result, determined by an implementation-defined algorithm based on numberFormat and result.
|
||||
// 2. Let approximatelySign be an ILND String value used to signify that a number is approximate.
|
||||
|
@ -1801,7 +1802,7 @@ Vector<PatternPartitionWithSource> format_approximately(NumberFormat& number_for
|
|||
// 3. Insert a new Record { [[Type]]: "approximatelySign", [[Value]]: approximatelySign } at index i in result.
|
||||
PatternPartitionWithSource partition;
|
||||
partition.type = "approximatelySign"sv;
|
||||
partition.value = approximately_sign;
|
||||
partition.value = TRY_OR_THROW_OOM(vm, String::from_utf8(approximately_sign));
|
||||
|
||||
result.insert_before_matching(move(partition), [](auto const& part) {
|
||||
return part.type.is_one_of("integer"sv, "decimal"sv, "plusSign"sv, "minusSign"sv, "percentSign"sv, "currency"sv);
|
||||
|
|
|
@ -292,7 +292,7 @@ ThrowCompletionOr<MathematicalValue> to_intl_mathematical_value(VM&, Value value
|
|||
NumberFormat::UnsignedRoundingMode get_unsigned_rounding_mode(NumberFormat::RoundingMode, bool is_negative);
|
||||
RoundingDecision apply_unsigned_rounding_mode(MathematicalValue const& x, MathematicalValue const& r1, MathematicalValue const& r2, Optional<NumberFormat::UnsignedRoundingMode> const& unsigned_rounding_mode);
|
||||
ThrowCompletionOr<Vector<PatternPartitionWithSource>> partition_number_range_pattern(VM&, NumberFormat&, MathematicalValue start, MathematicalValue end);
|
||||
Vector<PatternPartitionWithSource> format_approximately(NumberFormat&, Vector<PatternPartitionWithSource> result);
|
||||
ThrowCompletionOr<Vector<PatternPartitionWithSource>> format_approximately(VM&, NumberFormat&, Vector<PatternPartitionWithSource> result);
|
||||
Vector<PatternPartitionWithSource> collapse_number_range(Vector<PatternPartitionWithSource> result);
|
||||
ThrowCompletionOr<DeprecatedString> format_numeric_range(VM&, NumberFormat&, MathematicalValue start, MathematicalValue end);
|
||||
ThrowCompletionOr<Array*> format_numeric_range_to_parts(VM&, NumberFormat&, MathematicalValue start, MathematicalValue end);
|
||||
|
|
|
@ -148,7 +148,7 @@ ThrowCompletionOr<Vector<PatternPartitionWithUnit>> partition_relative_time_patt
|
|||
VERIFY(patterns.size() == 1);
|
||||
|
||||
// i. Let result be patterns.[[<valueString>]].
|
||||
auto result = patterns[0].pattern.to_deprecated_string();
|
||||
auto result = TRY_OR_THROW_OOM(vm, String::from_utf8(patterns[0].pattern));
|
||||
|
||||
// ii. Return a List containing the Record { [[Type]]: "literal", [[Value]]: result }.
|
||||
return Vector<PatternPartitionWithUnit> { { "literal"sv, move(result) } };
|
||||
|
|
|
@ -74,7 +74,7 @@ private:
|
|||
};
|
||||
|
||||
struct PatternPartitionWithUnit : public PatternPartition {
|
||||
PatternPartitionWithUnit(StringView type, DeprecatedString value, StringView unit_string = {})
|
||||
PatternPartitionWithUnit(StringView type, String value, StringView unit_string = {})
|
||||
: PatternPartition(type, move(value))
|
||||
, unit(unit_string)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue