Documentation
¶
Overview ¶
Package format ports cpython/Python/formatter_unicode.c. It implements the format-spec mini-language used by str.format, f-strings, and the format() builtin:
[[fill]align][sign][z][#][0][width][grouping][.precision][type]
All four formatters - string, int, float, and (later) complex - share the same parser. The float formatter delegates digit generation to pystrconv.FormatFloat for IEEE-754 round-trip parity with CPython.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidSpec = errors.New("format: invalid format specifier")
ErrInvalidSpec is returned by ParseSpec when the spec violates the grammar.
Functions ¶
func FormatFloat ¶
FormatFloat renders v under spec. Mirrors format_float_internal.
CPython: Python/formatter_unicode.c:L1290 format_float_internal
Types ¶
type Spec ¶
type Spec struct {
Fill rune
Align byte // '<', '>', '=', '^', or 0 if default
Sign byte // '+', '-', ' ', or 0
NoNegZero bool
Alt bool
Zero bool
Width int // -1 if unspecified
Thousands byte // ',', '_', or 0
Precision int // -1 if unspecified
Type byte // 0 if unspecified
}
Spec is the parsed form of a format-spec mini-language string.
CPython: Python/formatter_unicode.c:L18 InternalFormatSpec