public class AffixUtils extends Object
| Affix Pattern | Example Unescaped (Formatted) String |
|---|---|
| abc | abc |
| ab- | ab− |
| ab'-' | ab- |
| ab'' | ab' |
long tag = 0L;
while (AffixPatternUtils.hasNext(tag, patternString)) {
tag = AffixPatternUtils.nextToken(tag, patternString);
int typeOrCp = AffixPatternUtils.getTypeOrCp(tag);
switch (typeOrCp) {
case AffixPatternUtils.TYPE_MINUS_SIGN:
// Current token is a minus sign.
break;
case AffixPatternUtils.TYPE_PLUS_SIGN:
// Current token is a plus sign.
break;
case AffixPatternUtils.TYPE_PERCENT:
// Current token is a percent sign.
break;
// ... other types ...
default:
// Current token is an arbitrary code point.
// The variable typeOrCp is the code point.
break;
}
}
| Modifier and Type | Class and Description |
|---|---|
static interface |
AffixUtils.SymbolProvider |
static interface |
AffixUtils.TokenConsumer |
| Modifier and Type | Field and Description |
|---|---|
static int |
TYPE_APPROXIMATELY_SIGN |
static int |
TYPE_CURRENCY_DOUBLE
Represents a double currency symbol '¤¤'.
|
static int |
TYPE_CURRENCY_OVERFLOW
Represents a sequence of six or more currency symbols.
|
static int |
TYPE_CURRENCY_QUAD
Represents a quadruple currency symbol '¤¤¤¤'.
|
static int |
TYPE_CURRENCY_QUINT
Represents a quintuple currency symbol '¤¤¤¤¤'.
|
static int |
TYPE_CURRENCY_SINGLE
Represents a single currency symbol '¤'.
|
static int |
TYPE_CURRENCY_TRIPLE
Represents a triple currency symbol '¤¤¤'.
|
static int |
TYPE_MINUS_SIGN
Represents a minus sign symbol '-'.
|
static int |
TYPE_PERCENT
Represents a percent sign symbol '%'.
|
static int |
TYPE_PERMILLE
Represents a permille sign symbol '‰'.
|
static int |
TYPE_PLUS_SIGN
Represents a plus sign symbol '+'.
|
| Constructor and Description |
|---|
AffixUtils() |
| Modifier and Type | Method and Description |
|---|---|
static boolean |
containsOnlySymbolsAndIgnorables(CharSequence affixPattern,
UnicodeSet ignorables)
Returns whether the given affix pattern contains only symbols and ignorables as defined by the
given ignorables set.
|
static boolean |
containsType(CharSequence affixPattern,
int type)
Checks whether the given affix pattern contains at least one token of the given type, which is one
of the constants "TYPE_" in
AffixUtils. |
static String |
escape(CharSequence input)
Version of
AffixUtils.escape(java.lang.CharSequence, java.lang.StringBuilder) that returns a String, or null if input is null. |
static int |
escape(CharSequence input,
StringBuilder output)
Takes a string and escapes (quotes) characters that have special meaning in the affix pattern
syntax.
|
static int |
estimateLength(CharSequence patternString)
Estimates the number of code points present in an unescaped version of the affix pattern string
(one that would be returned by
AffixUtils.unescape(java.lang.CharSequence, org.graalvm.shadowed.com.ibm.icu.impl.FormattedStringBuilder, int, org.graalvm.shadowed.com.ibm.icu.impl.number.AffixUtils.SymbolProvider, org.graalvm.shadowed.com.ibm.icu.text.NumberFormat.Field)), assuming that all interpolated symbols consume
one code point and that currencies consume as many code points as their symbol width. |
static NumberFormat.Field |
getFieldForType(int type) |
static boolean |
hasCurrencySymbols(CharSequence affixPattern)
Checks whether the specified affix pattern has any unquoted currency symbols ("¤").
|
static void |
iterateWithConsumer(CharSequence affixPattern,
AffixUtils.TokenConsumer consumer)
Iterates over the affix pattern, calling the TokenConsumer for each token.
|
static String |
replaceType(CharSequence affixPattern,
int type,
char replacementChar)
Replaces all occurrences of tokens with the given type with the given replacement char.
|
static int |
unescape(CharSequence affixPattern,
FormattedStringBuilder output,
int position,
AffixUtils.SymbolProvider provider,
NumberFormat.Field field)
Executes the unescape state machine.
|
static int |
unescapedCount(CharSequence affixPattern,
boolean lengthOrCount,
AffixUtils.SymbolProvider provider)
Sames as
AffixUtils.unescape(java.lang.CharSequence, org.graalvm.shadowed.com.ibm.icu.impl.FormattedStringBuilder, int, org.graalvm.shadowed.com.ibm.icu.impl.number.AffixUtils.SymbolProvider, org.graalvm.shadowed.com.ibm.icu.text.NumberFormat.Field), but only calculates the length or code point count. |
public static final int TYPE_MINUS_SIGN
public static final int TYPE_PLUS_SIGN
public static final int TYPE_APPROXIMATELY_SIGN
public static final int TYPE_PERCENT
public static final int TYPE_PERMILLE
public static final int TYPE_CURRENCY_SINGLE
public static final int TYPE_CURRENCY_DOUBLE
public static final int TYPE_CURRENCY_TRIPLE
public static final int TYPE_CURRENCY_QUAD
public static final int TYPE_CURRENCY_QUINT
public static final int TYPE_CURRENCY_OVERFLOW
public static int estimateLength(CharSequence patternString)
AffixUtils.unescape(java.lang.CharSequence, org.graalvm.shadowed.com.ibm.icu.impl.FormattedStringBuilder, int, org.graalvm.shadowed.com.ibm.icu.impl.number.AffixUtils.SymbolProvider, org.graalvm.shadowed.com.ibm.icu.text.NumberFormat.Field)), assuming that all interpolated symbols consume
one code point and that currencies consume as many code points as their symbol width. Used for
computing padding width.patternString - The original string whose width will be estimated.public static int escape(CharSequence input, StringBuilder output)
Example input: "-$x"; example output: "'-'$x"
input - The string to be escaped.output - The string builder to which to append the escaped string.public static String escape(CharSequence input)
AffixUtils.escape(java.lang.CharSequence, java.lang.StringBuilder) that returns a String, or null if input is null.public static final NumberFormat.Field getFieldForType(int type)
public static int unescape(CharSequence affixPattern, FormattedStringBuilder output, int position, AffixUtils.SymbolProvider provider, NumberFormat.Field field)
AffixUtils.SymbolProvider, and inserts the result into
the FormattedStringBuilder at the requested location.
Example input: "'-'¤x"; example output: "-$x"
affixPattern - The original string to be unescaped.output - The FormattedStringBuilder to mutate with the result.position - The index into the FormattedStringBuilder to insert the the string.provider - An object to generate locale symbols.public static int unescapedCount(CharSequence affixPattern, boolean lengthOrCount, AffixUtils.SymbolProvider provider)
AffixUtils.unescape(java.lang.CharSequence, org.graalvm.shadowed.com.ibm.icu.impl.FormattedStringBuilder, int, org.graalvm.shadowed.com.ibm.icu.impl.number.AffixUtils.SymbolProvider, org.graalvm.shadowed.com.ibm.icu.text.NumberFormat.Field), but only calculates the length or code point count. More efficient
than AffixUtils.unescape(java.lang.CharSequence, org.graalvm.shadowed.com.ibm.icu.impl.FormattedStringBuilder, int, org.graalvm.shadowed.com.ibm.icu.impl.number.AffixUtils.SymbolProvider, org.graalvm.shadowed.com.ibm.icu.text.NumberFormat.Field) if you only need the length but not the string itself.affixPattern - The original string to be unescaped.lengthOrCount - true to count length (UTF-16 code units); false to count code pointsprovider - An object to generate locale symbols.public static boolean containsType(CharSequence affixPattern, int type)
AffixUtils.affixPattern - The affix pattern to check.type - The token type.public static boolean hasCurrencySymbols(CharSequence affixPattern)
affixPattern - The string to check for currency symbols.public static String replaceType(CharSequence affixPattern, int type, char replacementChar)
affixPattern - The source affix pattern (does not get modified).type - The token type.replacementChar - The char to substitute in place of chars of the given token type.public static boolean containsOnlySymbolsAndIgnorables(CharSequence affixPattern, UnicodeSet ignorables)
public static void iterateWithConsumer(CharSequence affixPattern, AffixUtils.TokenConsumer consumer)