lib/fmt+test: add {n}-placeholder printf family
Hare-shaped {} / {0} / {n:mods} parser + printf wrappers. APIs:
fprintf, fprintfln, fdprintf, fdprintfln, printf, printfln, errorfln,
fatalf, bsprintf. Parser handles indexed/positional placeholders,
alignment (- / default / =), pad-width, zero-pad (_05), radix (x X o
b), precision (.N for int pad / str trunc), sign markers (+, space),
and {{ / }} escape.
Internals: scandigits + scanmods drive a field-by-field dispatch into
formatfield, which inlines the field→formattable widen per-arm to
sidestep task #18 (24B return-by-value miscompile in for-loop
context). Render through formatraw + formatone over io.stream sinks.
formatone tail-pad uses a separate counter rather than mirroring
Hare's `?`-propagating loop: ww's memio.fixed returns partial-write
0 instead of errors::overflow, so the Hare shape would spin forever
on a full fixed buffer.
Deferred per drew's vet: asprintf/errorf (needs os.alloc, #16),
parametric width/precision dispatch (#16-family), float arm (#17),
log.printfln family wiring (#15).
Tests: 26 scenarios covering every placeholder shape, both arms of
fprintf's variadic dispatch (incl. bool/rune to pin #18 regression),
bsprintf overflow + width-against-full-buffer, closed-stream.
This commit is contained in:
@@ -32,8 +32,10 @@ Signatures mirror Hare too, modulo:
|
||||
slice with `xs...` (`fdprintln(fd, args...)`). The bare `T...` form
|
||||
in tagged unions still means spread-flatten (`(...inner | E)`);
|
||||
the two uses don't overlap because `T...` only attaches to a
|
||||
*param* decl. `lib/fmt` is intentionally print-string-only — no
|
||||
`printf`-family.
|
||||
*param* decl. `lib/fmt` ships both the print family (`print` /
|
||||
`println` / `fprint` / `fprintln`) and the {n}-placeholder family
|
||||
(`printf` / `fprintf` / `bsprintf` / `fatalf`); the `%`-parametric
|
||||
modifier form is parsed but its `*mods` arg slot aborts on dispatch.
|
||||
|
||||
- `(T | U)` sum-typed parameters dispatch via `match` inside the
|
||||
callee. `strings.byteindex(haystack: str, needle: (str | rune))`,
|
||||
|
||||
Reference in New Issue
Block a user