public class MessagePattern
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
static class |
MessagePattern.ApostropheMode |
static class |
MessagePattern.ArgType
Argument type constants.
|
static class |
MessagePattern.Part |
| Modifier and Type | Field and Description |
|---|---|
static int |
ARG_NAME_NOT_NUMBER
Return value from
validateArgumentName(String) for when
the string is a valid "pattern identifier" but not a number. |
static int |
ARG_NAME_NOT_VALID
Return value from
validateArgumentName(String) for when
the string is invalid. |
static double |
NO_NUMERIC_VALUE
Special value that is returned by getNumericValue(Part) when no
numeric value is defined for a part.
|
| Constructor and Description |
|---|
MessagePattern() |
MessagePattern(MessagePattern.ApostropheMode mode)
Constructs an empty MessagePattern.
|
MessagePattern(java.lang.String pattern) |
| Modifier and Type | Method and Description |
|---|---|
java.lang.String |
autoQuoteApostropheDeep()
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.
|
void |
clear()
Clears this MessagePattern.
|
void |
clearPatternAndSetApostropheMode(MessagePattern.ApostropheMode mode)
Clears this MessagePattern and sets the ApostropheMode.
|
int |
countParts()
Returns the number of "parts" created by parsing the pattern string.
|
int |
findEndQuoteIndex(int index) |
MessagePattern.ApostropheMode |
getApostropheMode() |
int |
getLimitPartIndex(int start)
Returns the index of the ARG|MSG_LIMIT part corresponding to the ARG|MSG_START at start.
|
double |
getNumericValue(MessagePattern.Part part)
Returns the numeric value associated with an ARG_INT or ARG_DOUBLE.
|
MessagePattern.Part |
getPart(int i)
Gets the i-th pattern "part".
|
MessagePattern.Part.Type |
getPartType(int i)
Returns the Part.Type of the i-th pattern "part".
|
int |
getPatternIndex(int partIndex)
Returns the pattern index of the specified pattern "part".
|
java.lang.String |
getPatternString() |
double |
getPluralOffset(int pluralStart)
Returns the "offset:" value of a PluralFormat argument, or 0 if none is specified.
|
java.lang.String |
getSubstring(MessagePattern.Part part)
Returns the substring of the pattern string indicated by the Part.
|
boolean |
hasNamedArguments()
Does the parsed pattern have named arguments like {first_name}?
|
boolean |
hasNumberedArguments()
Does the parsed pattern have numbered arguments like {2}?
|
boolean |
isFrozen()
Determines whether this object is frozen (immutable) or not.
|
static boolean |
isNumeric(java.lang.String str) |
MessagePattern |
parse(java.lang.String pattern) |
int |
parseArgNameOrNumber(int nameIndex,
int index) |
int |
parseArgStyle(MessagePattern.ArgType argType,
int nameIndex,
int index,
int nestingLevel) |
java.util.Map<java.lang.String,java.lang.Object> |
parseArgType(int argStart,
int nameIndex,
int index) |
int |
parseExplicitValuePluralSelector(MessagePattern.ArgType argType,
int start,
int selectorIndex,
int index) |
int |
parsePluralOffset(boolean isEmpty,
int start,
int index) |
java.util.Map<java.lang.String,java.lang.Object> |
parsePluralOffsetOrNormalSelector(MessagePattern.ArgType argType,
int start,
int selectorIndex,
int index,
boolean isEmpty) |
MessagePattern |
parsePluralStyle(java.lang.String pattern)
Parses a PluralFormat pattern string.
|
boolean |
partSubstringMatches(MessagePattern.Part part,
java.lang.String s)
Compares the part's substring with the input string s.
|
java.lang.String |
toString() |
static int |
validateArgumentName(java.lang.String name)
Validates and parses an argument name or argument number string.
|
public static final int ARG_NAME_NOT_NUMBER
validateArgumentName(String) for when
the string is a valid "pattern identifier" but not a number.public static final int ARG_NAME_NOT_VALID
validateArgumentName(String) for when
the string is invalid.
It might not be a valid "pattern identifier",
or it have only ASCII digits but there is a leading zero or the number is too large.public static final double NO_NUMERIC_VALUE
public MessagePattern()
public MessagePattern(java.lang.String pattern)
public MessagePattern(MessagePattern.ApostropheMode mode)
mode - Explicit ApostropheMode.public MessagePattern parse(java.lang.String pattern)
public MessagePattern parsePluralStyle(java.lang.String pattern)
pattern - a PluralFormat pattern stringjava.lang.IllegalArgumentException - for syntax errors in the pattern stringjava.lang.IndexOutOfBoundsException - if certain limits are exceeded
(e.g., argument number too high, argument name too long, etc.)java.lang.NumberFormatException - if a number could not be parsedpublic int findEndQuoteIndex(int index)
public int parseArgNameOrNumber(int nameIndex,
int index)
public java.util.Map<java.lang.String,java.lang.Object> parseArgType(int argStart,
int nameIndex,
int index)
public int parseArgStyle(MessagePattern.ArgType argType, int nameIndex, int index, int nestingLevel)
public int parseExplicitValuePluralSelector(MessagePattern.ArgType argType, int start, int selectorIndex, int index)
public java.util.Map<java.lang.String,java.lang.Object> parsePluralOffsetOrNormalSelector(MessagePattern.ArgType argType, int start, int selectorIndex, int index, boolean isEmpty)
public int parsePluralOffset(boolean isEmpty,
int start,
int index)
public static boolean isNumeric(java.lang.String str)
public void clear()
public void clearPatternAndSetApostropheMode(MessagePattern.ApostropheMode mode)
mode - The new ApostropheMode.public MessagePattern.ApostropheMode getApostropheMode()
public java.lang.String getPatternString()
public boolean hasNamedArguments()
public boolean hasNumberedArguments()
public java.lang.String toString()
toString in class java.lang.Objectpublic static int validateArgumentName(java.lang.String name)
name - Input string.public java.lang.String autoQuoteApostropheDeep()
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}}."
MessageFormat#autoQuoteApostrophe(String)public int countParts()
public MessagePattern.Part getPart(int i)
i - The index of the Part data. (0..countParts()-1)java.lang.IndexOutOfBoundsException - if i is outside the (0..countParts()-1) rangepublic MessagePattern.Part.Type getPartType(int i)
i - The index of the Part data. (0..countParts()-1)java.lang.IndexOutOfBoundsException - if i is outside the (0..countParts()-1) rangepublic int getPatternIndex(int partIndex)
partIndex - The index of the Part data. (0..countParts()-1)java.lang.IndexOutOfBoundsException - if partIndex is outside the (0..countParts()-1) rangepublic java.lang.String getSubstring(MessagePattern.Part part)
part - a part of this MessagePattern.public boolean partSubstringMatches(MessagePattern.Part part, java.lang.String s)
part - a part of this MessagePattern.s - a string.public double getNumericValue(MessagePattern.Part part)
part - a part of this MessagePattern.public double getPluralOffset(int pluralStart)
pluralStart - the index of the first PluralFormat argument style part.
(0..countParts()-1)java.lang.IndexOutOfBoundsException - if pluralStart is outside the (0..countParts()-1) rangepublic int getLimitPartIndex(int start)
start - The index of some Part data (0..countParts()-1);
this Part should be of Type ARG_START or MSG_START.java.lang.IndexOutOfBoundsException - if start is outside the (0..countParts()-1) rangepublic boolean isFrozen()