Package org.python.core.stringlib
Class IntegerFormatter
java.lang.Object
org.python.core.stringlib.InternalFormat.Formatter
org.python.core.stringlib.IntegerFormatter
- All Implemented Interfaces:
Appendable
- Direct Known Subclasses:
IntegerFormatter.Traditional
A class that provides the implementation of integer formatting. In a limited way, it acts like a
StringBuilder to which text and one or more numbers may be appended, formatted according to the
format specifier supplied at construction. These are ephemeral objects that are not, on their
own, thread safe.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classA minor variation onIntegerFormatterto handle "traditional" %-formatting. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final InternalFormat.SpecFormat specification used by bin().static final InternalFormat.SpecFormat specification used by hex().static final InternalFormat.SpecFormat specification used by oct(). -
Constructor Summary
ConstructorsConstructorDescriptionIntegerFormatter(StringBuilder result, InternalFormat.Spec spec) Construct the formatter from a client-supplied buffer, to which the result will be appended, and a specification.Construct the formatter from a specification, allocating a buffer internally for the result. -
Method Summary
Modifier and TypeMethodDescriptionappend(char c) append(CharSequence csq) append(CharSequence csq, int start, int end) static PyStringConvert the object to binary according to the conventions of Python built-inbin().format(int value) Format an integer according to the specification represented by thisIntegerFormatter.format(BigInteger value) Format aBigInteger, which is the implementation type of Jythonlong, according to the specification represented by thisIntegerFormatter.static PyStringformatNumber(PyObject number, InternalFormat.Spec spec) Convert the object according to the conventions of Python built-inhex(), oroct().Methods inherited from class org.python.core.stringlib.InternalFormat.Formatter
alignmentNotAllowed, alternateFormNotAllowed, alternateFormNotAllowed, getPyResult, getResult, isBytes, notAllowed, notAllowed, pad, precisionNotAllowed, precisionTooLarge, setBytes, setStart, signNotAllowed, toString, unknownFormat, zeroPaddingNotAllowed
-
Field Details
-
BIN
Format specification used by bin(). -
OCT
Format specification used by oct(). -
HEX
Format specification used by hex().
-
-
Constructor Details
-
IntegerFormatter
Construct the formatter from a client-supplied buffer, to which the result will be appended, and a specification. SetsInternalFormat.Formatter.markto the end of the buffer.- Parameters:
result- destination bufferspec- parsed conversion specification
-
IntegerFormatter
Construct the formatter from a specification, allocating a buffer internally for the result.- Parameters:
spec- parsed conversion specification
-
-
Method Details
-
append
- Specified by:
appendin interfaceAppendable- Overrides:
appendin classInternalFormat.Formatter
-
append
- Specified by:
appendin interfaceAppendable- Overrides:
appendin classInternalFormat.Formatter
-
append
public IntegerFormatter append(CharSequence csq, int start, int end) throws IndexOutOfBoundsException - Specified by:
appendin interfaceAppendable- Overrides:
appendin classInternalFormat.Formatter- Throws:
IndexOutOfBoundsException
-
format
Format aBigInteger, which is the implementation type of Jythonlong, according to the specification represented by thisIntegerFormatter. The conversion type, and flags for grouping or base prefix are dealt with here. At the point this is used, we know theInternalFormat.Formatter.specis one of the integer types.- Parameters:
value- to convert- Returns:
- this object
-
format
Format an integer according to the specification represented by thisIntegerFormatter. The conversion type, and flags for grouping or base prefix are dealt with here. At the point this is used, we know theInternalFormat.Formatter.specis one of the integer types.- Parameters:
value- to convert- Returns:
- this object
-
bin
Convert the object to binary according to the conventions of Python built-inbin(). The object's __index__ method is called, and is responsible for raising the appropriate error (which the basePyObject.__index__()does).- Parameters:
number- to convert- Returns:
- PyString converted result
-
formatNumber
Convert the object according to the conventions of Python built-inhex(), oroct(). The object's__index__method is called, and is responsible for raising the appropriate error (which the basePyObject.__index__()does).- Parameters:
number- to convert- Returns:
- PyString converted result
-