public final class SimpleFormatter
extends java.lang.Object
Factory methods throw exceptions for syntax errors and for too few or too many arguments/placeholders.
SimpleFormatter objects are immutable and can be safely cached like strings.
Example:
SimpleFormatter fmt = SimpleFormatter.compile("{1} '{born}' in {0}");
// Output: "paul {born} in england"
System.out.println(fmt.format("england", "paul"));
MessageFormat,
MessagePattern.ApostropheMode| Modifier and Type | Method and Description |
|---|---|
static SimpleFormatter |
compile(java.lang.CharSequence pattern)
Creates a formatter from the pattern string.
|
static SimpleFormatter |
compileMinMaxArguments(java.lang.CharSequence pattern,
int min,
int max)
Creates a formatter from the pattern string.
|
java.lang.String |
format(java.lang.CharSequence... values)
Formats the given values.
|
java.lang.StringBuilder |
formatAndAppend(java.lang.StringBuilder appendTo,
int[] offsets,
java.lang.CharSequence... values)
Formats the given values, appending to the appendTo builder.
|
java.lang.StringBuilder |
formatAndReplace(java.lang.StringBuilder result,
int[] offsets,
java.lang.CharSequence... values)
Formats the given values, replacing the contents of the result builder.
|
int |
getArgumentLimit() |
java.lang.String |
getTextWithNoArguments()
Returns the pattern text with none of the arguments.
|
java.lang.String |
toString()
Returns a string similar to the original pattern, only for debugging.
|
public static SimpleFormatter compile(java.lang.CharSequence pattern)
pattern - The pattern string.java.lang.IllegalArgumentException - for bad argument syntax.public static SimpleFormatter compileMinMaxArguments(java.lang.CharSequence pattern, int min, int max)
pattern - The pattern string.min - The pattern must have at least this many arguments.max - The pattern must have at most this many arguments.java.lang.IllegalArgumentException - for bad argument syntax and too few or too many arguments.public int getArgumentLimit()
public java.lang.String format(java.lang.CharSequence... values)
public java.lang.StringBuilder formatAndAppend(java.lang.StringBuilder appendTo,
int[] offsets,
java.lang.CharSequence... values)
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 java.lang.StringBuilder formatAndReplace(java.lang.StringBuilder result,
int[] offsets,
java.lang.CharSequence... values)
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 java.lang.String toString()
toString in class java.lang.Objectpublic java.lang.String getTextWithNoArguments()
Copyright © 2016 Unicode, Inc. and others.