Movatterモバイル変換


[0]ホーム

URL:


ICU 78.1  78.1
Data Structures |Public Member Functions |Static Public Member Functions
icu::MessagePattern Class Reference

Parses and represents ICUMessageFormat patterns.More...

#include <messagepattern.h>

Inheritance diagram for icu::MessagePattern:

Data Structures

class  Part
 A message pattern "part", representing a pattern parsing event.More...
 

Public Member Functions

 MessagePattern (UErrorCode &errorCode)
 Constructs an emptyMessagePattern with default UMessagePatternApostropheMode.More...
 
 MessagePattern (UMessagePatternApostropheMode mode,UErrorCode &errorCode)
 Constructs an emptyMessagePattern.More...
 
 MessagePattern (constUnicodeString &pattern,UParseError *parseError,UErrorCode &errorCode)
 Constructs aMessagePattern with default UMessagePatternApostropheMode and parses theMessageFormat pattern string.More...
 
 MessagePattern (constMessagePattern &other)
 Copy constructor.More...
 
MessagePatternoperator= (constMessagePattern &other)
 Assignment operator.More...
 
virtual ~MessagePattern ()
 Destructor.More...
 
MessagePatternparse (constUnicodeString &pattern,UParseError *parseError,UErrorCode &errorCode)
 Parses aMessageFormat pattern string.More...
 
MessagePatternparseChoiceStyle (constUnicodeString &pattern,UParseError *parseError,UErrorCode &errorCode)
 Parses aChoiceFormat pattern string.More...
 
MessagePatternparsePluralStyle (constUnicodeString &pattern,UParseError *parseError,UErrorCode &errorCode)
 Parses aPluralFormat pattern string.More...
 
MessagePatternparseSelectStyle (constUnicodeString &pattern,UParseError *parseError,UErrorCode &errorCode)
 Parses aSelectFormat pattern string.More...
 
void clear ()
 Clears thisMessagePattern.More...
 
void clearPatternAndSetApostropheMode (UMessagePatternApostropheMode mode)
 Clears thisMessagePattern and sets the UMessagePatternApostropheMode.More...
 
bool operator== (constMessagePattern &other) const
 
bool operator!= (constMessagePattern &other) const
 
int32_t hashCode () const
 
UMessagePatternApostropheMode getApostropheMode () const
 
constUnicodeStringgetPatternString () const
 
UBool hasNamedArguments () const
 Does the parsed pattern have named arguments like {first_name}?More...
 
UBool hasNumberedArguments () const
 Does the parsed pattern have numbered arguments like {2}?More...
 
UnicodeString autoQuoteApostropheDeep () const
 Returns a version of the parsed pattern string where each ASCII apostrophe is doubled (escaped) if it is not already, and if it is not interpreted as quoting syntax.More...
 
int32_t countParts () const
 Returns the number of "parts" created by parsing the pattern string.More...
 
constPartgetPart (int32_t i) const
 Gets the i-th pattern "part".More...
 
UMessagePatternPartType getPartType (int32_t i) const
 Returns the UMessagePatternPartType of the i-th pattern "part".More...
 
int32_t getPatternIndex (int32_t partIndex) const
 Returns the pattern index of the specified pattern "part".More...
 
UnicodeString getSubstring (constPart &part) const
 Returns the substring of the pattern string indicated by thePart.More...
 
UBool partSubstringMatches (constPart &part, constUnicodeString &s) const
 Compares the part's substring with the input string s.More...
 
double getNumericValue (constPart &part) const
 Returns the numeric value associated with an ARG_INT or ARG_DOUBLE.More...
 
double getPluralOffset (int32_t pluralStart) const
 Returns the "offset:" value of aPluralFormat argument, or 0 if none is specified.More...
 
int32_t getLimitPartIndex (int32_t start) const
 Returns the index of the ARG|MSG_LIMIT part corresponding to the ARG|MSG_START at start.More...
 
- Public Member Functions inherited fromicu::UObject
virtual ~UObject ()
 Destructor.More...
 
virtualUClassID getDynamicClassID () const
 ICU4C "poor man's RTTI", returns a UClassID for the actual ICU class.More...
 

Static Public Member Functions

static int32_t validateArgumentName (constUnicodeString &name)
 Validates and parses an argument name or argument number string.More...
 

Detailed Description

Parses and represents ICUMessageFormat patterns.

Also handles patterns forChoiceFormat,PluralFormat andSelectFormat. Used in the implementations of those classes as well as in tools for message validation, translation and format conversion.

The parser handles all syntax relevant for identifying message arguments. This includes "complex" arguments whose style strings contain nestedMessageFormat pattern substrings. For "simple" arguments (with no nestedMessageFormat pattern substrings), the argument style is not parsed any further.

The parser handles named and numbered message arguments and allows both in one message.

Once a pattern has been parsed successfully, iterate through the parsed data withcountParts(),getPart() and related methods.

The data logically represents a parse tree, but is stored and accessed as a list of "parts" for fast and simple parsing and to minimize object allocations. Arguments and nested messages are best handled via recursion. For every _START "part",MessagePattern.getLimitPartIndex() efficiently returns the index of the corresponding _LIMIT "part".

List of "parts":

message = MSG_START (SKIP_SYNTAX | INSERT_CHAR | REPLACE_NUMBER | argument)* MSG_LIMITargument = noneArg | simpleArg | complexArgcomplexArg = choiceArg | pluralArg | selectArgnoneArg = ARG_START.NONE (ARG_NAME | ARG_NUMBER) ARG_LIMIT.NONEsimpleArg = ARG_START.SIMPLE (ARG_NAME | ARG_NUMBER) ARG_TYPE [ARG_STYLE] ARG_LIMIT.SIMPLEchoiceArg = ARG_START.CHOICE (ARG_NAME | ARG_NUMBER) choiceStyle ARG_LIMIT.CHOICEpluralArg = ARG_START.PLURAL (ARG_NAME | ARG_NUMBER) pluralStyle ARG_LIMIT.PLURALselectArg = ARG_START.SELECT (ARG_NAME | ARG_NUMBER) selectStyle ARG_LIMIT.SELECTchoiceStyle = ((ARG_INT | ARG_DOUBLE) ARG_SELECTOR message)+pluralStyle = [ARG_INT | ARG_DOUBLE] (ARG_SELECTOR [ARG_INT | ARG_DOUBLE] message)+selectStyle = (ARG_SELECTOR message)+

This class is not intended for public subclassing.

Stable:
ICU 4.8

Definition at line362 of filemessagepattern.h.

Constructor & Destructor Documentation

◆ MessagePattern()[1/4]

icu::MessagePattern::MessagePattern(UErrorCodeerrorCode)

Constructs an emptyMessagePattern with default UMessagePatternApostropheMode.

Parameters
errorCodeStandard ICU error code. Its input value must pass theU_SUCCESS() test, or else the function returns immediately. Check forU_FAILURE() on output or use with function chaining. (See User Guide for details.)
Stable:
ICU 4.8

◆ MessagePattern()[2/4]

icu::MessagePattern::MessagePattern(UMessagePatternApostropheMode mode,
UErrorCodeerrorCode 
)

Constructs an emptyMessagePattern.

Parameters
modeExplicit UMessagePatternApostropheMode.
errorCodeStandard ICU error code. Its input value must pass theU_SUCCESS() test, or else the function returns immediately. Check forU_FAILURE() on output or use with function chaining. (See User Guide for details.)
Stable:
ICU 4.8

◆ MessagePattern()[3/4]

icu::MessagePattern::MessagePattern(constUnicodeStringpattern,
UParseErrorparseError,
UErrorCodeerrorCode 
)

Constructs aMessagePattern with default UMessagePatternApostropheMode and parses theMessageFormat pattern string.

Parameters
patternaMessageFormat pattern string
parseErrorStruct to receive information on the position of an error within the pattern. Can be nullptr.
errorCodeStandard ICU error code. Its input value must pass theU_SUCCESS() test, or else the function returns immediately. Check forU_FAILURE() on output or use with function chaining. (See User Guide for details.) TODO: turn
Exceptions
intoUErrorCode specifics?
IllegalArgumentExceptionfor syntax errors in the pattern string
IndexOutOfBoundsExceptionif certain limits are exceeded (e.g., argument number too high, argument name too long, etc.)
NumberFormatExceptionif a number could not be parsed
Stable:
ICU 4.8

◆ MessagePattern()[4/4]

icu::MessagePattern::MessagePattern(constMessagePatternother)

Copy constructor.

Parameters
otherObject to copy.
Stable:
ICU 4.8

◆ ~MessagePattern()

virtual icu::MessagePattern::~MessagePattern()
virtual

Destructor.

Stable:
ICU 4.8

Member Function Documentation

◆ autoQuoteApostropheDeep()

UnicodeString icu::MessagePattern::autoQuoteApostropheDeep() const

Returns a version of the parsed pattern string where each ASCII apostrophe is doubled (escaped) if it is not already, and if it is not interpreted as quoting syntax.

For example, this turns "I don't '{know}' {gender,select,female{h''er}other{h'im}}." into "I don''t '{know}' {gender,select,female{h''er}other{h''im}}."

Returns
the deep-auto-quoted version of the parsed pattern string.
See also
MessageFormat.autoQuoteApostrophe()
Stable:
ICU 4.8

◆ clear()

void icu::MessagePattern::clear()

Clears thisMessagePattern.

countParts() will return 0.

Stable:
ICU 4.8

◆ clearPatternAndSetApostropheMode()

void icu::MessagePattern::clearPatternAndSetApostropheMode(UMessagePatternApostropheMode mode)
inline

Clears thisMessagePattern and sets the UMessagePatternApostropheMode.

countParts() will return 0.

Parameters
modeThe new UMessagePatternApostropheMode.
Stable:
ICU 4.8

Definition at line519 of filemessagepattern.h.

◆ countParts()

int32_t icu::MessagePattern::countParts() const
inline

Returns the number of "parts" created by parsing the pattern string.

Returns 0 if no pattern has been parsed orclear() was called.

Returns
the number of pattern parts.
Stable:
ICU 4.8

Definition at line616 of filemessagepattern.h.

◆ getApostropheMode()

UMessagePatternApostropheMode icu::MessagePattern::getApostropheMode() const
inline
Returns
this instance's UMessagePatternApostropheMode.
Stable:
ICU 4.8

Definition at line550 of filemessagepattern.h.

◆ getLimitPartIndex()

int32_t icu::MessagePattern::getLimitPartIndex(int32_t start) const
inline

Returns the index of the ARG|MSG_LIMIT part corresponding to the ARG|MSG_START at start.

Parameters
startThe index of somePart data (0..countParts()-1); thisPart should be of Type ARG_START or MSG_START.
Returns
The first i>start where getPart(i).getType()==ARG|MSG_LIMIT at the same nesting level, or start itself if getPartType(msgStart)!=ARG|MSG_START.
Stable:
ICU 4.8

Definition at line698 of filemessagepattern.h.

◆ getNumericValue()

double icu::MessagePattern::getNumericValue(constPartpart) const

Returns the numeric value associated with an ARG_INT or ARG_DOUBLE.

Parameters
parta part of thisMessagePattern.
Returns
the part's numeric value, or UMSGPAT_NO_NUMERIC_VALUE if this is not a numeric part.
Stable:
ICU 4.8

◆ getPart()

constPart& icu::MessagePattern::getPart(int32_t i) const
inline

Gets the i-th pattern "part".

Parameters
iThe index of thePart data. (0..countParts()-1)
Returns
the i-th pattern "part".
Stable:
ICU 4.8

Definition at line626 of filemessagepattern.h.

◆ getPartType()

UMessagePatternPartType icu::MessagePattern::getPartType(int32_t i) const
inline

Returns the UMessagePatternPartType of the i-th pattern "part".

Convenience method for getPart(i).getType().

Parameters
iThe index of thePart data. (0..countParts()-1)
Returns
The UMessagePatternPartType of the i-thPart.
Stable:
ICU 4.8

Definition at line637 of filemessagepattern.h.

◆ getPatternIndex()

int32_t icu::MessagePattern::getPatternIndex(int32_t partIndex) const
inline

Returns the pattern index of the specified pattern "part".

Convenience method for getPart(partIndex).getIndex().

Parameters
partIndexThe index of thePart data. (0..countParts()-1)
Returns
The pattern index of thisPart.
Stable:
ICU 4.8

Definition at line648 of filemessagepattern.h.

◆ getPatternString()

constUnicodeString& icu::MessagePattern::getPatternString() const
inline
Returns
the parsed pattern string (null if none was parsed).
Stable:
ICU 4.8

Definition at line561 of filemessagepattern.h.

◆ getPluralOffset()

double icu::MessagePattern::getPluralOffset(int32_t pluralStart) const

Returns the "offset:" value of aPluralFormat argument, or 0 if none is specified.

Parameters
pluralStartthe index of the firstPluralFormat argument style part. (0..countParts()-1)
Returns
the "offset:" value.
Stable:
ICU 4.8

◆ getSubstring()

UnicodeString icu::MessagePattern::getSubstring(constPartpart) const
inline

Returns the substring of the pattern string indicated by thePart.

Convenience method forgetPatternString().substring(part.getIndex(), part.getLimit()).

Parameters
parta part of thisMessagePattern.
Returns
the substring associated with part.
Stable:
ICU 4.8

Definition at line659 of filemessagepattern.h.

Referencesicu::UnicodeString::tempSubString().

◆ hashCode()

int32_t icu::MessagePattern::hashCode() const
Returns
A hash code for this object.
Stable:
ICU 4.8

◆ hasNamedArguments()

UBool icu::MessagePattern::hasNamedArguments() const
inline

Does the parsed pattern have named arguments like {first_name}?

Returns
true if the parsed pattern has at least one named argument.
Stable:
ICU 4.8

Definition at line570 of filemessagepattern.h.

◆ hasNumberedArguments()

UBool icu::MessagePattern::hasNumberedArguments() const
inline

Does the parsed pattern have numbered arguments like {2}?

Returns
true if the parsed pattern has at least one numbered argument.
Stable:
ICU 4.8

Definition at line579 of filemessagepattern.h.

◆ operator!=()

bool icu::MessagePattern::operator!=(constMessagePatternother) const
inline
Parameters
otheranother object to compare with.
Returns
false if this object is equivalent to the other one.
Stable:
ICU 4.8

Definition at line536 of filemessagepattern.h.

Referencesicu::operator==().

◆ operator=()

MessagePattern& icu::MessagePattern::operator=(constMessagePatternother)

Assignment operator.

Parameters
otherObject to copy.
Returns
*this=other
Stable:
ICU 4.8

◆ operator==()

bool icu::MessagePattern::operator==(constMessagePatternother) const
Parameters
otheranother object to compare with.
Returns
true if this object is equivalent to the other one.
Stable:
ICU 4.8

◆ parse()

MessagePattern& icu::MessagePattern::parse(constUnicodeStringpattern,
UParseErrorparseError,
UErrorCodeerrorCode 
)

Parses aMessageFormat pattern string.

Parameters
patternaMessageFormat pattern string
parseErrorStruct to receive information on the position of an error within the pattern. Can be nullptr.
errorCodeStandard ICU error code. Its input value must pass theU_SUCCESS() test, or else the function returns immediately. Check forU_FAILURE() on output or use with function chaining. (See User Guide for details.)
Returns
*this
Exceptions
IllegalArgumentExceptionfor syntax errors in the pattern string
IndexOutOfBoundsExceptionif certain limits are exceeded (e.g., argument number too high, argument name too long, etc.)
NumberFormatExceptionif a number could not be parsed
Stable:
ICU 4.8

◆ parseChoiceStyle()

MessagePattern& icu::MessagePattern::parseChoiceStyle(constUnicodeStringpattern,
UParseErrorparseError,
UErrorCodeerrorCode 
)

Parses aChoiceFormat pattern string.

Parameters
patternaChoiceFormat pattern string
parseErrorStruct to receive information on the position of an error within the pattern. Can be nullptr.
errorCodeStandard ICU error code. Its input value must pass theU_SUCCESS() test, or else the function returns immediately. Check forU_FAILURE() on output or use with function chaining. (See User Guide for details.)
Returns
*this
Exceptions
IllegalArgumentExceptionfor syntax errors in the pattern string
IndexOutOfBoundsExceptionif certain limits are exceeded (e.g., argument number too high, argument name too long, etc.)
NumberFormatExceptionif a number could not be parsed
Stable:
ICU 4.8

◆ parsePluralStyle()

MessagePattern& icu::MessagePattern::parsePluralStyle(constUnicodeStringpattern,
UParseErrorparseError,
UErrorCodeerrorCode 
)

Parses aPluralFormat pattern string.

Parameters
patternaPluralFormat pattern string
parseErrorStruct to receive information on the position of an error within the pattern. Can be nullptr.
errorCodeStandard ICU error code. Its input value must pass theU_SUCCESS() test, or else the function returns immediately. Check forU_FAILURE() on output or use with function chaining. (See User Guide for details.)
Returns
*this
Exceptions
IllegalArgumentExceptionfor syntax errors in the pattern string
IndexOutOfBoundsExceptionif certain limits are exceeded (e.g., argument number too high, argument name too long, etc.)
NumberFormatExceptionif a number could not be parsed
Stable:
ICU 4.8

◆ parseSelectStyle()

MessagePattern& icu::MessagePattern::parseSelectStyle(constUnicodeStringpattern,
UParseErrorparseError,
UErrorCodeerrorCode 
)

Parses aSelectFormat pattern string.

Parameters
patternaSelectFormat pattern string
parseErrorStruct to receive information on the position of an error within the pattern. Can be nullptr.
errorCodeStandard ICU error code. Its input value must pass theU_SUCCESS() test, or else the function returns immediately. Check forU_FAILURE() on output or use with function chaining. (See User Guide for details.)
Returns
*this
Exceptions
IllegalArgumentExceptionfor syntax errors in the pattern string
IndexOutOfBoundsExceptionif certain limits are exceeded (e.g., argument number too high, argument name too long, etc.)
NumberFormatExceptionif a number could not be parsed
Stable:
ICU 4.8

◆ partSubstringMatches()

UBool icu::MessagePattern::partSubstringMatches(constPartpart,
constUnicodeStrings 
) const
inline

Compares the part's substring with the input string s.

Parameters
parta part of thisMessagePattern.
sa string.
Returns
true if getSubstring(part).equals(s).
Stable:
ICU 4.8

Definition at line670 of filemessagepattern.h.

◆ validateArgumentName()

static int32_t icu::MessagePattern::validateArgumentName(constUnicodeStringname)
static

Validates and parses an argument name or argument number string.

An argument name must be a "pattern identifier", that is, it must contain no Unicode Pattern_Syntax or Pattern_White_Space characters. If it only contains ASCII digits, then it must be a small integer with no leading zero.

Parameters
nameInput string.
Returns
>=0 if the name is a valid number, ARG_NAME_NOT_NUMBER (-1) if it is a "pattern identifier" but not all ASCII digits, ARG_NAME_NOT_VALID (-2) if it is neither.
Stable:
ICU 4.8

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

Generated by doxygen 1.9.1
[8]ページ先頭

©2009-2025 Movatter.jp