The parser handles all syntax relevant for identifying message arguments. This includes "complex" arguments whose style strings contain nested MessageFormat pattern substrings. For "simple" arguments (with no nested MessageFormat 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 with countParts(), 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", getLimitPartIndex(int) efficiently returns
the index of the corresponding _LIMIT "part".
List of "parts":
message = MSG_START (SKIP_SYNTAX | INSERT_CHAR | REPLACE_NUMBER | argument)* MSG_LIMIT argument = noneArg | simpleArg | complexArg complexArg = choiceArg | pluralArg | selectArg noneArg = ARG_START.NONE (ARG_NAME | ARG_NUMBER) ARG_LIMIT.NONE simpleArg = ARG_START.SIMPLE (ARG_NAME | ARG_NUMBER) ARG_TYPE [ARG_STYLE] ARG_LIMIT.SIMPLE choiceArg = ARG_START.CHOICE (ARG_NAME | ARG_NUMBER) choiceStyle ARG_LIMIT.CHOICE pluralArg = ARG_START.PLURAL (ARG_NAME | ARG_NUMBER) pluralStyle ARG_LIMIT.PLURAL selectArg = ARG_START.SELECT (ARG_NAME | ARG_NUMBER) selectStyle ARG_LIMIT.SELECT choiceStyle = ((ARG_INT | ARG_DOUBLE) ARG_SELECTOR message)+ pluralStyle = [ARG_INT | ARG_DOUBLE] (ARG_SELECTOR [ARG_INT | ARG_DOUBLE] message)+ selectStyle = (ARG_SELECTOR message)+
ARG_START.CHOICE stands for an ARG_START Part with ArgType CHOICE.
This class is not intended for public subclassing.
| Modifier and Type | Class and Description |
|---|---|
| public static enum | MessagePattern.ApostropheMode
Mode for when an apostrophe starts quoted literal text for MessageFormat output. |
| public static enum | MessagePattern.ArgType
Argument type constants. |
| public static class | MessagePattern.Part
A message pattern "part", representing a pattern parsing event. |
| Modifier and Type | Field and Description |
|---|---|
| private MessagePattern. | |
| public static final int | ARG_NAME_NOT_NUMBER
Return value from |
| public static final int | ARG_NAME_NOT_VALID
Return value from |
| private static final MessagePattern. | |
| private static final MessagePattern. | |
| private volatile boolean | |
| private boolean | |
| private boolean | |
| private static final int | |
| private String | |
| private boolean | |
| public static final double | NO_NUMERIC_VALUE
Special value that is returned by getNumericValue(Part) when no numeric value is defined for a part. |
| private ArrayList | |
| private ArrayList |
| Access | Constructor and Description |
|---|---|
| public | |
| public | MessagePattern(MessagePattern.
Explicit ApostropheMode. modeConstructs an empty MessagePattern. |
| public | MessagePattern(String
a MessageFormat pattern string pattern)Constructs a MessagePattern with default ApostropheMode and parses the MessageFormat pattern string. |
| Modifier and Type | Method and Description | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| private void | |||||||||||||||||||||||||||||||||||
| private void | |||||||||||||||||||||||||||||||||||
| private void | |||||||||||||||||||||||||||||||||||
| pack-priv static void | appendReducedApostrophes(String s, int start, int limit, StringBuilder sb)
Appends the s[start, limit[ substring to sb, but with only half of the apostrophes according to JDK pattern behavior. | ||||||||||||||||||||||||||||||||||
| public String | Returns: the deep-auto-quoted version of the parsed pattern string.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. | ||||||||||||||||||||||||||||||||||
| public void | |||||||||||||||||||||||||||||||||||
| public void | clearPatternAndSetApostropheMode(MessagePattern.
The new ApostropheMode. modeClears this MessagePattern and sets the ApostropheMode. | ||||||||||||||||||||||||||||||||||
| public Object | Returns: a copy of this object (or itself if frozen).Overrides java. | ||||||||||||||||||||||||||||||||||
| public MessagePattern | Returns: a copy of this object.Implements com. | ||||||||||||||||||||||||||||||||||
| public int | Returns: the number of pattern parts.Returns the number of "parts" created by parsing the pattern string. | ||||||||||||||||||||||||||||||||||
| public boolean | Returns: true if this object is equivalent to the other one.another object to compare with. other)Overrides java. | ||||||||||||||||||||||||||||||||||
| public MessagePattern | Returns: thisImplements com. | ||||||||||||||||||||||||||||||||||
| public MessagePattern. | |||||||||||||||||||||||||||||||||||
| public int | 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.The index of some Part data (0..countParts()-1);
this Part should be of Type ARG_START or MSG_START. start)Returns the index of the ARG|MSG_LIMIT part corresponding to the ARG|MSG_START at start. | ||||||||||||||||||||||||||||||||||
| public double | Returns: the part's numeric value, or NO_NUMERIC_VALUE if this is not a numeric part.a part of this MessagePattern. partReturns the numeric value associated with an ARG_INT or ARG_DOUBLE. | ||||||||||||||||||||||||||||||||||
| public MessagePattern. | Returns: the i-th pattern "part".The index of the Part data. (0..countParts()-1) i)Gets the i-th pattern "part". | ||||||||||||||||||||||||||||||||||
| public MessagePattern. | Returns: The Part.Type of the i-th Part.The index of the Part data. (0..countParts()-1) i)Returns the Part.Type of the i-th pattern "part". | ||||||||||||||||||||||||||||||||||
| public int | Returns: The pattern index of this Part.The index of the Part data. (0..countParts()-1) partIndex)Returns the pattern index of the specified pattern "part". | ||||||||||||||||||||||||||||||||||
| public String | |||||||||||||||||||||||||||||||||||
| public double | Returns: the "offset:" value.the index of the first PluralFormat argument style part. (0..countParts()-1) pluralStart)Returns the "offset:" value of a PluralFormat argument, or 0 if none is specified. | ||||||||||||||||||||||||||||||||||
| public String | Returns: the substring associated with part.a part of this MessagePattern. partReturns the substring of the pattern string indicated by the Part. | ||||||||||||||||||||||||||||||||||
| public int | |||||||||||||||||||||||||||||||||||
| public boolean | Returns: true if the parsed pattern has at least one named argument.Does the parsed pattern have named arguments like {first_name}? | ||||||||||||||||||||||||||||||||||
| public boolean | Returns: true if the parsed pattern has at least one numbered argument.Does the parsed pattern have numbered arguments like {2}? | ||||||||||||||||||||||||||||||||||
| private boolean | Returns: true if we are inside a MessageFormat (sub-)pattern, as opposed to inside a top-level choice/plural/select pattern.
| ||||||||||||||||||||||||||||||||||
| private boolean | Returns: true if we are in a MessageFormat sub-pattern of a top-level ChoiceFormat pattern.
| ||||||||||||||||||||||||||||||||||
| private static boolean | |||||||||||||||||||||||||||||||||||
| private boolean | |||||||||||||||||||||||||||||||||||
| public boolean | Returns: true if this object is frozen.Implements com. | ||||||||||||||||||||||||||||||||||
| private boolean | |||||||||||||||||||||||||||||||||||
| private boolean | |||||||||||||||||||||||||||||||||||
| private boolean | |||||||||||||||||||||||||||||||||||
| pack-priv boolean | |||||||||||||||||||||||||||||||||||
| public MessagePattern | |||||||||||||||||||||||||||||||||||
| private int | |||||||||||||||||||||||||||||||||||
| private static int | 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.Validates and parses an argument name or argument number string. | ||||||||||||||||||||||||||||||||||
| private int | |||||||||||||||||||||||||||||||||||
| public MessagePattern | Returns: thisa ChoiceFormat pattern string pattern)Parses a ChoiceFormat pattern string. | ||||||||||||||||||||||||||||||||||
| private int | |||||||||||||||||||||||||||||||||||
| private void | parseDouble(int start index into the message string start, int limit index into the message string, must be start
true if U+221E is allowed (for ChoiceFormat) allowInfinity)Parses a number from the specified message substring. private int |
| private int |
| public MessagePattern | Returns: thisa PluralFormat pattern string pattern)Parses a PluralFormat pattern string. public MessagePattern | Returns: thisa SelectFormat pattern string pattern)Parses a SelectFormat pattern string. private int |
| public boolean | Returns: true if getSubstring(part).equals(s).a part of this MessagePattern. part,a string. s)Compares the part's substring with the input string s. private void |
| private static String |
| private static String |
| private String |
| private String |
| private void |
| private int |
| private int |
| private int |
| public String |
| public static int | 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.Input string. name)Validates and parses an argument name or argument number string. |