ICU 75.1 75.1

Public Member Functions | Friends
icu::message2::MessageFormatter::Builder Class Reference

The mutable Builder class allows each part of the MessageFormatter to be initialized separately; calling its `build()` method yields an immutable MessageFormatter. More...

`#include <messageformat2.h>`

Inheritance diagram for icu::message2::MessageFormatter::Builder:

## Public Member Functions
Builder & | setLocale (const Locale &locale)
| Sets the locale to use for formatting. More...
Builder & | setPattern (const UnicodeString &pattern, UParseError &parseError, UErrorCode &status)
| Sets the pattern (contents of the message) and parses it into a data model. More...
Builder & | setFunctionRegistry (const MFFunctionRegistry &functionRegistry)
| Sets a custom function registry. More...
Builder & | setDataModel (MFDataModel &&dataModel)
| Sets a data model. More...
MessageFormatter | build (UErrorCode &status) const
| Constructs a new immutable MessageFormatter using the pattern or data model that was previously set, and the locale (if it was previously set) or default locale (otherwise). More...
| Builder (UErrorCode &status)
| Default constructor. More...
virtual | ~Builder ()
| Destructor. More...
Public Member Functions inherited from icu::UObject
virtual | ~UObject ()
| Destructor. More...
virtual UClassID | getDynamicClassID () const
| ICU4C "poor man's RTTI", returns a UClassID for the actual ICU class. More...

## Friends
class | MessageFormatter

## Detailed Description

The mutable Builder class allows each part of the MessageFormatter to be initialized separately; calling its `build()` method yields an immutable MessageFormatter.

Not copyable or movable.

Definition at line 148 of file messageformat2.h.

## Constructor & Destructor Documentation

## ◆ Builder()

icu::message2::MessageFormatter::Builder::Builder | ( | UErrorCode & | status | ) |

Default constructor.

Returns a Builder with the default locale and with no data model or pattern set. Either `setPattern()` or `setDataModel()` has to be called before calling `build()`.

Parameters

  status | Input/output error code.

Internal:
  Do not use. This API is for internal use only. ICU 75 technology preview

Deprecated:
  This API is for technology preview only.

## ◆ ~Builder()

virtual icu::message2::MessageFormatter::Builder::~Builder | ( |  | ) |
| virtual

Destructor.

Internal:
  Do not use. This API is for internal use only. ICU 75 technology preview

Deprecated:
  This API is for technology preview only.

## Member Function Documentation

## ◆ build()

MessageFormatter icu::message2::MessageFormatter::Builder::build | ( | UErrorCode & | status | ) | const

Constructs a new immutable MessageFormatter using the pattern or data model that was previously set, and the locale (if it was previously set) or default locale (otherwise).

The builder object (`this`) can still be used after calling `build()`.

Parameters

  status | Input/output error code. If neither the pattern nor the data model is set, set to failure code.

Returns
  The new MessageFormatter object

Internal:
  Do not use. This API is for internal use only. ICU 75 technology preview

Deprecated:
  This API is for technology preview only.

## ◆ setDataModel()

Builder& icu::message2::MessageFormatter::Builder::setDataModel | ( | MFDataModel && | dataModel | ) |

Sets a data model.

If a pattern was previously set, it is removed.

Parameters

  dataModel | Data model to format. Passed by move.

Returns
  A reference to the builder.

Internal:
  Do not use. This API is for internal use only. ICU 75 technology preview

Deprecated:
  This API is for technology preview only.

## ◆ setFunctionRegistry()

Builder& icu::message2::MessageFormatter::Builder::setFunctionRegistry | ( | const MFFunctionRegistry & | functionRegistry | ) |

Sets a custom function registry.

Parameters

  functionRegistry | Reference to the function registry to use. `functionRegistry` is not copied, and the caller must ensure its lifetime contains the lifetime of the `MessageFormatter` object built by this builder.

Returns
  A reference to the builder.

Internal:
  Do not use. This API is for internal use only. ICU 75 technology preview

Deprecated:
  This API is for technology preview only.

## ◆ setLocale()

Builder& icu::message2::MessageFormatter::Builder::setLocale | ( | const Locale & | locale | ) |

Sets the locale to use for formatting.

Parameters

  locale | The desired locale.

Returns
  A reference to the builder.

Internal:
  Do not use. This API is for internal use only. ICU 75 technology preview

Deprecated:
  This API is for technology preview only.

## ◆ setPattern()

Builder& icu::message2::MessageFormatter::Builder::setPattern | ( | const UnicodeString & | pattern,
|  | UParseError & | parseError,
|  | UErrorCode & | status
| ) |  |

Sets the pattern (contents of the message) and parses it into a data model.

If a data model was previously set, it is removed.

Parameters

  pattern | A string in MessageFormat 2.0 syntax.
  parseError | Struct to receive information on the position of an error within the pattern.
  status | Input/output error code. If the pattern cannot be parsed, set to failure code.

Returns
  A reference to the builder.

Internal:
  Do not use. This API is for internal use only. ICU 75 technology preview

Deprecated:
  This API is for technology preview only.

The documentation for this class was generated from the following file:

- i18n/unicode/messageformat2.h