#ifndef V8_INTL_SUPPORT
#error Internationalization is expected to be enabled.
#endif
#include "src/objects/js-duration-format.h"
#include <map>
#include <memory>
#include <string>
#include <string_view>
#include "src/common/globals.h"
#include "src/execution/isolate.h"
#include "src/heap/factory.h"
#include "src/objects/intl-objects.h"
#include "src/objects/js-duration-format-inl.h"
#include "src/objects/js-number-format.h"
#include "src/objects/js-temporal-objects.h"
#include "src/objects/managed-inl.h"
#include "src/objects/objects-inl.h"
#include "src/objects/option-utils.h"
#include "unicode/dtfmtsym.h"
#include "unicode/listformatter.h"
#include "unicode/locid.h"
#include "unicode/numberformatter.h"
#include "unicode/ulistformatter.h"
#include "unicode/unumberformatter.h"
namespace v8 {
namespace internal {
DurationRecord;
namespace {
enum class StylesList { … };
enum class Unit { … };
struct DurationUnitOptions { … };
const std::initializer_list<const char*> kLongShortNarrowStrings = {
"long", "short", "narrow"};
const std::initializer_list<const char*> kLongShortNarrowNumericStrings = {
"long", "short", "narrow", "numeric"};
const std::initializer_list<const char*> kLongShortNarrowNumeric2DigitStrings =
{"long", "short", "narrow", "numeric", "2-digit"};
const std::initializer_list<JSDurationFormat::FieldStyle>
kLongShortNarrowEnums = {JSDurationFormat::FieldStyle::kLong,
JSDurationFormat::FieldStyle::kShort,
JSDurationFormat::FieldStyle::kNarrow};
const std::initializer_list<JSDurationFormat::FieldStyle>
kLongShortNarrowNumericEnums = {JSDurationFormat::FieldStyle::kLong,
JSDurationFormat::FieldStyle::kShort,
JSDurationFormat::FieldStyle::kNarrow,
JSDurationFormat::FieldStyle::kNumeric};
const std::initializer_list<JSDurationFormat::FieldStyle>
kLongShortNarrowNumeric2DigitEnums = {
JSDurationFormat::FieldStyle::kLong,
JSDurationFormat::FieldStyle::kShort,
JSDurationFormat::FieldStyle::kNarrow,
JSDurationFormat::FieldStyle::kNumeric,
JSDurationFormat::FieldStyle::k2Digit};
Maybe<DurationUnitOptions> GetDurationUnitOptions(
Isolate* isolate, Unit unit, const char* unit_string,
const char* display_field, Handle<JSReceiver> options,
JSDurationFormat::Style base_style,
const std::vector<const char*>& value_strings,
const std::vector<JSDurationFormat::FieldStyle>& value_enums,
JSDurationFormat::FieldStyle digital_base,
JSDurationFormat::FieldStyle prev_style) { … }
JSDurationFormat::Separator GetSeparator(const icu::Locale& l) { … }
}
MaybeHandle<JSDurationFormat> JSDurationFormat::New(
Isolate* isolate, DirectHandle<Map> map, Handle<Object> locales,
Handle<Object> input_options) { … }
namespace {
Handle<String> StyleToString(Isolate* isolate, JSDurationFormat::Style style) { … }
Handle<String> StyleToString(Isolate* isolate,
JSDurationFormat::FieldStyle style) { … }
Handle<String> DisplayToString(Isolate* isolate,
JSDurationFormat::Display display) { … }
}
Handle<JSObject> JSDurationFormat::ResolvedOptions(
Isolate* isolate, DirectHandle<JSDurationFormat> format) { … }
namespace {
UNumberUnitWidth ToUNumberUnitWidth(JSDurationFormat::FieldStyle style) { … }
struct Part { … };
char16_t SeparatorToChar(JSDurationFormat::Separator separator) { … }
bool FormattedToParts(const char*, icu::number::FormattedNumber&, bool, bool,
JSDurationFormat::Separator,
std::vector<std::vector<Part>>*,
std::vector<icu::UnicodeString>*);
bool Output(const char* type, double value,
const icu::number::LocalizedNumberFormatter& fmt, bool addToLast,
bool display_negative_sign, bool negative_duration,
JSDurationFormat::Separator separator,
std::vector<std::vector<Part>>* parts,
std::vector<icu::UnicodeString>* strings) { … }
bool FormattedToParts(const char* type, icu::number::FormattedNumber& formatted,
bool addToLast, bool display_negative_sign,
JSDurationFormat::Separator separator,
std::vector<std::vector<Part>>* parts,
std::vector<icu::UnicodeString>* strings) { … }
bool OutputLongShortOrNarrow(const char* type, double value,
JSDurationFormat::Display display,
const icu::number::LocalizedNumberFormatter& fmt,
bool addToLast, bool display_negative_sign,
bool negative_duration,
JSDurationFormat::Separator separator,
std::vector<std::vector<Part>>* parts,
std::vector<icu::UnicodeString>* strings) { … }
bool OutputLongShortNarrowOrNumeric(
const char* type, double value, JSDurationFormat::Display display,
JSDurationFormat::FieldStyle style,
const icu::number::LocalizedNumberFormatter& fmt, icu::MeasureUnit unit,
bool addToLast, bool display_negative_sign, bool negative_duration,
JSDurationFormat::Separator separator,
std::vector<std::vector<Part>>* parts,
std::vector<icu::UnicodeString>* strings) { … }
bool OutputLongShortNarrowNumericOr2Digit(
const char* type, double value, JSDurationFormat::Display display,
JSDurationFormat::FieldStyle style,
const icu::number::LocalizedNumberFormatter& fmt, icu::MeasureUnit unit,
bool maybeAddToLast, bool displayRequired, bool display_negative_sign,
bool negative_duration, JSDurationFormat::Separator separator,
std::vector<std::vector<Part>>* parts,
std::vector<icu::UnicodeString>* strings) { … }
bool DisplayRequired(DirectHandle<JSDurationFormat> df,
const DurationRecord& record) { … }
void DurationRecordToListOfFormattedNumber(
DirectHandle<JSDurationFormat> df,
const icu::number::LocalizedNumberFormatter& fmt,
const DurationRecord& record, std::vector<std::vector<Part>>* parts,
std::vector<icu::UnicodeString>* strings) { … }
UListFormatterWidth StyleToWidth(JSDurationFormat::Style style) { … }
template <typename T, bool Details,
MaybeHandle<T> (*Format)(Isolate*, const icu::FormattedValue&,
const std::vector<std::vector<Part>>*,
JSDurationFormat::Separator separator)>
MaybeHandle<T> PartitionDurationFormatPattern(Isolate* isolate,
DirectHandle<JSDurationFormat> df,
const DurationRecord& record,
const char* method_name) { … }
Maybe<DurationRecord> ToDurationRecord(Isolate* isolate, Handle<Object> input,
const DurationRecord& default_value) { … }
template <typename T, bool Details,
MaybeHandle<T> (*Format)(Isolate*, const icu::FormattedValue&,
const std::vector<std::vector<Part>>*,
JSDurationFormat::Separator)>
MaybeHandle<T> FormatCommon(Isolate* isolate, Handle<JSDurationFormat> df,
Handle<Object> duration, const char* method_name) { … }
}
MaybeHandle<String> FormattedToString(
Isolate* isolate, const icu::FormattedValue& formatted,
const std::vector<std::vector<Part>>* parts, JSDurationFormat::Separator) { … }
MaybeHandle<JSArray> FormattedListToJSArray(
Isolate* isolate, const icu::FormattedValue& formatted,
const std::vector<std::vector<Part>>* parts,
JSDurationFormat::Separator separator) { … }
MaybeHandle<String> JSDurationFormat::Format(Isolate* isolate,
Handle<JSDurationFormat> df,
Handle<Object> duration) { … }
MaybeHandle<JSArray> JSDurationFormat::FormatToParts(
Isolate* isolate, Handle<JSDurationFormat> df, Handle<Object> duration) { … }
const std::set<std::string>& JSDurationFormat::GetAvailableLocales() { … }
}
}