6 #ifndef MESSAGEFORMAT_DATA_MODEL_H 7 #define MESSAGEFORMAT_DATA_MODEL_H 9 #if U_SHOW_CPLUSPLUS_API 11 #if !UCONFIG_NO_NORMALIZATION 13 #if !UCONFIG_NO_FORMATTING 18 #include "unicode/messageformat2_data_model_names.h" 20 #ifndef U_HIDE_DEPRECATED_API 39 static inline std::vector<T> toStdVector(
const T* arr, int32_t len) {
40 std::vector<T> result;
41 for (int32_t i = 0; i < len; i++) {
42 result.push_back(arr[i]);
47 #if defined(U_REAL_MSVC) 51 #pragma warning(disable: 4251) 56 class MessageFormatter;
61 namespace data_model {
126 Literal(
const Literal& other) : thisIsQuoted(other.thisIsQuoted), contents(other.contents) {}
138 swap(l1.thisIsQuoted, l2.thisIsQuoted);
139 swap(l1.contents, l2.contents);
171 bool operator<(
const Literal& other)
const;
197 bool thisIsQuoted =
false;
304 swap(o1.contents, o2.contents);
328 std::optional<std::variant<VariableName, Literal>> contents;
403 swap(k1.contents, k2.contents);
448 std::optional<Literal> contents;
474 return toStdVector<Key>(keys.getAlias(), len);
572 swap(s1.len, s2.len);
573 swap(s1.keys, s2.keys);
597 friend class Builder;
598 friend class message2::Checker;
600 friend class message2::Serializer;
605 const Key* getKeysInternal()
const;
669 swap(o1.name, o2.name);
670 swap(o1.rand, o2.rand);
707 U_I18N_API friend inline void swap(OptionMap& m1, OptionMap& m2) noexcept {
710 swap(m1.bogus, m2.bogus);
711 swap(m1.options, m2.options);
712 swap(m1.len, m2.len);
717 U_I18N_API std::vector<Option> getOptions()
const {
718 return toStdVector<Option>(options.getAlias(), len);
727 bool checkDuplicates =
true;
734 friend inline void swap(Builder& m1, Builder& m2) noexcept {
737 swap(m1.options, m2.options);
738 swap(m1.checkDuplicates, m2.checkDuplicates);
741 Builder(
const Builder&) =
delete;
742 Builder& operator=(Builder) noexcept;
746 friend class message2::Serializer;
749 LocalArray<Option> options;
787 return options.getOptions();
802 OptionMap::Builder options;
884 swap(o1.name, o2.name);
885 swap(o1.options, o2.options);
911 friend class Builder;
912 friend class message2::Checker;
914 friend class message2::Serializer;
919 const OptionMap& getOptionsInternal()
const;
927 typedef enum UMarkupType {
990 std::vector<Option>
getOptions()
const {
return options.getOptions(); }
999 std::vector<Option>
getAttributes()
const {
return attributes.getOptions(); }
1029 OptionMap::Builder options;
1030 OptionMap::Builder attributes;
1031 UMarkupType type = UMARKUP_COUNT;
1136 friend class Builder;
1137 friend class message2::Serializer;
1142 OptionMap attributes;
1143 const OptionMap& getOptionsInternal()
const {
return options; }
1144 const OptionMap& getAttributesInternal()
const {
return attributes; }
1145 Markup(UMarkupType,
UnicodeString, OptionMap&&, OptionMap&&);
1231 bool hasOperand =
false;
1232 bool hasOperator =
false;
1235 OptionMap::Builder attributes;
1320 swap(e1.rator, e2.rator);
1321 swap(e1.rand, e2.rand);
1322 swap(e1.attributes, e2.attributes);
1354 friend class message2::Serializer;
1370 Expression(
const Operator &rAtor,
const Operand &rAnd,
const OptionMap& attrs) : rator(rAtor), rand(rAnd), attributes(attrs) {}
1371 Expression(
const Operand &rAnd,
const OptionMap& attrs) : rator(std::nullopt), rand(
Operand(rAnd)), attributes(attrs) {}
1372 Expression(
const Operator &rAtor,
const OptionMap& attrs) : rator(rAtor), rand(), attributes(attrs) {}
1373 std::optional<Operator> rator;
1375 OptionMap attributes;
1376 const OptionMap& getAttributesInternal()
const {
return attributes; }
1462 swap(p1.piece, p2.piece);
1526 std::variant<UnicodeString, Expression, Markup> piece;
1544 #ifndef U_IN_DOXYGEN 1675 swap(p1.bogus, p2.bogus);
1676 swap(p1.len, p2.len);
1677 swap(p1.parts, p2.parts);
1712 using iterator_category = std::forward_iterator_tag;
1713 using difference_type = std::ptrdiff_t;
1714 using value_type = std::variant<UnicodeString, Expression, Markup>;
1715 using pointer = value_type*;
1716 using reference =
const value_type&;
1734 return patternContents(part);
1753 friend class Builder;
1755 friend class message2::Serializer;
1778 int32_t numParts()
const;
1793 static const std::variant<UnicodeString, Expression, Markup>&
1794 patternContents(
const PatternPart& p) {
return p.piece; }
1963 swap(b1.var, b2.var);
1964 swap(b1.expr, b2.expr);
1965 swap(b1.local, b2.local);
1966 b1.updateAnnotation();
1967 b2.updateAnnotation();
1999 friend class message2::Checker;
2001 friend class message2::Parser;
2002 friend class message2::Serializer;
2013 const Operator* annotation =
nullptr;
2015 const OptionMap& getOptionsInternal()
const;
2017 bool hasAnnotation()
const {
return !local && (annotation !=
nullptr); }
2018 void updateAnnotation();
2023 #ifndef U_IN_DOXYGEN 2036 U_I18N_API friend inline void swap(Matcher& m1, Matcher& m2) noexcept {
2047 swap(m1.selectors, m2.selectors);
2048 swap(m1.numSelectors, m2.numSelectors);
2049 swap(m1.variants, m2.variants);
2050 swap(m1.numVariants, m2.numVariants);
2055 friend class MFDataModel;
2057 Matcher(VariableName* ss, int32_t ns, Variant* vs, int32_t nv);
2066 LocalArray<VariableName> selectors;
2068 int32_t numSelectors = 0;
2070 LocalArray<Variant> variants;
2072 int32_t numVariants = 0;
2140 std::vector<Binding> result;
2142 return toStdVector<Binding>(bindings.getAlias(), bindingsLen);
2155 if (std::holds_alternative<Pattern>(body)) {
2158 const Matcher* match = std::get_if<Matcher>(&body);
2160 return toStdVector<VariableName>(match->selectors.getAlias(), match->numSelectors);
2172 if (std::holds_alternative<Pattern>(body)) {
2175 const Matcher* match = std::get_if<Matcher>(&body);
2177 return toStdVector<Variant>(match->variants.getAlias(), match->numVariants);
2225 swap(m1.body, m2.body);
2226 swap(m1.bindings, m2.bindings);
2227 swap(m1.bindingsLen, m2.bindingsLen);
2264 bool hasPattern =
true;
2265 bool hasSelectors =
false;
2268 UVector* selectors =
nullptr;
2269 UVector* variants =
nullptr;
2270 UVector* bindings =
nullptr;
2369 friend class message2::Checker;
2371 friend class message2::Serializer;
2375 bool hasPattern()
const {
return std::holds_alternative<Pattern>(body); }
2381 std::variant<Matcher, Pattern> body;
2385 int32_t bindingsLen = 0;
2387 const Binding* getLocalVariablesInternal()
const;
2389 const Variant* getVariantsInternal()
const;
2391 int32_t numSelectors()
const {
2392 const Matcher* matcher = std::get_if<Matcher>(&body);
2393 return (matcher ==
nullptr ? 0 : matcher->numSelectors);
2395 int32_t numVariants()
const {
2396 const Matcher* matcher = std::get_if<Matcher>(&body);
2397 return (matcher ==
nullptr ? 0 : matcher->numVariants);
2401 void initBindings(
const Binding*);
2403 MFDataModel(
const Builder& builder,
UErrorCode&) noexcept;
2410 #endif // U_HIDE_DEPRECATED_API 2420 #endif // MESSAGEFORMAT_DATA_MODEL_H const SelectorKeys & getKeys() const
Accesses the keys of the variant.
The mutable Markup::Builder class allows the markup to be constructed incrementally.
A Variant pairs a list of keys with a pattern It corresponds to the Variant interface defined in http...
U_I18N_API UBool isWildcard() const
Determines if this is a wildcard key.
U_I18N_API std::vector< VariableName > getSelectors() const
Accesses the selectors.
std::vector< Option > getAttributes() const
Gets the attributes of this markup.
A PatternPart is a single element (text or expression) in a Pattern.
U_I18N_API UBool isExpression() const
Checks if the part is an expression part.
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.
U_I18N_API Operand(const Literal &l)
Literal operand constructor.
Variant(const SelectorKeys &keys, Pattern &&pattern)
Constructor.
U_COMMON_API UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
U_I18N_API Iterator end() const
Returns a special value to mark the end of iteration.
Builder & setName(const UnicodeString &n)
Sets the name of this markup.
Literal(const Literal &other)
Copy constructor.
U_I18N_API PatternPart(Markup &&m)
Markup part constructor.
U_I18N_API std::vector< Key > getKeys() const
Returns the underlying list of keys.
Binding()
Default constructor.
friend void swap(Operator &o1, Operator &o2) noexcept
Non-member swap function.
Literal(UBool q, const UnicodeString &s)
Literal constructor.
U_I18N_API UBool isText() const
Checks if the part is a text part.
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.
U_I18N_API friend void swap(PatternPart &p1, PatternPart &p2) noexcept
Non-member swap function.
UBool isStandalone() const
Checks if this markup is an standalone tag.
U_I18N_API SelectorKeys()
Default constructor.
U_I18N_API friend void swap(Pattern &p1, Pattern &p2) noexcept
Non-member swap function.
UBool isQuoted() const
Determines if this literal appeared as a quoted literal in the message.
U_I18N_API friend void swap(Expression &e1, Expression &e2) noexcept
Non-member swap function.
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)
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside...
U_I18N_API friend void swap(MFDataModel &m1, MFDataModel &m2) noexcept
Non-member swap function.
#define U_I18N_API_CLASS
Set to export library symbols from inside the i18n library, and to import them from outside...
U_I18N_API Key(const Key &other)
Copy constructor.
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.
U_I18N_API std::vector< Option > getAttributes() const
Gets the attributes of this expression.
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 ...
The mutable MFDataModel::Builder class allows the data model to be constructed incrementally.
C++ API: "Smart pointers" for use with and in ICU4C C++ code.
U_I18N_API Operand(const UnicodeString &v)
Variable operand constructor.
friend void swap(Option &o1, Option &o2) noexcept
Non-member swap function.
friend void swap(Binding &b1, Binding &b2) noexcept
Non-member swap function.
U_I18N_API std::vector< Variant > getVariants() const
Accesses the variants.
"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)
The Operator class corresponds to the FunctionRef type in the Expression interface defined in https:/...
U_I18N_API UBool isMarkup() const
Checks if the part is a markup part.
U_I18N_API Iterator begin() const
Returns the parts of this pattern.
U_I18N_API Operand()
Default constructor.
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 .
The MFDataModel class describes a parsed representation of the text of a message. ...
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.
Basic definitions for ICU, for both C and C++ APIs.
U_I18N_API std::vector< Binding > getLocalVariables() const
Accesses the local variable declarations for this data model.
U_I18N_API Pattern()
Default constructor.
U_I18N_API Key(const Literal &lit)
Literal key constructor.
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...
U_I18N_API friend void swap(Operand &o1, Operand &o2) noexcept
Non-member swap function.
U_I18N_API PatternPart(const UnicodeString &t)
Text part constructor.
U_I18N_API PatternPart(Expression &&e)
Expression part constructor.
U_I18N_API Key()
Wildcard constructor; constructs a Key representing the catchall or wildcard key, '*'...
The SelectorKeys class represents the key list for a single variant.
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.
U_I18N_API friend void swap(Key &k1, Key &k2) noexcept
Non-member swap function.
int8_t UBool
The ICU boolean type, a signed-byte integer.
UBool isClose() const
Checks if this markup is an closing tag.
const Operand & getValue() const
Accesses the right-hand side of the option.
U_I18N_API friend void swap(SelectorKeys &s1, SelectorKeys &s2) noexcept
Non-member swap function.
The mutable Operator::Builder class allows the operator to be constructed incrementally.