ICU 78.2 78.2
Loading...
Searching...
No Matches
messageformat2_arguments.h
Go to the documentation of this file.
1// © 2024 and later: Unicode, Inc. and others.
2// License & terms of use: http://www.unicode.org/copyright.html
3
4#include "unicode/utypes.h"
5
6#ifndef MESSAGEFORMAT2_ARGUMENTS_H
7#define MESSAGEFORMAT2_ARGUMENTS_H
8
9#if U_SHOW_CPLUSPLUS_API
10
11#if !UCONFIG_NO_NORMALIZATION
12
13#if !UCONFIG_NO_FORMATTING
14
15#if !UCONFIG_NO_MF2
16
21
22#include "unicode/messageformat2_data_model_names.h"
23#include "unicode/messageformat2_formattable.h"
24#include "unicode/unistr.h"
25
26#ifndef U_HIDE_DEPRECATED_API
27
28#include <map>
29
30U_NAMESPACE_BEGIN
31
32namespace message2 {
33
34 class MessageFormatter;
35
36 // Arguments
37 // ----------
38
48 public:
60 U_I18N_API MessageArguments(const std::map<UnicodeString, Formattable>& args, UErrorCode& status) {
61 if (U_FAILURE(status)) {
62 return;
63 }
64 argumentNames = LocalArray<UnicodeString>(new UnicodeString[argsLen = static_cast<int32_t>(args.size())]);
65 arguments = LocalArray<Formattable>(new Formattable[argsLen]);
66 if (!argumentNames.isValid() || !arguments.isValid()) {
68 return;
69 }
70 int32_t i = 0;
71 for (auto iter = args.begin(); iter != args.end(); ++iter) {
72 argumentNames[i] = iter->first;
73 arguments[i] = iter->second;
74 i++;
75 }
76 }
77
100 private:
101 friend class MessageContext;
102
103 const Formattable* getArgument(const data_model::VariableName&,
104 UErrorCode&) const;
105
106 // Avoids using Hashtable so that code constructing a Hashtable
107 // doesn't have to appear in this header file
108 LocalArray<UnicodeString> argumentNames;
109 LocalArray<Formattable> arguments;
110 int32_t argsLen = 0;
111 }; // class MessageArguments
112
113} // namespace message2
114
115U_NAMESPACE_END
116
117#endif // U_HIDE_DEPRECATED_API
118
119#endif /* #if !UCONFIG_NO_MF2 */
120
121#endif /* #if !UCONFIG_NO_FORMATTING */
122
123#endif /* #if !UCONFIG_NO_NORMALIZATION */
124
125#endif /* U_SHOW_CPLUSPLUS_API */
126
127#endif // MESSAGEFORMAT2_ARGUMENTS_H
128
129// eof
"Smart pointer" class, deletes objects via the C++ array delete[] operator.
UObject is the common ICU "boilerplate" class.
Definition uobject.h:222
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition unistr.h:303
The Formattable class represents a typed value that can be formatted, originating either from a messa...
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...
U_I18N_API MessageArguments & operator=(MessageArguments &&) noexcept
Move operator: The source MessageArguments will be left in a valid but undefined state.
C++ API: Unicode String.
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition utypes.h:509
@ U_MEMORY_ALLOCATION_ERROR
Memory allocation error.
Definition utypes.h:552
#define U_FAILURE(x)
Does the error code indicate a failure?
Definition utypes.h:827
#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
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside.
Definition utypes.h:316