Loading...
Searching...
No Matches
messageformat2_arguments.h
Go to the documentation of this file.
// © 2024 and later: Unicode, Inc. and others.
// License & terms of use: http://www.unicode.org/copyright.html
#include "unicode/utypes.h"
#ifndef MESSAGEFORMAT2_ARGUMENTS_H
#define MESSAGEFORMAT2_ARGUMENTS_H
#if U_SHOW_CPLUSPLUS_API
#if !UCONFIG_NO_NORMALIZATION
#if !UCONFIG_NO_FORMATTING
#if !UCONFIG_NO_MF2
#include "unicode/messageformat2_data_model_names.h"
#include "unicode/messageformat2_formattable.h"
#include "unicode/unistr.h"
#ifndef U_HIDE_DEPRECATED_API
#include <map>
U_NAMESPACE_BEGIN
namespace message2 {
class MessageFormatter;
// Arguments
// ----------
class U_I18N_API_CLASS MessageArguments : public UObject {
public:
U_I18N_API MessageArguments(const std::map<UnicodeString, Formattable>& args, UErrorCode& status) {
if (U_FAILURE(status)) {
return;
}
argumentNames = LocalArray<UnicodeString>(new UnicodeString[argsLen = static_cast<int32_t>(args.size())]);
arguments = LocalArray<Formattable>(new Formattable[argsLen]);
if (!argumentNames.isValid() || !arguments.isValid()) {
status = U_MEMORY_ALLOCATION_ERROR;
return;
}
int32_t i = 0;
for (auto iter = args.begin(); iter != args.end(); ++iter) {
argumentNames[i] = iter->first;
arguments[i] = iter->second;
i++;
}
}
U_I18N_API MessageArguments& operator=(MessageArguments&&) noexcept;
U_I18N_API MessageArguments() = default;
U_I18N_API virtual ~MessageArguments();
private:
friend class MessageContext;
const Formattable* getArgument(const data_model::VariableName&,
UErrorCode&) const;
// Avoids using Hashtable so that code constructing a Hashtable
// doesn't have to appear in this header file
LocalArray<UnicodeString> argumentNames;
LocalArray<Formattable> arguments;
int32_t argsLen = 0;
}; // class MessageArguments
} // namespace message2
U_NAMESPACE_END
#endif // U_HIDE_DEPRECATED_API
#endif /* #if !UCONFIG_NO_MF2 */
#endif /* #if !UCONFIG_NO_FORMATTING */
#endif /* #if !UCONFIG_NO_NORMALIZATION */
#endif /* U_SHOW_CPLUSPLUS_API */
#endif // MESSAGEFORMAT2_ARGUMENTS_H
// eof
icu::LocalArray
"Smart pointer" class, deletes objects via the C++ array delete[] operator.
Definition localpointer.h:364
icu::UObject
UObject is the common ICU "boilerplate" class.
Definition uobject.h:222
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition unistr.h:303
icu::message2::Formattable
The Formattable class represents a typed value that can be formatted, originating either from a messa...
Definition messageformat2_formattable.h:113
icu::message2::MessageArguments::MessageArguments
U_I18N_API MessageArguments(const std::map< UnicodeString, Formattable > &args, UErrorCode &status)
Message arguments constructor, which takes a map and returns a container of arguments that can be pas...
Definition messageformat2_arguments.h:60
icu::message2::MessageArguments::operator=
U_I18N_API MessageArguments & operator=(MessageArguments &&) noexcept
Move operator: The source MessageArguments will be left in a valid but undefined state.
unistr.h
C++ API: Unicode String.
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition utypes.h:509
U_MEMORY_ALLOCATION_ERROR
@ U_MEMORY_ALLOCATION_ERROR
Memory allocation error.
Definition utypes.h:552
U_FAILURE
#define U_FAILURE(x)
Does the error code indicate a failure?
Definition utypes.h:827
U_I18N_API_CLASS
#define U_I18N_API_CLASS
Set to export library symbols from inside the i18n library, and to import them from outside,...
Definition utypes.h:457
U_I18N_API
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside.
Definition utypes.h:316