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
132 return (std::get_if<icu::Formattable>(&contents))->getDouble();
134 if (std::holds_alternative<double>(contents)) {
135 return *(std::get_if<double>(&contents));
154 return std::get_if<icu::Formattable>(&contents)->getLong();
156 if (std::holds_alternative<int64_t>(contents)) {
157 return static_cast<int32_t
>(*(std::get_if<int64_t>(&contents)));
177 return std::get_if<icu::Formattable>(&contents)->getInt64();
179 if (std::holds_alternative<int64_t>(contents)) {
180 return *(std::get_if<int64_t>(&contents));
213 if (std::holds_alternative<UnicodeString>(contents)) {
214 return *std::get_if<UnicodeString>(&contents);
235 return std::get_if<DateInfo>(&contents);
278 auto result = std::get_if<const FormattableObject*>(&contents);
281 if (result !=
nullptr) {
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);
450 friend class FunctionOptions;
454 const FunctionValue* value;
458 bool thisWasMerged =
false;
461 U_I18N_API const UnicodeString& getName()
const {
return name; }
462 U_I18N_API const FunctionValue& getValue()
const {
return *value; }
463 U_I18N_API bool wasMerged()
const {
return thisWasMerged; }
464 U_I18N_API ResolvedFunctionOption(
const UnicodeString& n,
const FunctionValue& f,
bool b);
466 U_I18N_API ResolvedFunctionOption(ResolvedFunctionOption&&);
467 U_I18N_API ResolvedFunctionOption& operator=(ResolvedFunctionOption&& other) =
default;
468 U_I18N_API ResolvedFunctionOption& operator=(
const ResolvedFunctionOption& other) =
default;
469 U_I18N_API ResolvedFunctionOption(
const ResolvedFunctionOption&) =
default;
481using FunctionOptionsMap = std::map<UnicodeString, const message2::FunctionValue*>;
505 FunctionOptionsMap result;
506 for (int32_t i = 0; i < functionOptionsLen; i++) {
507 ResolvedFunctionOption& opt = options[i];
508 result[opt.getName()] = &opt.getValue();
549 if (f1.bogus || f2.bogus) {
550 f1.bogus = f2.bogus =
true;
553 swap(f1.options, f2.options);
554 swap(f1.functionOptionsLen, f2.functionOptionsLen);
571 friend class MessageFormatter;
572 friend class StandardFunctions;
576 const ResolvedFunctionOption* getResolvedFunctionOptions(int32_t& len)
const;
579 UnicodeString getStringFunctionOption(
const std::u16string_view)
const;
580 UBool wasSetFromLiteral(
const std::u16string_view)
const;
583 int32_t optionsCount()
const {
return functionOptionsLen; }
590 ResolvedFunctionOption* options;
591 int32_t functionOptionsLen = 0;
C++ API: Character Iterator.
Abstract class that defines an API for iteration on text objects.
Represents a span of a string containing a given field.
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...
FunctionOptions & operator=(FunctionOptions) noexcept
Assignment operator.
FunctionOptions()
Default constructor.
FunctionOptions mergeOptions(const FunctionOptions &other, UErrorCode &) const
Returns a new FunctionOptions object containing all the key-value pairs from this and other.
virtual ~FunctionOptions()
Destructor.
FunctionOptionsMap getOptions() const
Returns a map of all name-value pairs provided as options to this function.
FunctionOptions(const FunctionOptions &)
Copy constructor.
friend void swap(FunctionOptions &f1, FunctionOptions &f2) noexcept
Non-member swap function.
Type representing argument and return values for custom functions.
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.