diff --git a/Libraries/LibJS/Runtime/Intl/DurationFormat.cpp b/Libraries/LibJS/Runtime/Intl/DurationFormat.cpp index bd760204426..f5215499359 100644 --- a/Libraries/LibJS/Runtime/Intl/DurationFormat.cpp +++ b/Libraries/LibJS/Runtime/Intl/DurationFormat.cpp @@ -407,7 +407,7 @@ Vector format_numeric_hours(VM& vm, DurationFormat const& du for (auto& part : hours_parts) { // a. Append the Record { [[Type]]: part.[[Type]], [[Value]]: part.[[Value]], [[Unit]]: "hour" } to result. - result.unchecked_append({ .type = part.type, .value = move(part.value), .unit = "hour"sv }); + result.unchecked_append({ .type = part.type, .value = part.value.to_utf8_but_should_be_ported_to_utf16(), .unit = "hour"sv }); } // 13. Return result. @@ -472,7 +472,7 @@ Vector format_numeric_minutes(VM& vm, DurationFormat const& for (auto& part : minutes_parts) { // a. Append the Record { [[Type]]: part.[[Type]], [[Value]]: part.[[Value]], [[Unit]]: "minute" } to result. - result.unchecked_append({ .type = part.type, .value = move(part.value), .unit = "minute"sv }); + result.unchecked_append({ .type = part.type, .value = part.value.to_utf8_but_should_be_ported_to_utf16(), .unit = "minute"sv }); } // 14. Return result. @@ -560,7 +560,7 @@ Vector format_numeric_seconds(VM& vm, DurationFormat const& for (auto& part : seconds_parts) { // a. Append the Record { [[Type]]: part.[[Type]], [[Value]]: part.[[Value]], [[Unit]]: "second" } to result. - result.unchecked_append({ .type = part.type, .value = move(part.value), .unit = "second"sv }); + result.unchecked_append({ .type = part.type, .value = part.value.to_utf8_but_should_be_ported_to_utf16(), .unit = "second"sv }); } // 18. Return result. @@ -922,7 +922,7 @@ Vector partition_duration_format_pattern(VM& vm, DurationFor for (auto& part : parts) { // a. Append the Record { [[Type]]: part.[[Type]], [[Value]]: part.[[Value]], [[Unit]]: numberFormatUnit } to list. - list.unchecked_append({ .type = part.type, .value = move(part.value), .unit = number_format_unit.as_string() }); + list.unchecked_append({ .type = part.type, .value = part.value.to_utf8_but_should_be_ported_to_utf16(), .unit = number_format_unit.as_string() }); } // 11. Append list to result. diff --git a/Libraries/LibJS/Runtime/Intl/NumberFormat.cpp b/Libraries/LibJS/Runtime/Intl/NumberFormat.cpp index 27213a19d0e..16af55adec0 100644 --- a/Libraries/LibJS/Runtime/Intl/NumberFormat.cpp +++ b/Libraries/LibJS/Runtime/Intl/NumberFormat.cpp @@ -152,7 +152,7 @@ Vector partition_number_pattern(NumberFormat c } // 16.5.6 FormatNumeric ( numberFormat, x ), https://tc39.es/ecma402/#sec-formatnumber -String format_numeric(NumberFormat const& number_format, MathematicalValue const& number) +Utf16String format_numeric(NumberFormat const& number_format, MathematicalValue const& number) { // 1. Let parts be ? PartitionNumberPattern(numberFormat, x). // 2. Let result be the empty String. @@ -258,7 +258,7 @@ ThrowCompletionOr> partition_number_ran } // 16.5.22 FormatNumericRange ( numberFormat, x, y ), https://tc39.es/ecma402/#sec-formatnumericrange -ThrowCompletionOr format_numeric_range(VM& vm, NumberFormat const& number_format, MathematicalValue const& start, MathematicalValue const& end) +ThrowCompletionOr format_numeric_range(VM& vm, NumberFormat const& number_format, MathematicalValue const& start, MathematicalValue const& end) { // 1. Let parts be ? PartitionNumberRangePattern(numberFormat, x, y). { diff --git a/Libraries/LibJS/Runtime/Intl/NumberFormat.h b/Libraries/LibJS/Runtime/Intl/NumberFormat.h index fad9379fca3..e88ddcf2ae6 100644 --- a/Libraries/LibJS/Runtime/Intl/NumberFormat.h +++ b/Libraries/LibJS/Runtime/Intl/NumberFormat.h @@ -182,11 +182,11 @@ private: int currency_digits(StringView currency); Vector partition_number_pattern(NumberFormat const&, MathematicalValue const& number); -String format_numeric(NumberFormat const&, MathematicalValue const& number); +Utf16String format_numeric(NumberFormat const&, MathematicalValue const& number); GC::Ref format_numeric_to_parts(VM&, NumberFormat const&, MathematicalValue const& number); ThrowCompletionOr to_intl_mathematical_value(VM&, Value value); ThrowCompletionOr> partition_number_range_pattern(VM&, NumberFormat const&, MathematicalValue const& start, MathematicalValue const& end); -ThrowCompletionOr format_numeric_range(VM&, NumberFormat const&, MathematicalValue const& start, MathematicalValue const& end); +ThrowCompletionOr format_numeric_range(VM&, NumberFormat const&, MathematicalValue const& start, MathematicalValue const& end); ThrowCompletionOr> format_numeric_range_to_parts(VM&, NumberFormat const&, MathematicalValue const& start, MathematicalValue const& end); } diff --git a/Libraries/LibUnicode/NumberFormat.cpp b/Libraries/LibUnicode/NumberFormat.cpp index 7d9e786ad96..35a79a7de60 100644 --- a/Libraries/LibUnicode/NumberFormat.cpp +++ b/Libraries/LibUnicode/NumberFormat.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2024, Tim Flynn + * Copyright (c) 2021-2025, Tim Flynn * * SPDX-License-Identifier: BSD-2-Clause */ @@ -601,7 +601,7 @@ public: virtual ~NumberFormatImpl() override = default; - virtual String format(Value const& value) const override + virtual Utf16String format(Value const& value) const override { UErrorCode status = U_ZERO_ERROR; @@ -613,7 +613,7 @@ public: if (icu_failure(status)) return {}; - return icu_string_to_string(result); + return icu_string_to_utf16_string(result); } virtual Vector format_to_parts(Value const& value) const override @@ -625,7 +625,7 @@ public: return format_to_parts_impl(formatted, value, value); } - virtual String format_range(Value const& start, Value const& end) const override + virtual Utf16String format_range(Value const& start, Value const& end) const override { UErrorCode status = U_ZERO_ERROR; @@ -637,7 +637,7 @@ public: if (icu_failure(status)) return {}; - return icu_string_to_string(result); + return icu_string_to_utf16_string(result); } virtual Vector format_range_to_parts(Value const& start, Value const& end) const override @@ -830,7 +830,7 @@ private: auto value = formatted_number.tempSubStringBetween(range.start, range.end); Partition partition; - partition.value = icu_string_to_string(value); + partition.value = icu_string_to_utf16_string(value); apply_to_partition(partition, range.field, range.start); result.unchecked_append(move(partition)); diff --git a/Libraries/LibUnicode/NumberFormat.h b/Libraries/LibUnicode/NumberFormat.h index 586b3f238d8..6b4699deb72 100644 --- a/Libraries/LibUnicode/NumberFormat.h +++ b/Libraries/LibUnicode/NumberFormat.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2024, Tim Flynn + * Copyright (c) 2021-2025, Tim Flynn * * SPDX-License-Identifier: BSD-2-Clause */ @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -149,16 +150,16 @@ public: struct Partition { StringView type; - String value; + Utf16String value; StringView source; }; using Value = Variant; - virtual String format(Value const&) const = 0; + virtual Utf16String format(Value const&) const = 0; virtual Vector format_to_parts(Value const&) const = 0; - virtual String format_range(Value const&, Value const&) const = 0; + virtual Utf16String format_range(Value const&, Value const&) const = 0; virtual Vector format_range_to_parts(Value const&, Value const&) const = 0; virtual void create_plural_rules(PluralForm) = 0;