#ifndef V8_INTL_SUPPORT
#error Internationalization is expected to be enabled.
#endif
#include "src/objects/js-number-format.h"
#include <set>
#include <string>
#include "src/execution/isolate.h"
#include "src/numbers/conversions.h"
#include "src/objects/intl-objects.h"
#include "src/objects/js-number-format-inl.h"
#include "src/objects/managed-inl.h"
#include "src/objects/objects-inl.h"
#include "src/objects/option-utils.h"
#include "src/strings/char-predicates-inl.h"
#include "unicode/currunit.h"
#include "unicode/locid.h"
#include "unicode/numberformatter.h"
#include "unicode/numberrangeformatter.h"
#include "unicode/numsys.h"
#include "unicode/ucurr.h"
#include "unicode/uloc.h"
#include "unicode/unumberformatter.h"
#include "unicode/uvernum.h"
namespace v8 {
namespace internal {
namespace {
#define AVOID_AMBIGUOUS_OP_WARNING(x) …
enum class Style { … };
enum class CurrencyDisplay { … };
enum class CurrencySign { … };
enum class UnitDisplay { … };
enum class Notation { … };
enum class CompactDisplay { … };
enum class SignDisplay { … };
enum class UseGrouping { … };
UNumberUnitWidth ToUNumberUnitWidth(CurrencyDisplay currency_display) { … }
UNumberUnitWidth ToUNumberUnitWidth(UnitDisplay unit_display) { … }
UNumberSignDisplay ToUNumberSignDisplay(SignDisplay sign_display,
CurrencySign currency_sign) { … }
icu::number::Notation ToICUNotation(Notation notation,
CompactDisplay compact_display) { … }
UNumberFormatRoundingMode ToUNumberFormatRoundingMode(
Intl::RoundingMode rounding_mode) { … }
UNumberGroupingStrategy ToUNumberGroupingStrategy(UseGrouping use_grouping) { … }
std::map<const std::string, icu::MeasureUnit> CreateUnitMap() { … }
class UnitFactory { … };
icu::MeasureUnit IsSanctionedUnitIdentifier(const std::string& unit) { … }
Maybe<std::pair<icu::MeasureUnit, icu::MeasureUnit>> IsWellFormedUnitIdentifier(
Isolate* isolate, const std::string& unit) { … }
int CurrencyDigits(const icu::UnicodeString& currency) { … }
bool IsAToZ(char ch) { … }
bool IsWellFormedCurrencyCode(const std::string& currency) { … }
Handle<String> StyleAsString(Isolate* isolate, Style style) { … }
Handle<String> CurrencyDisplayString(Isolate* isolate,
const icu::UnicodeString& skeleton) { … }
Handle<Object> UseGroupingFromSkeleton(Isolate* isolate,
const icu::UnicodeString& skeleton) { … }
const icu::UnicodeString CurrencyFromSkeleton(
const icu::UnicodeString& skeleton) { … }
}
const icu::UnicodeString JSNumberFormat::NumberingSystemFromSkeleton(
const icu::UnicodeString& skeleton) { … }
namespace {
Handle<String> CurrencySignString(Isolate* isolate,
const icu::UnicodeString& skeleton) { … }
Handle<String> UnitDisplayString(Isolate* isolate,
const icu::UnicodeString& skeleton) { … }
Notation NotationFromSkeleton(const icu::UnicodeString& skeleton) { … }
Handle<String> NotationAsString(Isolate* isolate, Notation notation) { … }
Handle<String> CompactDisplayString(Isolate* isolate,
const icu::UnicodeString& skeleton) { … }
Handle<String> SignDisplayString(Isolate* isolate,
const icu::UnicodeString& skeleton) { … }
}
Handle<String> JSNumberFormat::RoundingModeString(
Isolate* isolate, const icu::UnicodeString& skeleton) { … }
Handle<Object> JSNumberFormat::RoundingIncrement(
Isolate* isolate, const icu::UnicodeString& skeleton) { … }
Handle<String> JSNumberFormat::RoundingPriorityString(
Isolate* isolate, const icu::UnicodeString& skeleton) { … }
Handle<String> JSNumberFormat::TrailingZeroDisplayString(
Isolate* isolate, const icu::UnicodeString& skeleton) { … }
int32_t JSNumberFormat::MinimumIntegerDigitsFromSkeleton(
const icu::UnicodeString& skeleton) { … }
bool JSNumberFormat::FractionDigitsFromSkeleton(
const icu::UnicodeString& skeleton, int32_t* minimum, int32_t* maximum) { … }
bool JSNumberFormat::SignificantDigitsFromSkeleton(
const icu::UnicodeString& skeleton, int32_t* minimum, int32_t* maximum) { … }
namespace {
std::string UnitFromSkeleton(const icu::UnicodeString& skeleton) { … }
Style StyleFromSkeleton(const icu::UnicodeString& skeleton) { … }
}
icu::number::UnlocalizedNumberFormatter
JSNumberFormat::SetDigitOptionsToFormatter(
const icu::number::UnlocalizedNumberFormatter& settings,
const Intl::NumberFormatDigitOptions& digit_options) { … }
Handle<JSObject> JSNumberFormat::ResolvedOptions(
Isolate* isolate, DirectHandle<JSNumberFormat> number_format) { … }
MaybeHandle<JSNumberFormat> JSNumberFormat::UnwrapNumberFormat(
Isolate* isolate, Handle<JSReceiver> format_holder) { … }
MaybeHandle<JSNumberFormat> JSNumberFormat::New(Isolate* isolate,
DirectHandle<Map> map,
Handle<Object> locales,
Handle<Object> options_obj,
const char* service) { … }
namespace {
icu::number::FormattedNumber FormatDecimalString(
Isolate* isolate,
const icu::number::LocalizedNumberFormatter& number_format,
Handle<String> string, UErrorCode& status) { … }
}
bool IntlMathematicalValue::IsNaN() const { … }
MaybeHandle<String> IntlMathematicalValue::ToString(Isolate* isolate) const { … }
namespace {
Maybe<icu::number::FormattedNumber> IcuFormatNumber(
Isolate* isolate,
const icu::number::LocalizedNumberFormatter& number_format,
Handle<Object> numeric_obj) { … }
}
Maybe<icu::number::FormattedNumber> IntlMathematicalValue::FormatNumeric(
Isolate* isolate,
const icu::number::LocalizedNumberFormatter& number_format,
const IntlMathematicalValue& x) { … }
Maybe<icu::number::FormattedNumberRange> IntlMathematicalValue::FormatRange(
Isolate* isolate,
const icu::number::LocalizedNumberRangeFormatter& number_range_format,
const IntlMathematicalValue& x, const IntlMathematicalValue& y) { … }
namespace {
template <typename Char>
std::pair<int, int> FindLeadingAndTrailingWhiteSpaceOrLineTerminator(
base::Vector<const Char> src) { … }
Handle<String> TrimWhiteSpaceOrLineTerminator(Isolate* isolate,
Handle<String> string) { … }
}
Maybe<IntlMathematicalValue> IntlMathematicalValue::From(Isolate* isolate,
Handle<Object> value) { … }
Maybe<icu::Formattable> IntlMathematicalValue::ToFormattable(
Isolate* isolate) const { … }
namespace {
bool cmp_NumberFormatSpan(const NumberFormatSpan& a,
const NumberFormatSpan& b) { … }
}
std::vector<NumberFormatSpan> FlattenRegionsToParts(
std::vector<NumberFormatSpan>* regions) { … }
namespace {
Maybe<int> ConstructParts(Isolate* isolate,
const icu::FormattedValue& formatted,
Handle<JSArray> result, int start_index,
bool style_is_unit, bool is_nan, bool output_source,
bool output_unit, DirectHandle<String> unit) { … }
}
Maybe<int> Intl::AddNumberElements(Isolate* isolate,
const icu::FormattedValue& formatted,
Handle<JSArray> result, int start_index,
DirectHandle<String> unit) { … }
namespace {
template <typename T, MaybeHandle<T> (*F)(
Isolate*, const icu::FormattedValue&,
const icu::number::LocalizedNumberFormatter&, bool)>
MaybeHandle<T> PartitionNumberRangePattern(
Isolate* isolate, DirectHandle<JSNumberFormat> number_format,
Handle<Object> start, Handle<Object> end, const char* func_name) { … }
MaybeHandle<String> FormatToString(Isolate* isolate,
const icu::FormattedValue& formatted,
const icu::number::LocalizedNumberFormatter&,
bool) { … }
MaybeHandle<JSArray> FormatToJSArray(
Isolate* isolate, const icu::FormattedValue& formatted,
const icu::number::LocalizedNumberFormatter& nfmt, bool is_nan,
bool output_source) { … }
MaybeHandle<JSArray> FormatRangeToJSArray(
Isolate* isolate, const icu::FormattedValue& formatted,
const icu::number::LocalizedNumberFormatter& nfmt, bool is_nan) { … }
}
Maybe<icu::number::LocalizedNumberRangeFormatter>
JSNumberFormat::GetRangeFormatter(
Isolate* isolate, Tagged<String> locale,
const icu::number::LocalizedNumberFormatter& number_formatter) { … }
MaybeHandle<String> JSNumberFormat::FormatNumeric(
Isolate* isolate,
const icu::number::LocalizedNumberFormatter& number_format,
Handle<Object> numeric_obj) { … }
MaybeHandle<String> JSNumberFormat::NumberFormatFunction(
Isolate* isolate, DirectHandle<JSNumberFormat> number_format,
Handle<Object> value) { … }
MaybeHandle<JSArray> JSNumberFormat::FormatToParts(
Isolate* isolate, DirectHandle<JSNumberFormat> number_format,
Handle<Object> numeric_obj) { … }
MaybeHandle<String> JSNumberFormat::FormatNumericRange(
Isolate* isolate, DirectHandle<JSNumberFormat> number_format,
Handle<Object> x_obj, Handle<Object> y_obj) { … }
MaybeHandle<JSArray> JSNumberFormat::FormatNumericRangeToParts(
Isolate* isolate, DirectHandle<JSNumberFormat> number_format,
Handle<Object> x_obj, Handle<Object> y_obj) { … }
namespace {
struct CheckNumberElements { … };
}
const std::set<std::string>& JSNumberFormat::GetAvailableLocales() { … }
}
}