silo:std.fmt

Source src/silo:std.fmt

1##! Format-spec machinery shared by Display/Debug/LowerHex/Binary and the `format` macro.
2##!
3##! Declares `FmtSpec`, the alignment and sign unions, and the
4##! default-spec constructor.
5
6:use
7  :open core AnyInt AnyUInt Bool Char Option None Some Str
8:end
9
10# si[impl format.spec]
11##(
12Parameter record threaded through every format-trait method. Impls MUST honour
13`.align`, `.width`, `.precision`, `.fill` when meaningful for the target type.
14The `.alt` flag enables `{:#x}` / `{:#b}` style alternate-form rendering.
15)#
16:record(pub) FmtSpec
17  .width     (Option AnyUInt)
18  .precision (Option AnyUInt)
19  .fill      Char
20  .align     Alignment
21  .sign      SignMode
22  .alt       Bool
23:end
24
25## Horizontal placement of a rendered value within its allotted width.
26:union(pub) Alignment
27  | Left
28  | Right
29  | Center
30:end
31
32## Numeric sign-rendering mode: implicit on negatives (Auto), always shown (Always), or leading space on positives (Space).
33:union(pub) SignMode
34  | Auto
35  | Always
36  | Space
37:end
38
39# si[impl format.spec.default]
40## The fill/align/sign/precision/width combination the `format` macro passes for every
41## placeholder that has no explicit specifiers. Fill defaults to ASCII space, alignment
42## `Left`, sign `Auto`, alt `false`.
43:fn(pub) default-fmt-spec ( -> FmtSpec )
44  None None ' ' Left Auto false FmtSpec
45:end