Top Description Fields Constructors Methods
org.python.core.stringlib

public abstract Class TextFormatter

extends AbstractFormatter
Class Inheritance
Known Direct Subclasses
org.python.core.PyUnicode.StrFormatter
Imports
org.python.core.PySequence, org.python.core.stringlib.InternalFormat.Spec

A class that provides the implementation of 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.

Field Summary

Inherited from org.python.core.stringlib.InternalFormat.AbstractFormatter:
byteslenSignlenWholemarkresultspecstart

Constructor Summary

AccessConstructor and Description
public
TextFormatter(StringBuilder
destination buffer
result
,
InternalFormat.Spec
parsed conversion specification
spec
)

Construct the formatter from a client-supplied buffer, to which the result will be appended, and a specification.

public
TextFormatter(InternalFormat.Spec
parsed conversion specification
spec
)

Construct the formatter from a specification, allocating a buffer internally for the result.

Method Summary

Modifier and TypeMethod and Description
public TextFormatter
append(char
The character to append
c
)

Overrides org.python.core.stringlib.InternalFormat.AbstractFormatter.append.

Implements java.lang.Appendable.append.

Appends the specified character to this Appendable.
public TextFormatter
public TextFormatter
append(CharSequence
The character sequence to append. If csq is null, then the four characters "null" are appended to this Appendable.
csq
)

Overrides org.python.core.stringlib.InternalFormat.AbstractFormatter.append.

Implements java.lang.Appendable.append.

Appends the specified character sequence to this Appendable.
public TextFormatter
append(CharSequence
The character sequence from which a subsequence will be appended. If csq is null, then characters will be appended as if csq contained the four characters "null".
csq
,
int
The index of the first character in the subsequence
start
,
int
The index of the character following the last character in the subsequence
end
)

Overrides org.python.core.stringlib.InternalFormat.AbstractFormatter.append.

Implements java.lang.Appendable.append.

Appends a subsequence of the specified character sequence to this Appendable.
public TextFormatter

Returns:

this TextFormatter object
format
(String
to format
value
)

Format the given String into the result buffer.

public TextFormatter

Returns:

this TextFormatter object
format
(PySequence.OfInt
to format
value
)

Format the given String into the result buffer.

public TextFormatter
pad()

Overrides org.python.core.stringlib.InternalFormat.AbstractFormatter.pad.

Pad the result so far (defined as the contents of result from mark to the end) using the alignment, target width and fill character defined in spec.
Inherited from org.python.core.stringlib.InternalFormat.AbstractFormatter:
alignmentNotAllowedalternateFormNotAllowedalternateFormNotAllowedformatgetResultgroupDigitsisBytesmakeSpaceAtnotAllowednotAllowednotAllowedpadprecisionNotAllowedprecisionTooLargeresetsectionLengthssetBytessetStartsignNotAllowedtoStringunknownFormatuppercasezeroPadAfterSignWithGroupingFixupzeroPaddingNotAllowed

Constructor Detail

TextFormatterback to summary
public TextFormatter(StringBuilder result, InternalFormat.Spec spec)

Construct the formatter from a client-supplied buffer, to which the result will be appended, and a specification. Sets mark to the end of the buffer.

Parameters
result:StringBuilder

destination buffer

spec:InternalFormat.Spec

parsed conversion specification

TextFormatterback to summary
public TextFormatter(InternalFormat.Spec spec)

Construct the formatter from a specification, allocating a buffer internally for the result.

Parameters
spec:InternalFormat.Spec

parsed conversion specification

Method Detail

appendback to summary
public TextFormatter append(char c)

Overrides org.python.core.stringlib.InternalFormat.AbstractFormatter.append.

Implements java.lang.Appendable.append.

Doc from java.lang.Appendable.append.

Appends the specified character to this Appendable.

Parameters
c:char

The character to append

Returns:TextFormatter

A reference to this Appendable

Annotations
@Override
appendback to summary
public TextFormatter append(int c)

Overrides org.python.core.stringlib.InternalFormat.AbstractFormatter.append.

Annotations
@Override
appendback to summary
public TextFormatter append(CharSequence csq)

Overrides org.python.core.stringlib.InternalFormat.AbstractFormatter.append.

Implements java.lang.Appendable.append.

Doc from java.lang.Appendable.append.

Appends the specified character sequence to this Appendable.

Depending on which class implements the character sequence csq, the entire sequence may not be appended. For instance, if csq is a java.nio.CharBuffer then the subsequence to append is defined by the buffer's position and limit.

Parameters
csq:CharSequence

The character sequence to append. If csq is null, then the four characters "null" are appended to this Appendable.

Returns:TextFormatter

A reference to this Appendable

Annotations
@Override
appendback to summary
public TextFormatter append(CharSequence csq, int start, int end) throws IndexOutOfBoundsException

Overrides org.python.core.stringlib.InternalFormat.AbstractFormatter.append.

Implements java.lang.Appendable.append.

Doc from java.lang.Appendable.append.

Appends a subsequence of the specified character sequence to this Appendable.

An invocation of this method of the form out.append(csq, start, end) when csq is not null, behaves in exactly the same way as the invocation

    out.append(csq.subSequence(start, end)) 
Parameters
csq:CharSequence

The character sequence from which a subsequence will be appended. If csq is null, then characters will be appended as if csq contained the four characters "null".

start:int

The index of the first character in the subsequence

end:int

The index of the character following the last character in the subsequence

Returns:TextFormatter

A reference to this Appendable

Annotations
@Override
Exceptions
IndexOutOfBoundsException:
If start or end are negative, start is greater than end, or end is greater than csq.length()
formatback to summary
public TextFormatter format(String value)

Format the given 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 chars. The method deals with this correctly, essentially by not counting the high-surrogates in the allowance. The final value of lenWhole counts the UTF-16 units added.

Parameters
value:String

to format

Returns:TextFormatter

this TextFormatter object

formatback to summary
public TextFormatter format(PySequence.OfInt value)

Format the given 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 chars. The method deals with this correctly, essentially by not counting the high-surrogates in the allowance. The final value of lenWhole counts the UTF-16 units added.

Parameters
value:PySequence.OfInt

to format

Returns:TextFormatter

this TextFormatter object

padback to summary
public TextFormatter pad()

Overrides org.python.core.stringlib.InternalFormat.AbstractFormatter.pad.

Doc from org.python.core.stringlib.InternalFormat.AbstractFormatter.pad.

Pad the result so far (defined as the contents of result from mark to the end) using the alignment, target width and fill character defined in 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 start or lenWhole as follows.

Effect of padding on start or lenWhole
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
Note that in the "pad after sign" mode, only the last number into the buffer receives the padding. This padding gets incorporated into the whole part of the number. (In other modes, the padding is around result[mark:].) When this would not be appropriate, it is up to the client to disallow this (which complex does).
Returns:TextFormatter

this Formatter object

Annotations
@Override