Class AffixUtils
java.lang.Object
org.graalvm.shadowed.com.ibm.icu.impl.number.AffixUtils
Performs manipulations on affix patterns: the prefix and suffix strings associated with a decimal
format pattern. For example:
To manually iterate over tokens in a literal string, use the following pattern, which is designed to
be efficient.
| 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;
}
}
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfacestatic interface -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intRepresents a double currency symbol '¤¤'.static final intRepresents a sequence of six or more currency symbols.static final intRepresents a quadruple currency symbol '¤¤¤¤'.static final intRepresents a quintuple currency symbol '¤¤¤¤¤'.static final intRepresents a single currency symbol '¤'.static final intRepresents a triple currency symbol '¤¤¤'.static final intRepresents a minus sign symbol '-'.static final intRepresents a percent sign symbol '%'.static final intRepresents a permille sign symbol '‰'.static final intRepresents a plus sign symbol '+'. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleancontainsOnlySymbolsAndIgnorables(CharSequence affixPattern, UnicodeSet ignorables) Returns whether the given affix pattern contains only symbols and ignorables as defined by the given ignorables set.static booleancontainsType(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_" inAffixUtils.static Stringescape(CharSequence input) Version ofescape(CharSequence, StringBuilder)that returns a String, or null if input is null.static intescape(CharSequence input, StringBuilder output) Takes a string and escapes (quotes) characters that have special meaning in the affix pattern syntax.static intestimateLength(CharSequence patternString) Estimates the number of code points present in an unescaped version of the affix pattern string (one that would be returned byunescape(CharSequence, FormattedStringBuilder, int, AffixUtils.SymbolProvider, NumberFormat.Field)), assuming that all interpolated symbols consume one code point and that currencies consume as many code points as their symbol width.static final NumberFormat.FieldgetFieldForType(int type) static booleanhasCurrencySymbols(CharSequence affixPattern) Checks whether the specified affix pattern has any unquoted currency symbols ("¤").static voiditerateWithConsumer(CharSequence affixPattern, AffixUtils.TokenConsumer consumer) Iterates over the affix pattern, calling the TokenConsumer for each token.static StringreplaceType(CharSequence affixPattern, int type, char replacementChar) Replaces all occurrences of tokens with the given type with the given replacement char.static intunescape(CharSequence affixPattern, FormattedStringBuilder output, int position, AffixUtils.SymbolProvider provider, NumberFormat.Field field) Executes the unescape state machine.static intunescapedCount(CharSequence affixPattern, boolean lengthOrCount, AffixUtils.SymbolProvider provider) Sames asunescape(CharSequence, FormattedStringBuilder, int, AffixUtils.SymbolProvider, NumberFormat.Field), but only calculates the length or code point count.
-
Field Details
-
TYPE_MINUS_SIGN
public static final int TYPE_MINUS_SIGNRepresents a minus sign symbol '-'.- See Also:
-
TYPE_PLUS_SIGN
public static final int TYPE_PLUS_SIGNRepresents a plus sign symbol '+'.- See Also:
-
TYPE_APPROXIMATELY_SIGN
public static final int TYPE_APPROXIMATELY_SIGN- See Also:
-
TYPE_PERCENT
public static final int TYPE_PERCENTRepresents a percent sign symbol '%'.- See Also:
-
TYPE_PERMILLE
public static final int TYPE_PERMILLERepresents a permille sign symbol '‰'.- See Also:
-
TYPE_CURRENCY_SINGLE
public static final int TYPE_CURRENCY_SINGLERepresents a single currency symbol '¤'.- See Also:
-
TYPE_CURRENCY_DOUBLE
public static final int TYPE_CURRENCY_DOUBLERepresents a double currency symbol '¤¤'.- See Also:
-
TYPE_CURRENCY_TRIPLE
public static final int TYPE_CURRENCY_TRIPLERepresents a triple currency symbol '¤¤¤'.- See Also:
-
TYPE_CURRENCY_QUAD
public static final int TYPE_CURRENCY_QUADRepresents a quadruple currency symbol '¤¤¤¤'.- See Also:
-
TYPE_CURRENCY_QUINT
public static final int TYPE_CURRENCY_QUINTRepresents a quintuple currency symbol '¤¤¤¤¤'.- See Also:
-
TYPE_CURRENCY_OVERFLOW
public static final int TYPE_CURRENCY_OVERFLOWRepresents a sequence of six or more currency symbols.- See Also:
-
-
Constructor Details
-
AffixUtils
public AffixUtils()
-
-
Method Details
-
estimateLength
Estimates the number of code points present in an unescaped version of the affix pattern string (one that would be returned byunescape(CharSequence, FormattedStringBuilder, int, AffixUtils.SymbolProvider, 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.- Parameters:
patternString- The original string whose width will be estimated.- Returns:
- The length of the unescaped string.
-
escape
Takes a string and escapes (quotes) characters that have special meaning in the affix pattern syntax. This function does not reverse-lookup symbols.Example input: "-$x"; example output: "'-'$x"
- Parameters:
input- The string to be escaped.output- The string builder to which to append the escaped string.- Returns:
- The number of chars (UTF-16 code units) appended to the output.
-
escape
Version ofescape(CharSequence, StringBuilder)that returns a String, or null if input is null. -
getFieldForType
-
unescape
public static int unescape(CharSequence affixPattern, FormattedStringBuilder output, int position, AffixUtils.SymbolProvider provider, NumberFormat.Field field) Executes the unescape state machine. Replaces the unquoted characters "-", "+", "%", "‰", and "¤" with the corresponding symbols provided by theAffixUtils.SymbolProvider, and inserts the result into the FormattedStringBuilder at the requested location.Example input: "'-'¤x"; example output: "-$x"
- Parameters:
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.- Returns:
- The length of the string added to affixPattern.
-
unescapedCount
public static int unescapedCount(CharSequence affixPattern, boolean lengthOrCount, AffixUtils.SymbolProvider provider) Sames asunescape(CharSequence, FormattedStringBuilder, int, AffixUtils.SymbolProvider, NumberFormat.Field), but only calculates the length or code point count. More efficient thanunescape(CharSequence, FormattedStringBuilder, int, AffixUtils.SymbolProvider, NumberFormat.Field)if you only need the length but not the string itself.- Parameters:
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.- Returns:
- The number of code points in the unescaped string.
-
containsType
Checks whether the given affix pattern contains at least one token of the given type, which is one of the constants "TYPE_" inAffixUtils.- Parameters:
affixPattern- The affix pattern to check.type- The token type.- Returns:
- true if the affix pattern contains the given token type; false otherwise.
-
hasCurrencySymbols
Checks whether the specified affix pattern has any unquoted currency symbols ("¤").- Parameters:
affixPattern- The string to check for currency symbols.- Returns:
- true if the literal has at least one unquoted currency symbol; false otherwise.
-
replaceType
Replaces all occurrences of tokens with the given type with the given replacement char.- Parameters:
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.- Returns:
- A string containing the new affix pattern.
-
containsOnlySymbolsAndIgnorables
public 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. -
iterateWithConsumer
public static void iterateWithConsumer(CharSequence affixPattern, AffixUtils.TokenConsumer consumer) Iterates over the affix pattern, calling the TokenConsumer for each token.
-