Produce JS-visible string results as UTF-16 at their source, including numeric formatting, BigInt and BigFraction formatting, URI encoding, console formatting, parser errors, regular expression errors, Intl and Temporal records, LibUnicode locale boundaries, and LibWeb bindings. Handle fractional radix formatting through the UTF-16 builder view.
71 lines
1.5 KiB
C++
71 lines
1.5 KiB
C++
/*
|
|
* Copyright (c) 2022-2024, Tim Flynn <trflynn89@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/String.h>
|
|
#include <AK/Utf16String.h>
|
|
#include <AK/Variant.h>
|
|
#include <LibCrypto/BigInt/SignedBigInteger.h>
|
|
#include <LibJS/Export.h>
|
|
#include <LibJS/Runtime/BigInt.h>
|
|
#include <LibJS/Runtime/Value.h>
|
|
#include <LibUnicode/NumberFormat.h>
|
|
|
|
namespace JS::Intl {
|
|
|
|
// https://tc39.es/ecma402/#intl-mathematical-value
|
|
class JS_API MathematicalValue {
|
|
public:
|
|
enum class Symbol {
|
|
PositiveInfinity,
|
|
NegativeInfinity,
|
|
NegativeZero,
|
|
NotANumber,
|
|
};
|
|
|
|
MathematicalValue() = default;
|
|
|
|
explicit MathematicalValue(double value)
|
|
: m_value(value_from_number(value))
|
|
{
|
|
}
|
|
|
|
explicit MathematicalValue(Utf16String value)
|
|
: m_value(move(value))
|
|
{
|
|
}
|
|
|
|
explicit MathematicalValue(Symbol symbol)
|
|
: m_value(symbol)
|
|
{
|
|
}
|
|
|
|
MathematicalValue(Value);
|
|
|
|
bool is_number() const;
|
|
double as_number() const;
|
|
|
|
bool is_string() const;
|
|
Utf16String const& as_string() const;
|
|
|
|
bool is_mathematical_value() const;
|
|
bool is_positive_infinity() const;
|
|
bool is_negative_infinity() const;
|
|
bool is_negative_zero() const;
|
|
bool is_nan() const;
|
|
|
|
Unicode::NumberFormat::Value to_value() const;
|
|
|
|
private:
|
|
using ValueType = Variant<double, Utf16String, Symbol>;
|
|
|
|
static ValueType value_from_number(double number);
|
|
|
|
ValueType m_value { 0.0 };
|
|
};
|
|
|
|
}
|