mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 00:57:45 +00:00
LibJS: Convert Intl.NumberFormat to use Unicode::Style
This commit is contained in:
parent
25e67f63a2
commit
0865f71d37
2 changed files with 6 additions and 53 deletions
|
@ -10,7 +10,6 @@
|
||||||
#include <LibJS/Runtime/Intl/NumberFormat.h>
|
#include <LibJS/Runtime/Intl/NumberFormat.h>
|
||||||
#include <LibJS/Runtime/Intl/NumberFormatFunction.h>
|
#include <LibJS/Runtime/Intl/NumberFormatFunction.h>
|
||||||
#include <LibUnicode/CurrencyCode.h>
|
#include <LibUnicode/CurrencyCode.h>
|
||||||
#include <LibUnicode/Locale.h>
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
@ -145,34 +144,6 @@ StringView NumberFormat::currency_sign_string() const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NumberFormat::set_unit_display(StringView unit_display)
|
|
||||||
{
|
|
||||||
if (unit_display == "short"sv)
|
|
||||||
m_unit_display = UnitDisplay::Short;
|
|
||||||
else if (unit_display == "narrow"sv)
|
|
||||||
m_unit_display = UnitDisplay::Narrow;
|
|
||||||
else if (unit_display == "long"sv)
|
|
||||||
m_unit_display = UnitDisplay::Long;
|
|
||||||
else
|
|
||||||
VERIFY_NOT_REACHED();
|
|
||||||
}
|
|
||||||
|
|
||||||
StringView NumberFormat::unit_display_string() const
|
|
||||||
{
|
|
||||||
VERIFY(m_unit_display.has_value());
|
|
||||||
|
|
||||||
switch (*m_unit_display) {
|
|
||||||
case UnitDisplay::Short:
|
|
||||||
return "short"sv;
|
|
||||||
case UnitDisplay::Narrow:
|
|
||||||
return "narrow"sv;
|
|
||||||
case UnitDisplay::Long:
|
|
||||||
return "long"sv;
|
|
||||||
default:
|
|
||||||
VERIFY_NOT_REACHED();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
StringView NumberFormat::rounding_type_string() const
|
StringView NumberFormat::rounding_type_string() const
|
||||||
{
|
{
|
||||||
switch (m_rounding_type) {
|
switch (m_rounding_type) {
|
||||||
|
@ -1293,20 +1264,7 @@ Optional<Variant<StringView, String>> get_number_format_pattern(NumberFormat& nu
|
||||||
// i. Let unit be "fallback".
|
// i. Let unit be "fallback".
|
||||||
// e. Let patterns be patterns.[[<unit>]].
|
// e. Let patterns be patterns.[[<unit>]].
|
||||||
// f. Let patterns be patterns.[[<unitDisplay>]].
|
// f. Let patterns be patterns.[[<unitDisplay>]].
|
||||||
Vector<Unicode::NumberFormat> formats;
|
auto formats = Unicode::get_unit_formats(number_format.data_locale(), number_format.unit(), number_format.unit_display());
|
||||||
|
|
||||||
switch (number_format.unit_display()) {
|
|
||||||
case NumberFormat::UnitDisplay::Long:
|
|
||||||
formats = Unicode::get_unit_formats(number_format.data_locale(), number_format.unit(), Unicode::Style::Long);
|
|
||||||
break;
|
|
||||||
case NumberFormat::UnitDisplay::Short:
|
|
||||||
formats = Unicode::get_unit_formats(number_format.data_locale(), number_format.unit(), Unicode::Style::Short);
|
|
||||||
break;
|
|
||||||
case NumberFormat::UnitDisplay::Narrow:
|
|
||||||
formats = Unicode::get_unit_formats(number_format.data_locale(), number_format.unit(), Unicode::Style::Narrow);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
patterns = Unicode::select_pattern_with_plurality(formats, number);
|
patterns = Unicode::select_pattern_with_plurality(formats, number);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include <AK/String.h>
|
#include <AK/String.h>
|
||||||
#include <LibJS/Runtime/Intl/AbstractOperations.h>
|
#include <LibJS/Runtime/Intl/AbstractOperations.h>
|
||||||
#include <LibJS/Runtime/Object.h>
|
#include <LibJS/Runtime/Object.h>
|
||||||
|
#include <LibUnicode/Locale.h>
|
||||||
#include <LibUnicode/NumberFormat.h>
|
#include <LibUnicode/NumberFormat.h>
|
||||||
|
|
||||||
namespace JS::Intl {
|
namespace JS::Intl {
|
||||||
|
@ -39,12 +40,6 @@ public:
|
||||||
Accounting,
|
Accounting,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class UnitDisplay {
|
|
||||||
Short,
|
|
||||||
Narrow,
|
|
||||||
Long,
|
|
||||||
};
|
|
||||||
|
|
||||||
enum class RoundingType {
|
enum class RoundingType {
|
||||||
Invalid,
|
Invalid,
|
||||||
SignificantDigits,
|
SignificantDigits,
|
||||||
|
@ -116,9 +111,9 @@ public:
|
||||||
void set_unit(String unit) { m_unit = move(unit); }
|
void set_unit(String unit) { m_unit = move(unit); }
|
||||||
|
|
||||||
bool has_unit_display() const { return m_unit_display.has_value(); }
|
bool has_unit_display() const { return m_unit_display.has_value(); }
|
||||||
UnitDisplay unit_display() const { return *m_unit_display; }
|
Unicode::Style unit_display() const { return *m_unit_display; }
|
||||||
StringView unit_display_string() const;
|
StringView unit_display_string() const { return Unicode::style_to_string(*m_unit_display); }
|
||||||
void set_unit_display(StringView unit_display);
|
void set_unit_display(StringView unit_display) { m_unit_display = Unicode::style_from_string(unit_display); }
|
||||||
|
|
||||||
int min_integer_digits() const { return m_min_integer_digits; }
|
int min_integer_digits() const { return m_min_integer_digits; }
|
||||||
void set_min_integer_digits(int min_integer_digits) { m_min_integer_digits = min_integer_digits; }
|
void set_min_integer_digits(int min_integer_digits) { m_min_integer_digits = min_integer_digits; }
|
||||||
|
@ -177,7 +172,7 @@ private:
|
||||||
Optional<CurrencyDisplay> m_currency_display {}; // [[CurrencyDisplay]]
|
Optional<CurrencyDisplay> m_currency_display {}; // [[CurrencyDisplay]]
|
||||||
Optional<CurrencySign> m_currency_sign {}; // [[CurrencySign]]
|
Optional<CurrencySign> m_currency_sign {}; // [[CurrencySign]]
|
||||||
Optional<String> m_unit {}; // [[Unit]]
|
Optional<String> m_unit {}; // [[Unit]]
|
||||||
Optional<UnitDisplay> m_unit_display {}; // [[UnitDisplay]]
|
Optional<Unicode::Style> m_unit_display {}; // [[UnitDisplay]]
|
||||||
int m_min_integer_digits { 0 }; // [[MinimumIntegerDigits]]
|
int m_min_integer_digits { 0 }; // [[MinimumIntegerDigits]]
|
||||||
Optional<int> m_min_fraction_digits {}; // [[MinimumFractionDigits]]
|
Optional<int> m_min_fraction_digits {}; // [[MinimumFractionDigits]]
|
||||||
Optional<int> m_max_fraction_digits {}; // [[MaximumFractionDigits]]
|
Optional<int> m_max_fraction_digits {}; // [[MaximumFractionDigits]]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue