6 #ifndef MESSAGEFORMAT_DATA_MODEL_H 7 #define MESSAGEFORMAT_DATA_MODEL_H 9 #if U_SHOW_CPLUSPLUS_API 11 #if !UCONFIG_NO_FORMATTING 16 #include "unicode/messageformat2_data_model_names.h" 18 #ifndef U_HIDE_DEPRECATED_API 37 static inline std::vector<T> toStdVector(
const T* arr, int32_t len) {
38 std::vector<T> result;
39 for (int32_t i = 0; i < len; i++) {
40 result.push_back(arr[i]);
45 #if defined(U_REAL_MSVC) 49 #pragma warning(disable: 4251) 55 class MessageFormatter;
60 namespace data_model {
124 Literal(
const Literal& other) : thisIsQuoted(other.thisIsQuoted), contents(other.contents) {}
136 swap(l1.thisIsQuoted, l2.thisIsQuoted);
137 swap(l1.contents, l2.contents);
169 bool operator<(
const Literal& other)
const;
195 bool thisIsQuoted =
false;
207 #if U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN 208 template class U_I18N_API LocalPointerBase<message2::data_model::Literal>;
209 template class U_I18N_API LocalArray<message2::data_model::Literal>;
211 #if defined(U_REAL_MSVC) 224 #if U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN 225 #if defined(U_REAL_MSVC) && defined(_MSVC_STL_VERSION) 226 struct U_I18N_API std::_Nontrivial_dummy_type;
227 template class U_I18N_API std::_Variant_storage_<false, icu::UnicodeString, icu::message2::data_model::Literal>;
229 template class U_I18N_API std::variant<icu::UnicodeString, icu::message2::data_model::Literal>;
230 template class U_I18N_API std::optional<std::variant<icu::UnicodeString, icu::message2::data_model::Literal>>;
231 template class U_I18N_API std::optional<icu::message2::data_model::Literal>;
238 namespace data_model {
264 UBool isVariable()
const;
273 UBool isLiteral()
const;
282 virtual UBool isNull()
const;
302 const Literal& asLiteral()
const;
343 swap(o1.contents, o2.contents);
367 std::optional<std::variant<VariableName, Literal>> contents;
405 const Literal& asLiteral()
const;
412 Key(
const Key& other) : contents(other.contents) {}
420 Key() : contents(std::nullopt) {}
442 swap(k1.contents, k2.contents);
450 Key& operator=(
Key) noexcept;
464 bool operator<(
const Key& other)
const;
487 std::optional<Literal> contents;
498 #if U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN 499 template class U_I18N_API LocalPointerBase<message2::data_model::Key>;
500 template class U_I18N_API LocalArray<message2::data_model::Key>;
505 namespace data_model {
529 return toStdVector<Key>(keys.getAlias(), len);
627 swap(s1.len, s2.len);
628 swap(s1.keys, s2.keys);
652 friend class Builder;
653 friend class message2::Checker;
655 friend class message2::Serializer;
660 const Key* getKeysInternal()
const;
668 namespace data_model {
729 swap(o1.name, o2.name);
730 swap(o1.rand, o2.rand);
766 #if U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN 767 template class U_I18N_API LocalPointerBase<message2::data_model::Option>;
768 template class U_I18N_API LocalArray<message2::data_model::Option>;
773 namespace data_model {
780 int32_t size()
const;
782 const Option& getOption(int32_t,
UErrorCode&)
const;
783 friend inline void swap(OptionMap& m1, OptionMap& m2) noexcept {
786 swap(m1.bogus, m2.bogus);
787 swap(m1.options, m2.options);
788 swap(m1.len, m2.len);
790 OptionMap() : len(0) {}
791 OptionMap(
const OptionMap&);
792 OptionMap& operator=(OptionMap);
793 std::vector<Option> getOptions()
const {
794 return toStdVector<Option>(options.getAlias(), len);
797 OptionMap(Option*, int32_t);
798 virtual ~OptionMap();
803 bool checkDuplicates =
true;
810 friend inline void swap(Builder& m1, Builder& m2) noexcept {
813 swap(m1.options, m2.options);
814 swap(m1.checkDuplicates, m2.checkDuplicates);
817 Builder(
const Builder&) =
delete;
818 Builder& operator=(Builder) noexcept;
822 friend class message2::Serializer;
825 LocalArray<Option> options;
838 namespace data_model {
872 return options.getOptions();
887 OptionMap::Builder options;
969 swap(o1.name, o2.name);
970 swap(o1.options, o2.options);
996 friend class Builder;
997 friend class message2::Checker;
999 friend class message2::Serializer;
1004 const OptionMap& getOptionsInternal()
const;
1021 #if U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN 1022 template class U_I18N_API std::optional<icu::message2::data_model::Operator>;
1028 namespace message2 {
1029 namespace data_model {
1031 typedef enum UMarkupType {
1094 std::vector<Option>
getOptions()
const {
return options.getOptions(); }
1133 OptionMap::Builder options;
1134 OptionMap::Builder attributes;
1135 UMarkupType type = UMARKUP_COUNT;
1240 friend class Builder;
1241 friend class message2::Serializer;
1246 OptionMap attributes;
1247 const OptionMap& getOptionsInternal()
const {
return options; }
1248 const OptionMap& getAttributesInternal()
const {
return attributes; }
1249 Markup(UMarkupType,
UnicodeString, OptionMap&&, OptionMap&&);
1277 UBool isStandaloneAnnotation()
const;
1288 UBool isFunctionCall()
const;
1312 const Operand& getOperand()
const;
1335 bool hasOperand =
false;
1336 bool hasOperator =
false;
1339 OptionMap::Builder attributes;
1424 swap(e1.rator, e2.rator);
1425 swap(e1.rand, e2.rand);
1426 swap(e1.attributes, e2.attributes);
1458 friend class message2::Serializer;
1474 Expression(
const Operator &rAtor,
const Operand &rAnd,
const OptionMap& attrs) : rator(rAtor), rand(rAnd), attributes(attrs) {}
1475 Expression(
const Operand &rAnd,
const OptionMap& attrs) : rator(std::nullopt), rand(
Operand(rAnd)), attributes(attrs) {}
1476 Expression(
const Operator &rAtor,
const OptionMap& attrs) : rator(rAtor), rand(), attributes(attrs) {}
1477 std::optional<Operator> rator;
1479 OptionMap attributes;
1480 const OptionMap& getAttributesInternal()
const {
return attributes; }
1491 #if U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN 1492 template class U_I18N_API LocalPointerBase<message2::data_model::Expression>;
1493 template class U_I18N_API LocalArray<message2::data_model::Expression>;
1497 namespace message2 {
1498 namespace data_model {
1523 UBool isText()
const {
return std::holds_alternative<UnicodeString>(piece); }
1561 const Markup& asMarkup()
const;
1583 swap(p1.piece, p2.piece);
1647 std::variant<UnicodeString, Expression, Markup> piece;
1658 #if U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN 1659 template class U_I18N_API LocalPointerBase<message2::data_model::PatternPart>;
1660 template class U_I18N_API LocalArray<message2::data_model::PatternPart>;
1664 namespace message2 {
1665 namespace data_model {
1810 swap(p1.bogus, p2.bogus);
1811 swap(p1.len, p2.len);
1812 swap(p1.parts, p2.parts);
1847 using iterator_category = std::forward_iterator_tag;
1848 using difference_type = std::ptrdiff_t;
1849 using value_type = std::variant<UnicodeString, Expression, Markup>;
1850 using pointer = value_type*;
1851 using reference =
const value_type&;
1869 return patternContents(part);
1888 friend class Builder;
1890 friend class message2::Serializer;
1913 int32_t numParts()
const;
1928 static const std::variant<UnicodeString, Expression, Markup>&
1929 patternContents(
const PatternPart& p) {
return p.piece; }
2023 namespace data_model {
2098 swap(b1.var, b2.var);
2099 swap(b1.expr, b2.expr);
2100 swap(b1.local, b2.local);
2101 b1.updateAnnotation();
2102 b2.updateAnnotation();
2134 friend class message2::Checker;
2136 friend class message2::Parser;
2137 friend class message2::Serializer;
2148 const Operator* annotation =
nullptr;
2150 const OptionMap& getOptionsInternal()
const;
2152 bool hasAnnotation()
const {
return !local && (annotation !=
nullptr); }
2153 void updateAnnotation();
2164 #if U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN 2165 template class U_I18N_API LocalPointerBase<message2::data_model::Variant>;
2166 template class U_I18N_API LocalPointerBase<message2::data_model::Binding>;
2167 template class U_I18N_API LocalArray<message2::data_model::Variant>;
2168 template class U_I18N_API LocalArray<message2::data_model::Binding>;
2172 namespace message2 {
2173 using namespace data_model;
2180 #ifndef U_IN_DOXYGEN 2181 class Matcher :
public UObject {
2183 Matcher& operator=(Matcher);
2184 Matcher(
const Matcher&);
2193 friend inline void swap(Matcher& m1, Matcher& m2) noexcept {
2204 swap(m1.selectors, m2.selectors);
2205 swap(m1.numSelectors, m2.numSelectors);
2206 swap(m1.variants, m2.variants);
2207 swap(m1.numVariants, m2.numVariants);
2212 friend class MFDataModel;
2214 Matcher(Expression* ss, int32_t ns, Variant* vs, int32_t nv);
2223 LocalArray<Expression> selectors;
2225 int32_t numSelectors = 0;
2227 LocalArray<Variant> variants;
2229 int32_t numVariants = 0;
2242 #if U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN 2243 #if defined(U_REAL_MSVC) && defined(_MSVC_STL_VERSION) 2244 template class U_I18N_API std::_Variant_storage_<false, icu::message2::Matcher,icu::message2::data_model::Pattern>;
2246 template class U_I18N_API std::variant<icu::message2::Matcher,icu::message2::data_model::Pattern>;
2252 namespace message2 {
2317 std::vector<Binding> result;
2319 return toStdVector<Binding>(bindings.getAlias(), bindingsLen);
2332 if (std::holds_alternative<Pattern>(body)) {
2335 const Matcher* match = std::get_if<Matcher>(&body);
2337 return toStdVector<Expression>(match->selectors.getAlias(), match->numSelectors);
2349 if (std::holds_alternative<Pattern>(body)) {
2352 const Matcher* match = std::get_if<Matcher>(&body);
2354 return toStdVector<Variant>(match->variants.getAlias(), match->numVariants);
2366 const Pattern& getPattern()
const;
2404 swap(m1.body, m2.body);
2405 swap(m1.bindings, m2.bindings);
2406 swap(m1.bindingsLen, m2.bindingsLen);
2443 bool hasPattern =
true;
2444 bool hasSelectors =
false;
2447 UVector* selectors =
nullptr;
2448 UVector* variants =
nullptr;
2449 UVector* bindings =
nullptr;
2548 friend class Checker;
2550 friend class Serializer;
2554 bool hasPattern()
const {
return std::holds_alternative<Pattern>(body); }
2560 std::variant<Matcher, Pattern> body;
2564 int32_t bindingsLen = 0;
2566 const Binding* getLocalVariablesInternal()
const;
2567 const Expression* getSelectorsInternal()
const;
2568 const Variant* getVariantsInternal()
const;
2570 int32_t numSelectors()
const {
2571 const Matcher* matcher = std::get_if<Matcher>(&body);
2572 return (matcher ==
nullptr ? 0 : matcher->numSelectors);
2574 int32_t numVariants()
const {
2575 const Matcher* matcher = std::get_if<Matcher>(&body);
2576 return (matcher ==
nullptr ? 0 : matcher->numVariants);
2580 void initBindings(
const Binding*);
2582 MFDataModel(
const Builder& builder,
UErrorCode&) noexcept;
2589 #endif // U_HIDE_DEPRECATED_API 2597 #endif // MESSAGEFORMAT_DATA_MODEL_H const SelectorKeys & getKeys() const
Accesses the keys of the variant.
friend void swap(SelectorKeys &s1, SelectorKeys &s2) noexcept
Non-member swap function.
The mutable Markup::Builder class allows the markup to be constructed incrementally.
std::vector< Option > getAttributes() const
Gets the attributes of this expression.
A Variant pairs a list of keys with a pattern It corresponds to the Variant interface defined in http...
std::vector< Option > getAttributes() const
Gets the attributes of this markup.
A PatternPart is a single element (text or expression) in a Pattern.
friend void swap(Variant &v1, Variant &v2) noexcept
Non-member swap function.
bool operator!=(const StringPiece &x, const StringPiece &y)
Global operator != for StringPiece.
Builder & setClose()
Sets this to be an closing markup.
Variant(const SelectorKeys &keys, Pattern &&pattern)
Constructor.
UBool isText() const
Checks if the part is a text part.
Builder & setName(const UnicodeString &n)
Sets the name of this markup.
Literal(const Literal &other)
Copy constructor.
Binding()
Default constructor.
std::vector< Variant > getVariants() const
Accesses the variants.
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
friend void swap(Operator &o1, Operator &o2) noexcept
Non-member swap function.
Literal(UBool q, const UnicodeString &s)
Literal constructor.
Iterator end() const
Returns a special value to mark the end of iteration.
const UnicodeString & getName() const
Accesses the left-hand side of the option.
Option()
Default constructor.
friend void swap(Literal &l1, Literal &l2) noexcept
Non-member swap function.
Operator()
Default constructor.
std::vector< Key > getKeys() const
Returns the underlying list of keys.
SelectorKeys()
Default constructor.
UBool isStandalone() const
Checks if this markup is an standalone tag.
Iterator begin() const
Returns the parts of this pattern.
UBool isQuoted() const
Determines if this literal appeared as a quoted literal in the message.
Option(const UnicodeString &n, Operand &&r)
Constructor.
Markup()
Default constructor.
The Literal class corresponds to the literal nonterminal in the MessageFormat 2 grammar, https://github.com/unicode-org/message-format-wg/blob/main/spec/message.abnf and the Literal interface defined in // https://github.com/unicode-org/message-format-wg/blob/main/spec/data-model.md#expressions.
An Option pairs an option name with an Operand.
The mutable Pattern::Builder class allows the pattern to be constructed one part at a time...
Iterator operator++()
Increment operator (advances to the next iterator position)
Key(const Literal &lit)
Literal key constructor.
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside...
Operand(const Literal &l)
Literal operand constructor.
const std::vector< Expression > getSelectors() const
Accesses the selectors.
The mutable SelectorKeys::Builder class allows the key list to be constructed one key at a time...
The Pattern::Iterator class provides an iterator over the formattable parts of a pattern.
Operand()
Default constructor.
friend void swap(Expression &e1, Expression &e2) noexcept
Non-member swap function.
The mutable Expression::Builder class allows the operator to be constructed incrementally.
The Markup class corresponds to the markup nonterminal in the MessageFormat 2 grammar and the markup ...
Key(const Key &other)
Copy constructor.
C++ API: "Smart pointers" for use with and in ICU4C C++ code.
The MFDataModel class describes a parsed representation of the text of a message. ...
friend void swap(Option &o1, Option &o2) noexcept
Non-member swap function.
friend void swap(Binding &b1, Binding &b2) noexcept
Non-member swap function.
"Smart pointer" class, deletes objects via the C++ array delete[] operator.
std::vector< Option > getOptions() const
Gets the options of this markup.
reference operator*() const
Dereference operator (gets the element at the current iterator position)
UBool isExpression() const
Checks if the part is an expression part.
The Operator class corresponds to the FunctionRef type in the Expression interface defined in https:/...
friend void swap(Key &k1, Key &k2) noexcept
Non-member swap function.
friend void swap(MFDataModel &m1, MFDataModel &m2) noexcept
Non-member swap function.
PatternPart(Expression &&e)
Expression part constructor.
The mutable MFDataModel::Builder class allows the data model to be constructed incrementally.
PatternPart(const UnicodeString &t)
Text part constructor.
Pattern()
Default constructor.
PatternPart(Markup &&m)
Markup part constructor.
Key()
Wildcard constructor; constructs a Key representing the catchall or wildcard key, '*'...
The Operand class corresponds to the operand nonterminal in the MessageFormat 2 grammar, https://github.com/unicode-org/message-format-wg/blob/main/spec/message.abnf .
Builder & setOpen()
Sets this to be an opening markup.
The Expression class corresponds to the expression nonterminal in the MessageFormat 2 grammar and the...
Binding(const VariableName &v, Expression &&e)
Constructor.
A Binding pairs a variable name with an expression.
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
The Key class corresponds to the key nonterminal in the MessageFormat 2 grammar, https://github.com/unicode-org/message-format-wg/blob/main/spec/message.abnf .
UBool isMarkup() const
Checks if the part is a markup part.
UBool isOpen() const
Checks if this markup is an opening tag.
UBool isLocal() const
Returns true if and only if this binding represents a local declaration.
Operand(const UnicodeString &v)
Variable operand constructor.
Basic definitions for ICU, for both C and C++ APIs.
UBool isWildcard() const
Determines if this is a wildcard key.
std::vector< Option > getOptions() const
Accesses function options.
A Pattern is a sequence of formattable parts.
const Pattern & getPattern() const
Accesses the pattern of the variant.
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
The SelectorKeys class represents the key list for a single variant.
friend void swap(PatternPart &p1, PatternPart &p2) noexcept
Non-member swap function.
const VariableName & getVariable() const
Accesses the left-hand side of the binding.
UObject is the common ICU "boilerplate" class.
const UnicodeString & getName() const
Gets the name of this markup.
UMemory is the common ICU base class.
Builder & setStandalone()
Sets this to be a standalone markup.
std::vector< Binding > getLocalVariables() const
Accesses the local variable declarations for this data model.
friend void swap(Operand &o1, Operand &o2) noexcept
Non-member swap function.
int8_t UBool
The ICU boolean type, a signed-byte integer.
friend void swap(Pattern &p1, Pattern &p2) noexcept
Non-member swap function.
UBool isClose() const
Checks if this markup is an closing tag.
const Operand & getValue() const
Accesses the right-hand side of the option.
The mutable Operator::Builder class allows the operator to be constructed incrementally.