6 #ifndef MESSAGEFORMAT2_FORMATTABLE_H 7 #define MESSAGEFORMAT2_FORMATTABLE_H 9 #if U_SHOW_CPLUSPLUS_API 11 #if !UCONFIG_NO_FORMATTING 17 #include "unicode/messageformat2_data_model_names.h" 19 #ifndef U_HIDE_DEPRECATED_API 78 #if U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN 79 #if defined(U_REAL_MSVC) && defined(_MSVC_STL_VERSION) 80 template class U_I18N_API std::_Variant_storage_<
false,
86 std::pair<const icu::message2::Formattable *,int32_t>>;
88 typedef std::pair<const icu::message2::Formattable*, int32_t> P;
139 return (std::get_if<icu::Formattable>(&contents))->getDouble();
141 if (std::holds_alternative<double>(contents)) {
142 return *(std::get_if<double>(&contents));
160 if (isDecimal() && getType() ==
UFMT_LONG) {
161 return std::get_if<icu::Formattable>(&contents)->getLong();
163 if (std::holds_alternative<int64_t>(contents)) {
164 return static_cast<int32_t
>(*(std::get_if<int64_t>(&contents)));
184 return std::get_if<icu::Formattable>(&contents)->getInt64();
186 if (std::holds_alternative<int64_t>(contents)) {
187 return *(std::get_if<int64_t>(&contents));
220 if (std::holds_alternative<UnicodeString>(contents)) {
221 return *std::get_if<UnicodeString>(&contents);
240 return *std::get_if<double>(&contents);
283 return *std::get_if<const FormattableObject*>(&contents);
301 swap(f1.contents, f2.contents);
302 swap(f1.holdsDate, f2.holdsDate);
426 std::pair<const Formattable*, int32_t>> contents;
427 bool holdsDate =
false;
430 UBool isDecimal()
const {
431 return std::holds_alternative<icu::Formattable>(contents);
433 UBool isDate()
const {
434 return std::holds_alternative<double>(contents) && holdsDate;
452 class U_I18N_API ResolvedFunctionOption :
public UObject {
459 const UnicodeString& getName()
const {
return name; }
460 const Formattable& getValue()
const {
return value; }
461 ResolvedFunctionOption(
const UnicodeString& n,
const Formattable& f) : name(n), value(f) {}
462 ResolvedFunctionOption() {}
463 ResolvedFunctionOption(ResolvedFunctionOption&&);
464 ResolvedFunctionOption& operator=(ResolvedFunctionOption&& other) noexcept {
465 name = std::move(other.name);
466 value = std::move(other.value);
469 virtual ~ResolvedFunctionOption();
480 using FunctionOptionsMap = std::map<UnicodeString, message2::Formattable>;
505 const ResolvedFunctionOption* resolvedOptions = getResolvedFunctionOptions(len);
506 FunctionOptionsMap result;
507 for (int32_t i = 0; i < len; i++) {
508 const ResolvedFunctionOption& opt = resolvedOptions[i];
509 result[opt.getName()] = opt.getValue();
553 friend class StandardFunctions;
557 const ResolvedFunctionOption* getResolvedFunctionOptions(int32_t& len) const;
561 int32_t optionsCount()
const {
return functionOptionsLen; }
567 ResolvedFunctionOption* options;
568 int32_t functionOptionsLen = 0;
711 : fallback(input.fallback), source(input.source),
712 formatted(std::move(output)), previousOptions(
FunctionOptions()), type(kEvaluated) {}
726 : fallback(input.fallback), source(input.source),
727 formatted(std::move(output)), previousOptions(std::move(opts)), type(kEvaluated) {}
738 : fallback(fb), source(input), type(kUnevaluated) {}
795 bool canFormat()
const {
return !(isFallback() || isNullOperand()); }
867 FunctionOptions previousOptions;
1007 #endif // U_HIDE_DEPRECATED_API 1015 #endif // MESSAGEFORMAT2_FORMATTABLE_H
#define U_SUCCESS(x)
Does the error code indicate success?
double UDate
Date and Time data type.
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside...
Requested operation not supported in current context.
Abstract class that defines an API for iteration on text objects.
Start of codes indicating failure.
Represents a span of a string containing a given field.
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
FunctionOptionsMap getOptions() const
Returns a map of all name-value pairs provided as options to this function.
Structure encapsulating named options passed to a custom selector or formatter.
Basic definitions for ICU, for both C and C++ APIs.
FunctionOptions()
Default constructor.
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
C++ API: Character Iterator.
A string-like object that points to a sized piece of memory.
UObject is the common ICU "boilerplate" class.
int8_t UBool
The ICU boolean type, a signed-byte integer.
Base class for objects to which Unicode characters and strings can be appended.
A Locale object represents a specific geographical, political, or cultural region.