public final class SimpleFormatterImpl extends Object
SimpleFormatter
with only static methods, to avoid wrapper objects.
This class "compiles" pattern strings into a binary format and implements formatting etc. based on that.
Format: Index 0: One more than the highest argument number. Followed by zero or more arguments or literal-text segments.
An argument is stored as its number, less than ARG_NUM_LIMIT. A literal-text segment is stored as its length (at least 1) offset by ARG_NUM_LIMIT, followed by that many chars.
| Modifier and Type | Class and Description |
|---|---|
static class |
SimpleFormatterImpl.IterInternal
Internal iterator interface for maximum efficiency.
|
| Modifier and Type | Method and Description |
|---|---|
static String |
compileToStringMinMaxArguments(CharSequence pattern,
StringBuilder sb,
int min,
int max)
Creates a compiled form of the pattern string, for use with appropriate static methods.
|
static StringBuilder |
formatAndAppend(String compiledPattern,
StringBuilder appendTo,
int[] offsets,
CharSequence... values)
Formats the given values, appending to the appendTo builder.
|
static StringBuilder |
formatAndReplace(String compiledPattern,
StringBuilder result,
int[] offsets,
CharSequence... values)
Formats the given values, replacing the contents of the result builder.
|
static String |
formatCompiledPattern(String compiledPattern,
CharSequence... values)
Formats the given values.
|
static int |
formatPrefixSuffix(String compiledPattern,
Format.Field field,
int start,
int end,
FormattedStringBuilder output)
Special case for using FormattedStringBuilder with patterns with 0 or 1 argument.
|
static String |
formatRawPattern(String pattern,
int min,
int max,
CharSequence... values)
Formats the not-compiled pattern with the given values.
|
static int |
getArgumentLimit(String compiledPattern) |
static int |
getLength(String compiledPattern,
boolean codePoints)
Returns the length of the pattern text with none of the arguments.
|
static int |
getPrefixLength(String compiledPattern)
Returns the length in code units of the pattern text up until the first argument.
|
static String |
getTextWithNoArguments(String compiledPattern)
Returns the pattern text with none of the arguments.
|
public static String compileToStringMinMaxArguments(CharSequence pattern, StringBuilder sb, int min, int max)
pattern - The pattern string.sb - A StringBuilder instance which may or may not be used.min - The pattern must have at least this many arguments.max - The pattern must have at most this many arguments.IllegalArgumentException - for bad argument syntax and too few or too many arguments.public static int getArgumentLimit(String compiledPattern)
compiledPattern - Compiled form of a pattern string.public static String formatCompiledPattern(String compiledPattern, CharSequence... values)
compiledPattern - Compiled form of a pattern string.public static String formatRawPattern(String pattern, int min, int max, CharSequence... values)
pattern - Not-compiled form of a pattern string.min - The pattern must have at least this many arguments.max - The pattern must have at most this many arguments.IllegalArgumentException - for bad argument syntax and too few or too many arguments.public static StringBuilder formatAndAppend(String compiledPattern, StringBuilder appendTo, int[] offsets, CharSequence... values)
compiledPattern - Compiled form of a pattern string.appendTo - Gets the formatted pattern and values appended.offsets - offsets[i] receives the offset of where
values[i] replaced pattern argument {i}.
Can be null, or can be shorter or longer than values.
If there is no {i} in the pattern, then offsets[i] is set to -1.values - The argument values.
An argument value must not be the same object as appendTo.
values.length must be at least getArgumentLimit().
Can be null if getArgumentLimit()==0.public static StringBuilder formatAndReplace(String compiledPattern, StringBuilder result, int[] offsets, CharSequence... values)
compiledPattern - Compiled form of a pattern string.result - Gets its contents replaced by the formatted pattern and values.offsets - offsets[i] receives the offset of where
values[i] replaced pattern argument {i}.
Can be null, or can be shorter or longer than values.
If there is no {i} in the pattern, then offsets[i] is set to -1.values - The argument values.
An argument value may be the same object as result.
values.length must be at least getArgumentLimit().public static String getTextWithNoArguments(String compiledPattern)
compiledPattern - Compiled form of a pattern string.public static int getLength(String compiledPattern, boolean codePoints)
compiledPattern - Compiled form of a pattern string.codePoints - true to count code points; false to count code units.public static int getPrefixLength(String compiledPattern)
compiledPattern - Compiled form of a pattern string.public static int formatPrefixSuffix(String compiledPattern, Format.Field field, int start, int end, FormattedStringBuilder output)
compiledPattern - Compiled form of a pattern string.field - Field to use when adding chars to the output.start - The start index of the argument already in the output string.end - The end index of the argument already in the output string.output - Destination for formatted output.