6 #ifndef MESSAGEFORMAT2_FORMATTABLE_H
7 #define MESSAGEFORMAT2_FORMATTABLE_H
9 #if U_SHOW_CPLUSPLUS_API
11 #if !UCONFIG_NO_NORMALIZATION
13 #if !UCONFIG_NO_FORMATTING
19 #include "unicode/messageformat2_data_model_names.h"
22 #ifndef U_HIDE_DEPRECATED_API
136 return (std::get_if<icu::Formattable>(&contents))->getDouble();
138 if (std::holds_alternative<double>(contents)) {
139 return *(std::get_if<double>(&contents));
157 if (isDecimal() && getType() ==
UFMT_LONG) {
158 return std::get_if<icu::Formattable>(&contents)->getLong();
160 if (std::holds_alternative<int64_t>(contents)) {
161 return static_cast<int32_t
>(*(std::get_if<int64_t>(&contents)));
181 return std::get_if<icu::Formattable>(&contents)->getInt64();
183 if (std::holds_alternative<int64_t>(contents)) {
184 return *(std::get_if<int64_t>(&contents));
217 if (std::holds_alternative<UnicodeString>(contents)) {
218 return *std::get_if<UnicodeString>(&contents);
239 return std::get_if<DateInfo>(&contents);
282 return *std::get_if<const FormattableObject*>(&contents);
300 swap(f1.contents, f2.contents);
422 std::pair<const Formattable*, int32_t>> contents;
425 UBool isDecimal()
const {
426 return std::holds_alternative<icu::Formattable>(contents);
428 UBool isDate()
const {
429 return std::holds_alternative<DateInfo>(contents);
455 bool sourceIsLiteral;
458 U_I18N_API const UnicodeString& getName()
const {
return name; }
459 U_I18N_API const Formattable& getValue()
const {
return value; }
460 U_I18N_API bool isLiteral()
const {
return sourceIsLiteral; }
461 U_I18N_API ResolvedFunctionOption(
const UnicodeString& n,
const Formattable& f,
bool s)
462 : name(n), value(f), sourceIsLiteral(s) {}
464 U_I18N_API ResolvedFunctionOption(ResolvedFunctionOption&&);
465 U_I18N_API ResolvedFunctionOption& operator=(ResolvedFunctionOption&& other) noexcept {
466 name = std::move(other.name);
467 value = std::move(other.value);
468 sourceIsLiteral = other.sourceIsLiteral;
482 using FunctionOptionsMap = std::map<UnicodeString, message2::Formattable>;
507 const ResolvedFunctionOption* resolvedOptions = getResolvedFunctionOptions(len);
508 FunctionOptionsMap result;
509 for (int32_t i = 0; i < len; i++) {
510 const ResolvedFunctionOption& opt = resolvedOptions[i];
511 result[opt.getName()] = opt.getValue();
554 friend class InternalValue;
556 friend class StandardFunctions;
560 const ResolvedFunctionOption* getResolvedFunctionOptions(int32_t& len) const;
564 UnicodeString getStringFunctionOption(std::u16string_view) const;
565 int32_t optionsCount()
const {
return functionOptionsLen; }
571 ResolvedFunctionOption* options;
572 int32_t functionOptionsLen = 0;
716 : fallback(input.fallback), source(input.source),
717 formatted(std::move(output)), previousOptions(
FunctionOptions()), type(kEvaluated) {}
731 : fallback(input.fallback), source(input.source),
732 formatted(std::move(output)), previousOptions(std::move(opts)), type(kEvaluated) {}
743 : fallback(fb), source(input), type(kUnevaluated) {}
C++ API: Character Iterator.
Base class for objects to which Unicode characters and strings can be appended.
Abstract class that defines an API for iteration on text objects.
Represents a span of a string containing a given field.
A Locale object represents a specific geographical, political, or cultural region.
A string-like object that points to a sized piece of memory.
UObject is the common ICU "boilerplate" class.
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Structure encapsulating named options passed to a custom selector or formatter.
FunctionOptions()
Default constructor.
virtual ~FunctionOptions()
Destructor.
FunctionOptions & operator=(FunctionOptions &&) noexcept
Move assignment operator: The source FunctionOptions will be left in a valid but undefined state.
FunctionOptionsMap getOptions() const
Returns a map of all name-value pairs provided as options to this function.
C++ API: Format and parse dates in a language-independent manner.
The DateInfo struct represents all the information needed to format a date with a time zone.
UnicodeString zoneId
IANA time zone name; "UTC" if UTC; empty string if value is floating The time zone is required in ord...
int8_t UBool
The ICU boolean type, a signed-byte integer.
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
@ U_ILLEGAL_ARGUMENT_ERROR
Start of codes indicating failure.
@ U_UNSUPPORTED_ERROR
Requested operation not supported in current context.
#define U_SUCCESS(x)
Does the error code indicate success?
#define U_I18N_API_CLASS
Set to export library symbols from inside the i18n library, and to import them from outside,...
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside.
double UDate
Date and Time data type.