Format Syntax
format_string := text [ maybe_format text ] *
maybe_format := '{' '{' | '}' '}' | format
format := '{' [ argument ] [ ':' format_spec ] [ ws ] * '}'
argument := integer | identifier
format_spec := [[fill]align][sign]['#']['0'][width]['.' precision]type
fill := character
align := '<' | '^' | '>'
sign := '+' | '-'
width := count
precision := count | '*'
type := '' | '?' | 'x?' | 'X?' | identifier
count := parameter | integer
parameter := argument '$'
{[argument]':'[[fill] align][sign]['#'][width [$]]['.' precision [$]][type]}
-
argument => number(0, 1, 2, ..) or name
-
fill => the character to fill empty spaces, if
width
is specified -
align => left(<), center (^), right (>), if
width
is specified -
width [$] => width to be padded with
fill
(default to space), can be number or paramater, if paramater '$' must be used -
sign =>
+
can be used for numeric types to display sign (negative sign is only displayed for signed values) -
precision [$] => decimal digits for number or max width for non-number, can be number or paramater, if paramater '$' must be used.
.*
means that this {...} is associated with two format inputs rather than one: -
#
indicates that the "alternate” form of printing should be used. The alternate forms are:#?
pretty-print the Debug formatting (adds linebreaks and indentation)#x
precedes the argument with a 0x#X
precedes the argument with a 0x#b
precedes the argument with a 0b#o
precedes the argument with a 0o
Formatting Traits
- nothing ⇒ Display
- ? ⇒ Debug
- x? ⇒ Debug with lower-case hexadecimal integers
- X? ⇒ Debug with upper-case hexadecimal integers
- o ⇒ Octal
- x ⇒ LowerHex
- X ⇒ UpperHex
- p ⇒ Pointer
- b ⇒ Binary
- e ⇒ LowerExp
- E ⇒ UpperExp