public class TextFormatter extends InternalFormat.Formatter
str
and unicode
formatting.
In a limited way, it acts like a StringBuilder to which text, formatted according to the format
specifier supplied at construction. These are ephemeral objects that are not, on their own,
thread safe.Constructor and Description |
---|
TextFormatter(InternalFormat.Spec spec)
Construct the formatter from a specification, allocating a buffer internally for the result.
|
TextFormatter(java.lang.StringBuilder result,
InternalFormat.Spec spec)
Construct the formatter from a client-supplied buffer, to which the result will be appended,
and a specification.
|
Modifier and Type | Method and Description |
---|---|
TextFormatter |
append(char c) |
TextFormatter |
append(java.lang.CharSequence csq) |
TextFormatter |
append(java.lang.CharSequence csq,
int start,
int end) |
TextFormatter |
format(java.lang.String value)
Format the given
String into the result buffer. |
TextFormatter |
pad()
Pad the result so far (defined as the contents of
InternalFormat.Formatter.result from InternalFormat.Formatter.mark to
the end) using the alignment, target width and fill character defined in InternalFormat.Formatter.spec . |
alignmentNotAllowed, alternateFormNotAllowed, alternateFormNotAllowed, getPyResult, getResult, isBytes, notAllowed, notAllowed, precisionNotAllowed, precisionTooLarge, setBytes, setStart, signNotAllowed, toString, unknownFormat, zeroPaddingNotAllowed
public TextFormatter(java.lang.StringBuilder result, InternalFormat.Spec spec)
InternalFormat.Formatter.mark
to the end of the buffer.result
- destination bufferspec
- parsed conversion specificationpublic TextFormatter(InternalFormat.Spec spec)
spec
- parsed conversion specificationpublic TextFormatter append(char c)
append
in interface java.lang.Appendable
append
in class InternalFormat.Formatter
public TextFormatter append(java.lang.CharSequence csq)
append
in interface java.lang.Appendable
append
in class InternalFormat.Formatter
public TextFormatter append(java.lang.CharSequence csq, int start, int end) throws java.lang.IndexOutOfBoundsException
append
in interface java.lang.Appendable
append
in class InternalFormat.Formatter
java.lang.IndexOutOfBoundsException
public TextFormatter format(java.lang.String value)
String
into the result
buffer. Largely, this is a
matter of copying the value of the argument, but a subtlety arises when the string contains
supplementary (non-BMP) Unicode characters, which are represented as surrogate pairs. The
precision specified in the format relates to a count of Unicode characters (code points), not
Java char
s. The method deals with this correctly, essentially by not counting
the high-surrogates in the allowance. The final value of InternalFormat.Formatter.lenWhole
counts the UTF-16
units added.value
- to formatTextFormatter
objectpublic TextFormatter pad()
InternalFormat.Formatter
InternalFormat.Formatter.result
from InternalFormat.Formatter.mark
to
the end) using the alignment, target width and fill character defined in InternalFormat.Formatter.spec
.
The action of padding will increase the length of this segment to the target width, if
that is greater than the current length.
When the padding method has decided that that it needs to add n padding characters, it
will affect InternalFormat.Formatter.start
or InternalFormat.Formatter.lenWhole
as follows.
align | meaning | start | lenWhole | result.length() |
---|---|---|---|---|
< |
left-aligned | +0 | +0 | +n |
> |
right-aligned | +n | +0 | +n |
^ |
centred | +(n/2) | +0 | +n |
= |
pad after sign | +0 | +n | +n |
result[mark:]
.) When this would not be
appropriate, it is up to the client to disallow this (which complex
does).pad
in class InternalFormat.Formatter