A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://unicode-org.github.io/icu-docs/apidoc/released/icu4c/classicu_1_1SimpleFormatter.html below:

ICU 77.1: icu::SimpleFormatter Class Reference

Formats simple patterns like "{1} was born in {0}". More...

#include <simpleformatter.h>

  SimpleFormatter ()   Default constructor. More...
    SimpleFormatter (const UnicodeString &pattern, UErrorCode &errorCode)   Constructs a formatter from the pattern string. More...
    SimpleFormatter (const UnicodeString &pattern, int32_t min, int32_t max, UErrorCode &errorCode)   Constructs a formatter from the pattern string. More...
    SimpleFormatter (const SimpleFormatter &other)   Copy constructor. More...
  SimpleFormatteroperator= (const SimpleFormatter &other)   Assignment operator. More...
    ~SimpleFormatter ()   Destructor. More...
  UBool  applyPattern (const UnicodeString &pattern, UErrorCode &errorCode)   Changes this object according to the new pattern. More...
  UBool  applyPatternMinMaxArguments (const UnicodeString &pattern, int32_t min, int32_t max, UErrorCode &errorCode)   Changes this object according to the new pattern. More...
  int32_t  getArgumentLimit () const   UnicodeStringformat (const UnicodeString &value0, UnicodeString &appendTo, UErrorCode &errorCode) const   Formats the given value, appending to the appendTo builder. More...
  UnicodeStringformat (const UnicodeString &value0, const UnicodeString &value1, UnicodeString &appendTo, UErrorCode &errorCode) const   Formats the given values, appending to the appendTo builder. More...
  UnicodeStringformat (const UnicodeString &value0, const UnicodeString &value1, const UnicodeString &value2, UnicodeString &appendTo, UErrorCode &errorCode) const   Formats the given values, appending to the appendTo builder. More...
  UnicodeStringformatAndAppend (const UnicodeString *const *values, int32_t valuesLength, UnicodeString &appendTo, int32_t *offsets, int32_t offsetsLength, UErrorCode &errorCode) const   Formats the given values, appending to the appendTo string. More...
  UnicodeStringformatAndReplace (const UnicodeString *const *values, int32_t valuesLength, UnicodeString &result, int32_t *offsets, int32_t offsetsLength, UErrorCode &errorCode) const   Formats the given values, replacing the contents of the result string. More...
  UnicodeString  getTextWithNoArguments () const   Returns the pattern text with none of the arguments. More...
  UnicodeString  getTextWithNoArguments (int32_t *offsets, int32_t offsetsLength) const   Returns the pattern text with none of the arguments. More...
  class  number::impl::SimpleModifier  

Formats simple patterns like "{1} was born in {0}".

Minimal subset of MessageFormat; fast, simple, minimal dependencies. Supports only numbered arguments with no type nor style parameters, and formats only string values. Quoting via ASCII apostrophe compatible with ICU MessageFormat default behavior.

Factory methods set error codes for syntax errors and for too few or too many arguments/placeholders.

SimpleFormatter objects are thread-safe except for assignment and applying new patterns.

Example:

UErrorCode errorCode = U_ZERO_ERROR;
SimpleFormatter fmt("{1} '{born}' in {0}", errorCode);
UnicodeString result;

// Output: "paul {born} in england"
fmt.format("england", "paul", result, errorCode);

This class is not intended for public subclassing.

See also
MessageFormat
UMessagePatternApostropheMode
Stable:
ICU 57

Definition at line 60 of file simpleformatter.h.

◆ SimpleFormatter() [1/4] icu::SimpleFormatter::SimpleFormatter ( ) inline ◆ SimpleFormatter() [2/4]

Constructs a formatter from the pattern string.

Parameters
pattern The pattern string. errorCode ICU error code in/out parameter. Must fulfill U_SUCCESS before the function call. Set to U_ILLEGAL_ARGUMENT_ERROR for bad argument syntax.
Stable:
ICU 57

Definition at line 77 of file simpleformatter.h.

◆ SimpleFormatter() [3/4] icu::SimpleFormatter::SimpleFormatter ( const UnicodeStringpattern, int32_t  min, int32_t  max, UErrorCodeerrorCode  ) inline

Constructs a formatter from the pattern string.

The number of arguments checked against the given limits is the highest argument number plus one, not the number of occurrences of arguments.

Parameters
pattern The pattern string. min The pattern must have at least this many arguments. max The pattern must have at most this many arguments. errorCode ICU error code in/out parameter. Must fulfill U_SUCCESS before the function call. Set to U_ILLEGAL_ARGUMENT_ERROR for bad argument syntax and too few or too many arguments.
Stable:
ICU 57

Definition at line 95 of file simpleformatter.h.

◆ SimpleFormatter() [4/4] ◆ ~SimpleFormatter() icu::SimpleFormatter::~SimpleFormatter ( ) ◆ applyPattern()

Changes this object according to the new pattern.

Parameters
pattern The pattern string. errorCode ICU error code in/out parameter. Must fulfill U_SUCCESS before the function call. Set to U_ILLEGAL_ARGUMENT_ERROR for bad argument syntax.
Returns
true if U_SUCCESS(errorCode).
Stable:
ICU 57

Definition at line 129 of file simpleformatter.h.

References INT32_MAX.

◆ applyPatternMinMaxArguments()

Changes this object according to the new pattern.

The number of arguments checked against the given limits is the highest argument number plus one, not the number of occurrences of arguments.

Parameters
pattern The pattern string. min The pattern must have at least this many arguments. max The pattern must have at most this many arguments. errorCode ICU error code in/out parameter. Must fulfill U_SUCCESS before the function call. Set to U_ILLEGAL_ARGUMENT_ERROR for bad argument syntax and too few or too many arguments.
Returns
true if U_SUCCESS(errorCode).
Stable:
ICU 57
◆ format() [1/3]

Formats the given values, appending to the appendTo builder.

An argument value must not be the same object as appendTo. getArgumentLimit() must be at most 3.

Parameters
value0 Value for argument {0}. value1 Value for argument {1}. value2 Value for argument {2}. appendTo Gets the formatted pattern and values appended. errorCode ICU error code in/out parameter. Must fulfill U_SUCCESS before the function call.
Returns
appendTo
Stable:
ICU 57
◆ format() [2/3]

Formats the given values, appending to the appendTo builder.

An argument value must not be the same object as appendTo. getArgumentLimit() must be at most 2.

Parameters
value0 Value for argument {0}. value1 Value for argument {1}. appendTo Gets the formatted pattern and values appended. errorCode ICU error code in/out parameter. Must fulfill U_SUCCESS before the function call.
Returns
appendTo
Stable:
ICU 57
◆ format() [3/3]

Formats the given value, appending to the appendTo builder.

The argument value must not be the same object as appendTo. getArgumentLimit() must be at most 1.

Parameters
value0 Value for argument {0}. appendTo Gets the formatted pattern and value appended. errorCode ICU error code in/out parameter. Must fulfill U_SUCCESS before the function call.
Returns
appendTo
Stable:
ICU 57
◆ formatAndAppend()

Formats the given values, appending to the appendTo string.

Parameters
values The argument values. An argument value must not be the same object as appendTo. Can be nullptr if valuesLength==getArgumentLimit()==0. valuesLength The length of the values array. Must be at least getArgumentLimit(). appendTo Gets the formatted pattern and values appended. offsets offsets[i] receives the offset of where values[i] replaced pattern argument {i}. Can be shorter or longer than values. Can be nullptr if offsetsLength==0. If there is no {i} in the pattern, then offsets[i] is set to -1. offsetsLength The length of the offsets array. errorCode ICU error code in/out parameter. Must fulfill U_SUCCESS before the function call.
Returns
appendTo
Stable:
ICU 57
◆ formatAndReplace()

Formats the given values, replacing the contents of the result string.

May optimize by actually appending to the result if it is the same object as the value corresponding to the initial argument in the pattern.

Parameters
values The argument values. An argument value may be the same object as result. Can be nullptr if valuesLength==getArgumentLimit()==0. valuesLength The length of the values array. Must be at least getArgumentLimit(). result Gets its contents replaced by the formatted pattern and values. offsets offsets[i] receives the offset of where values[i] replaced pattern argument {i}. Can be shorter or longer than values. Can be nullptr if offsetsLength==0. If there is no {i} in the pattern, then offsets[i] is set to -1. offsetsLength The length of the offsets array. errorCode ICU error code in/out parameter. Must fulfill U_SUCCESS before the function call.
Returns
result
Stable:
ICU 57
◆ getArgumentLimit() int32_t icu::SimpleFormatter::getArgumentLimit ( ) const inline ◆ getTextWithNoArguments() [1/2] UnicodeString icu::SimpleFormatter::getTextWithNoArguments ( ) const inline

Returns the pattern text with none of the arguments.

Like formatting with all-empty string values.

Stable:
ICU 57

Definition at line 268 of file simpleformatter.h.

◆ getTextWithNoArguments() [2/2] UnicodeString icu::SimpleFormatter::getTextWithNoArguments ( int32_t *  offsets, int32_t  offsetsLength  ) const inline

Returns the pattern text with none of the arguments.

Like formatting with all-empty string values.

TODO(ICU-20406): Replace this with an Iterator interface.

Parameters
offsets offsets[i] receives the offset of where {i} was located before it was replaced by an empty string. For example, "a{0}b{1}" produces offset 1 for i=0 and 2 for i=1. Can be nullptr if offsetsLength==0. If there is no {i} in the pattern, then offsets[i] is set to -1. offsetsLength The length of the offsets array.
Internal:
Do not use. This API is for internal use only.

Definition at line 292 of file simpleformatter.h.

◆ operator=()

Assignment operator.

Stable:
ICU 57

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


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4