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"
21 #ifndef U_HIDE_DEPRECATED_API
80 #if U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN
81 #if defined(U_REAL_MSVC) && defined(_MSVC_STL_VERSION)
82 template class U_I18N_API std::_Variant_storage_<
false,
88 std::pair<const icu::message2::Formattable *,int32_t>>;
90 typedef std::pair<const icu::message2::Formattable*, int32_t> P;
141 return (std::get_if<icu::Formattable>(&contents))->getDouble();
143 if (std::holds_alternative<double>(contents)) {
144 return *(std::get_if<double>(&contents));
162 if (isDecimal() && getType() ==
UFMT_LONG) {
163 return std::get_if<icu::Formattable>(&contents)->getLong();
165 if (std::holds_alternative<int64_t>(contents)) {
166 return static_cast<int32_t
>(*(std::get_if<int64_t>(&contents)));
186 return std::get_if<icu::Formattable>(&contents)->getInt64();
188 if (std::holds_alternative<int64_t>(contents)) {
189 return *(std::get_if<int64_t>(&contents));
222 if (std::holds_alternative<UnicodeString>(contents)) {
223 return *std::get_if<UnicodeString>(&contents);
242 return *std::get_if<double>(&contents);
285 return *std::get_if<const FormattableObject*>(&contents);
303 swap(f1.contents, f2.contents);
304 swap(f1.holdsDate, f2.holdsDate);
428 std::pair<const Formattable*, int32_t>> contents;
429 bool holdsDate =
false;
432 UBool isDecimal()
const {
433 return std::holds_alternative<icu::Formattable>(contents);
435 UBool isDate()
const {
436 return std::holds_alternative<double>(contents) && holdsDate;
454 class U_I18N_API ResolvedFunctionOption :
public UObject {
461 const UnicodeString& getName()
const {
return name; }
462 const Formattable& getValue()
const {
return value; }
463 ResolvedFunctionOption(
const UnicodeString& n,
const Formattable& f) : name(n), value(f) {}
464 ResolvedFunctionOption() {}
465 ResolvedFunctionOption(ResolvedFunctionOption&&);
466 ResolvedFunctionOption& operator=(ResolvedFunctionOption&& other) noexcept {
467 name = std::move(other.name);
468 value = std::move(other.value);
471 virtual ~ResolvedFunctionOption();
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 int32_t optionsCount()
const {
return functionOptionsLen; }
570 ResolvedFunctionOption* options;
571 int32_t functionOptionsLen = 0;
712 : fallback(input.fallback), source(input.source),
713 formatted(std::move(output)), previousOptions(
FunctionOptions()), type(kEvaluated) {}
727 : fallback(input.fallback), source(input.source),
728 formatted(std::move(output)), previousOptions(std::move(opts)), type(kEvaluated) {}
739 : fallback(fb), source(input), type(kUnevaluated) {}
796 bool canFormat()
const {
return !(isFallback() || isNullOperand()); }
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.
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
Set to export library symbols from inside the i18n library, and to import them from outside.
double UDate
Date and Time data type.