Go to the documentation of this file.
17 #ifndef __MESSAGEPATTERN_H__
18 #define __MESSAGEPATTERN_H__
27 #if U_SHOW_CPLUSPLUS_API
29 #if !UCONFIG_NO_FORMATTING
272 #define UMSGPAT_ARG_TYPE_HAS_PLURAL_STYLE(argType) \
273 ((argType)==UMSGPAT_ARG_TYPE_PLURAL || (argType)==UMSGPAT_ARG_TYPE_SELECTORDINAL)
299 #define UMSGPAT_NO_NUMERIC_VALUE ((double)(-123456789))
303 class MessagePatternDoubleList;
304 class MessagePatternPartsList;
580 return hasArgNumbers;
638 return getPart(i).type;
649 return getPart(partIndex).index;
671 return 0==msg.compare(part.index, part.length, s);
699 int32_t limit=getPart(start).limitPartIndex;
816 return ((type*37+index)*37+length)*37+value;
822 static const int32_t MAX_LENGTH=0xffff;
823 static const int32_t MAX_VALUE=0x7fff;
831 int32_t limitPartIndex;
839 int32_t parseMessage(int32_t index, int32_t msgStartLength,
843 int32_t parseArg(int32_t index, int32_t argStartLength, int32_t nestingLevel,
848 int32_t parseChoiceStyle(int32_t index, int32_t nestingLevel,
862 static int32_t parseArgNumber(
const UnicodeString &s, int32_t start, int32_t limit);
864 int32_t parseArgNumber(int32_t start, int32_t limit) {
865 return parseArgNumber(msg, start, limit);
876 void parseDouble(int32_t start, int32_t limit,
UBool allowInfinity,
882 int32_t skipWhiteSpace(int32_t index);
884 int32_t skipIdentifier(int32_t index);
890 int32_t skipDouble(int32_t index);
894 UBool isChoice(int32_t index);
896 UBool isPlural(int32_t index);
898 UBool isSelect(int32_t index);
900 UBool isOrdinal(int32_t index);
906 UBool inMessageFormatPattern(int32_t nestingLevel);
917 void addLimitPart(int32_t start,
921 void addArgDoublePart(
double numericValue, int32_t start, int32_t length,
UErrorCode &errorCode);
923 void setParseError(
UParseError *parseError, int32_t index);
931 MessagePatternPartsList *partsList;
935 MessagePatternDoubleList *numericValuesList;
936 double *numericValues;
937 int32_t numericValuesLength;
940 UBool needsAutoQuoting;
945 #endif // !UCONFIG_NO_FORMATTING
949 #endif // __MESSAGEPATTERN_H__
MessagePattern(const UnicodeString &pattern, UParseError *parseError, UErrorCode &errorCode)
Constructs a MessagePattern with default UMessagePatternApostropheMode and parses the MessageFormat p...
UBool partSubstringMatches(const Part &part, const UnicodeString &s) const
Compares the part's substring with the input string s.
int32_t countParts() const
Returns the number of "parts" created by parsing the pattern string.
C API: Parse Error Information.
Basic definitions for ICU, for both C and C++ APIs.
UBool operator==(const Part &other) const
int8_t UBool
The ICU boolean type.
static UBool hasNumericValue(UMessagePatternPartType type)
Indicates whether the Part type has a numeric value.
UMessagePatternPartType getPartType(int32_t i) const
Returns the UMessagePatternPartType of the i-th pattern "part".
@ UMSGPAT_PART_TYPE_ARG_DOUBLE
A numeric value, for example the offset or an explicit selector value in a PluralFormat style.
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
#define U_COMMON_API
Set to export library symbols from inside the common library, and to import them from outside.
@ UMSGPAT_ARG_NAME_NOT_VALID
Return value from MessagePattern.validateArgumentName() for when the string is invalid.
UMessagePatternApostropheMode getApostropheMode() const
MessagePattern(const MessagePattern &other)
Copy constructor.
void clearPatternAndSetApostropheMode(UMessagePatternApostropheMode mode)
Clears this MessagePattern and sets the UMessagePatternApostropheMode.
UMessagePatternArgType
Argument type constants.
const Part & getPart(int32_t i) const
Gets the i-th pattern "part".
static int32_t validateArgumentName(const UnicodeString &name)
Validates and parses an argument name or argument number string.
UBool operator==(const MessagePattern &other) const
int32_t getValue() const
Returns a value associated with this part.
A UParseError struct is used to returned detailed information about parsing errors.
Parses and represents ICU MessageFormat patterns.
@ UMSGPAT_APOS_DOUBLE_REQUIRED
A literal apostrophe must be represented by a double apostrophe pattern character.
MessagePattern & operator=(const MessagePattern &other)
Assignment operator.
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
UnicodeString getSubstring(const Part &part) const
Returns the substring of the pattern string indicated by the Part.
MessagePattern(UErrorCode &errorCode)
Constructs an empty MessagePattern with default UMessagePatternApostropheMode.
@ UMSGPAT_PART_TYPE_ARG_SELECTOR
A selector substring in a "complex" argument style.
int32_t UChar32
Define UChar32 as a type for single Unicode code points.
UMessagePatternApostropheMode
Mode for when an apostrophe starts quoted literal text for MessageFormat output.
UObject is the common ICU "boilerplate" class.
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
const UnicodeString & getPatternString() const
MessagePattern(UMessagePatternApostropheMode mode, UErrorCode &errorCode)
Constructs an empty MessagePattern.
@ UMSGPAT_PART_TYPE_SKIP_SYNTAX
Indicates a substring of the pattern string which is to be skipped when formatting.
@ UMSGPAT_ARG_TYPE_SIMPLE
The argument has a "simple" type which is provided by the ARG_TYPE part.
UBool hasNumberedArguments() const
Does the parsed pattern have numbered arguments like {2}?
A message pattern "part", representing a pattern parsing event.
UMemory is the common ICU base class.
MessagePattern & parseSelectStyle(const UnicodeString &pattern, UParseError *parseError, UErrorCode &errorCode)
Parses a SelectFormat pattern string.
@ UMSGPAT_APOS_DOUBLE_OPTIONAL
A literal apostrophe is represented by either a single or a double apostrophe pattern character.
@ UMSGPAT_PART_TYPE_ARG_TYPE
The argument type.
@ UMSGPAT_PART_TYPE_MSG_START
Start of a message pattern (main or nested).
MessagePattern & parsePluralStyle(const UnicodeString &pattern, UParseError *parseError, UErrorCode &errorCode)
Parses a PluralFormat pattern string.
@ UMSGPAT_PART_TYPE_ARG_LIMIT
End of an argument.
int32_t getLimit() const
Returns the pattern string limit (exclusive-end) index associated with this Part.
UMessagePatternPartType getType() const
Returns the type of this part.
@ UMSGPAT_ARG_TYPE_SELECT
The argument is a SelectFormat with one or more (ARG_SELECTOR, message) pairs.
UMessagePatternArgType getArgType() const
Returns the argument type if this part is of type ARG_START or ARG_LIMIT, otherwise UMSGPAT_ARG_TYPE_...
virtual ~MessagePattern()
Destructor.
@ UMSGPAT_PART_TYPE_MSG_LIMIT
End of a message pattern (main or nested).
@ UMSGPAT_ARG_TYPE_PLURAL
The argument is a cardinal-number PluralFormat with an optional ARG_INT or ARG_DOUBLE offset (e....
UBool hasNamedArguments() const
Does the parsed pattern have named arguments like {first_name}?
int32_t getIndex() const
Returns the pattern string index associated with this Part.
double getNumericValue(const Part &part) const
Returns the numeric value associated with an ARG_INT or ARG_DOUBLE.
MessagePattern & parse(const UnicodeString &pattern, UParseError *parseError, UErrorCode &errorCode)
Parses a MessageFormat pattern string.
UBool operator!=(const Part &other) const
@ UMSGPAT_PART_TYPE_REPLACE_NUMBER
Indicates a syntactic (non-escaped) # symbol in a plural variant.
@ UMSGPAT_PART_TYPE_ARG_INT
An integer value, for example the offset or an explicit selector value in a PluralFormat style.
UnicodeString tempSubString(int32_t start=0, int32_t length=INT32_MAX) const
Create a temporary substring for the specified range.
@ UMSGPAT_PART_TYPE_ARG_NAME
The argument name.
@ UMSGPAT_PART_TYPE_INSERT_CHAR
Indicates that a syntax character needs to be inserted for auto-quoting.
@ UMSGPAT_ARG_TYPE_NONE
The argument has no specified type.
UMessagePatternPartType
MessagePattern::Part type constants.
@ UMSGPAT_PART_TYPE_ARG_STYLE
The argument style text.
int32_t getPatternIndex(int32_t partIndex) const
Returns the pattern index of the specified pattern "part".
UnicodeString autoQuoteApostropheDeep() const
Returns a version of the parsed pattern string where each ASCII apostrophe is doubled (escaped) if it...
@ UMSGPAT_ARG_TYPE_SELECTORDINAL
The argument is an ordinal-number PluralFormat with the same style parts sequence and semantics as UM...
@ UMSGPAT_ARG_NAME_NOT_NUMBER
Return value from MessagePattern.validateArgumentName() for when the string is a valid "pattern ident...
@ UMSGPAT_PART_TYPE_ARG_NUMBER
The argument number, provided by the value.
UBool operator!=(const MessagePattern &other) const
double getPluralOffset(int32_t pluralStart) const
Returns the "offset:" value of a PluralFormat argument, or 0 if none is specified.
MessagePattern & parseChoiceStyle(const UnicodeString &pattern, UParseError *parseError, UErrorCode &errorCode)
Parses a ChoiceFormat pattern string.
Part()
Default constructor, do not use.
int32_t getLimitPartIndex(int32_t start) const
Returns the index of the ARG|MSG_LIMIT part corresponding to the ARG|MSG_START at start.
@ UMSGPAT_PART_TYPE_ARG_START
Start of an argument.
int32_t getLength() const
Returns the length of the pattern substring associated with this Part.
@ UMSGPAT_ARG_TYPE_CHOICE
The argument is a ChoiceFormat with one or more ((ARG_INT | ARG_DOUBLE), ARG_SELECTOR,...
void clear()
Clears this MessagePattern.