/** *ThemutableBuilderclassallowseachpartoftheMessageFormattertobeinitialized *separately;callingits`build()`methodyieldsanimmutableMessageFormatter. * *Notcopyableormovable.
*/ class U_I18N_API_CLASS Builder : public UObject { private: friendclass MessageFormatter;
// The pattern to be parsed to generate the formatted message
UnicodeString pattern; bool hasPattern = false; bool hasDataModel = false; // The data model to be used to generate the formatted message // Initialized either by `setDataModel()`, or by the parser // through a call to `setPattern()`
MFDataModel dataModel; // Normalized representation of the pattern; // ignored if `setPattern()` wasn't called
UnicodeString normalizedInput; // Errors (internal representation of parse errors) // Ignored if `setPattern()` wasn't called
StaticErrors* errors;
Locale locale; // Not owned const MFFunctionRegistry* customMFFunctionRegistry; // Error behavior; see comment in `MessageFormatter` class bool signalErrors = false;
MessageFormatter() = delete; // default constructor not implemented
// Do not define default assignment operator const MessageFormatter &operator=(const MessageFormatter &) = delete;
// Selection methods
// Takes a vector of FormattedPlaceholders void resolveSelectors(MessageContext&, const Environment& env, UErrorCode&, UVector&) const; // Takes a vector of vectors of strings (input) and a vector of PrioritizedVariants (output) void filterVariants(const UVector&, UVector&, UErrorCode&) const; // Takes a vector of vectors of strings (input) and a vector of PrioritizedVariants (input/output) void sortVariants(const UVector&, UVector&, UErrorCode&) const; // Takes a vector of strings (input) and a vector of strings (output) void matchSelectorKeys(const UVector&, MessageContext&, InternalValue* rv, UVector&, UErrorCode&) const; // Takes a vector of FormattedPlaceholders (input), // and a vector of vectors of strings (output) void resolvePreferences(MessageContext&, UVector&, UVector&, UErrorCode&) const;
// Formatting methods
[[nodiscard]] FormattedPlaceholder formatLiteral(const UnicodeString&, const data_model::Literal&) const; void formatPattern(MessageContext&, const Environment&, const data_model::Pattern&, UErrorCode&, UnicodeString&) const; // Evaluates a function call // Dispatches on argument type
[[nodiscard]] InternalValue* evalFunctionCall(FormattedPlaceholder&& argument,
MessageContext& context,
UErrorCode& status) const; // Dispatches on function name
[[nodiscard]] InternalValue* evalFunctionCall(const FunctionName& functionName,
InternalValue* argument,
FunctionOptions&& options,
MessageContext& context,
UErrorCode& status) const; // Formats an expression that appears in a pattern or as the definition of a local variable
[[nodiscard]] InternalValue* formatExpression(const UnicodeString&, const Environment&, const data_model::Expression&,
MessageContext&,
UErrorCode&) const;
[[nodiscard]] FunctionOptions resolveOptions(const Environment& env, const OptionMap&, MessageContext&, UErrorCode&) const;
[[nodiscard]] InternalValue* formatOperand(const UnicodeString&, const Environment&, const data_model::Operand&,
MessageContext&,
UErrorCode&) const;
[[nodiscard]] FormattedPlaceholder evalArgument(const UnicodeString&, const data_model::VariableName&,
MessageContext&,
UErrorCode&) const; void formatSelectors(MessageContext& context, const Environment& env, UErrorCode &status, UnicodeString& result) const;
// Precondition: custom function registry exists // Note: this is non-const because the values in the MFFunctionRegistry are mutable // (a FormatterFactory can have mutable state) const MFFunctionRegistry& getCustomMFFunctionRegistry() const;
// The locale this MessageFormatter was created with /* const */ Locale locale;
// Registry for built-in functions
MFFunctionRegistry standardMFFunctionRegistry; // Registry for custom functions; may be null if no custom registry supplied // Note: this is *not* owned by the MessageFormatter object // The reason for this choice is to have a non-destructive MessageFormatter::Builder, // while also not requiring the function registry to be deeply-copyable. Making the // function registry copyable would impose a requirement on any implementations // of the FormatterFactory and SelectorFactory interfaces to implement a custom // clone() method, which is necessary to avoid sharing between copies of the // function registry (and thus double-frees) // Not deeply immutable (the values in the function registry are mutable, // as a FormatterFactory can have mutable state const MFFunctionRegistry* customMFFunctionRegistry;
// Data model, representing the parsed message
MFDataModel dataModel;
// Normalized version of the input string (optional whitespace removed)
UnicodeString normalizedInput;
// Errors -- only used while parsing and checking for data model errors; then // the MessageContext keeps track of errors // Must be a raw pointer to avoid including the internal header file // defining StaticErrors // Owned by `this`
StaticErrors* errors = nullptr;
// Error handling behavior. // If true, then formatting methods set their UErrorCode arguments // to signal MessageFormat errors, and no useful output is returned. // If false, then MessageFormat errors are not signaled and the // formatting methods return best-effort output. // The default is false. bool signalErrors = false;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.