aboutsummaryrefslogtreecommitdiff
path: root/lib/std/fmt.zig
AgeCommit message (Collapse)Author
2025-11-06test: add test case for enum-literal with '{t}' formatsnoire
Co-authored-by: Ryan Liptak <squeek502@hotmail.com>
2025-09-19std.fmt: migrate bufPrintZ to bufPrintSentinel (#25260)John Benediktsson
2025-09-04Reenable vector tests for armeb/thumbebLuna Schwalbe
https://github.com/ziglang/zig/issues/22060 has been fixed by upstream.
2025-09-04Reenable std.fmt.test.vector for riscv64Luna Schwalbe
The vector codegen issue as described in https://github.com/ziglang/zig/issues/4486 has been fixed upstream.
2025-08-31std.fmt: delete deprecated APIsAndrew Kelley
std.fmt.Formatter -> std.fmt.Alt std.fmt.format -> std.Io.Writer.print
2025-08-29std.Io: delete GenericReaderAndrew Kelley
and delete deprecated alias std.io
2025-08-08zig std: fix build failuresAndrew Kelley
2025-07-29disable more failing testsmlugg
Wow, *lots* of backends were reliant on Sema doing the heavy lifting for them. CBE, Wasm, and SPIR-V have all regressed in places now that they actually need to, like, initialize unions and such.
2025-07-09std: fmt.format to io.Writer.printAndrew Kelley
allows reverting format -> deprecatedFormat, plus I think this is a nicer place for the function.
2025-07-09chicken out and allow ascii string alignmentAndrew Kelley
2025-07-09std: replace formatInteger with formatNumberAndrew Kelley
2025-07-09eliminate all uses of std.io.Writer.count except for CBEAndrew Kelley
2025-07-08std.fmt: refactor to remove cacheStringAndrew Kelley
when this kind of trick is needed, do it inline
2025-07-07std.io.Writer.printValue: rework logicAndrew Kelley
Alignment and fill options only apply to numbers. Rework the implementation to mainly branch on the format string rather than the type information. This is more straightforward to maintain and more straightforward for comptime evaluation. Enums support being printed as decimal, hexadecimal, octal, and binary. `formatInteger` is another possible format method that is unconditionally called when the value type is struct and one of the integer-printing format specifiers are used.
2025-07-07std.fmt: fully remove format string from format methodsAndrew Kelley
Introduces `std.fmt.alt` which is a helper for calling alternate format methods besides one named "format".
2025-07-07std.fmt.format: use {t} for tag name rather than {s}Andrew Kelley
prevents footgun when formatted type changes from string to enum
2025-07-07std.io.Writer.Allocating: rename interface to writerAndrew Kelley
2025-07-07std: formatted printing no longer prints type namesAndrew Kelley
for structs, enums, and unions. auto untagged unions are no longer printed as pointers; instead they are printed as "{ ... }". extern and packed untagged unions have each field printed, similar to what gdb does. also fix bugs in delimiter based reading
2025-07-07std.fmt: breaking API changesAndrew Kelley
added adapter to AnyWriter and GenericWriter to help bridge the gap between old and new API make std.testing.expectFmt work at compile-time std.fmt no longer has a dependency on std.unicode. Formatted printing was never properly unicode-aware. Now it no longer pretends to be. Breakage/deprecations: * std.fs.File.reader -> std.fs.File.deprecatedReader * std.fs.File.writer -> std.fs.File.deprecatedWriter * std.io.GenericReader -> std.io.Reader * std.io.GenericWriter -> std.io.Writer * std.io.AnyReader -> std.io.Reader * std.io.AnyWriter -> std.io.Writer * std.fmt.format -> std.fmt.deprecatedFormat * std.fmt.fmtSliceEscapeLower -> std.ascii.hexEscape * std.fmt.fmtSliceEscapeUpper -> std.ascii.hexEscape * std.fmt.fmtSliceHexLower -> {x} * std.fmt.fmtSliceHexUpper -> {X} * std.fmt.fmtIntSizeDec -> {B} * std.fmt.fmtIntSizeBin -> {Bi} * std.fmt.fmtDuration -> {D} * std.fmt.fmtDurationSigned -> {D} * {} -> {f} when there is a format method * format method signature - anytype -> *std.io.Writer - inferred error set -> error{WriteFailed} - options -> (deleted) * std.fmt.Formatted - now takes context type explicitly - no fmt string
2025-04-27chore(std.mem): Rename `trimLeft` and `trimRight`Shun Sakai
Rename `trimLeft` to `trimStart`, and `trimRight` to `trimEnd`. `trimLeft` and `trimRight` functions remain as deprecated aliases for these new names.
2025-03-24fix(std/fmt.zig): fix overflow in fmtDurationSignedGasInfinity
fixes #23315
2025-02-12std.fmt.digits2: optimize for ReleaseSmallwooster0
Difference: ``` $ cat x.zig const std = @import("std"); pub const std_options = std.Options{ .keep_sigpipe = true }; pub fn main() void { std.io.getStdOut().writer().print("{d}\n", .{@intFromPtr(std.os.argv.ptr)}) catch {}; } $ zig build-exe x.zig -OReleaseSmall -fsingle-threaded -fno-unwind-tables && wc -c x 2576 x $ zig build-exe x.zig -OReleaseSmall -fsingle-threaded -fno-unwind-tables --zig-lib-dir ../zig/lib && wc -c x 2424 x ```
2025-02-11std.fmt: Add unit tests for all methods in the Parser structsaurabh
2025-02-10std.fmt: remove placeholders from binaryrpkak
2025-01-26std: check max depth for vector type in formatTypethejohnny5
2025-01-16all: update to `std.builtin.Type.{Pointer,Array,StructField}` field renamesmlugg
2025-01-16all: update to `std.builtin.Type.Pointer.Size` field renamesmlugg
This was done by regex substitution with `sed`. I then manually went over the entire diff and fixed any incorrect changes. This diff also changes a lot of `callconv(.C)` to `callconv(.c)`, since my regex happened to also trigger here. I opted to leave these changes in, since they *are* a correct migration, even if they're not the one I was trying to do!
2025-01-06std: Disable some tests affected by #22060 for thumbeb too.Alex Rønne Petersen
2024-12-13std: Disable some vector-related tests on armeb.Alex Rønne Petersen
https://github.com/ziglang/zig/issues/22060
2024-11-24Remove unused `buf` field from `std.fmt.Parser` (#21994)Andrew Barchuk
And make the initialization less error prone by removing a default for iter, which is required for a functional parser std: Add a brief doc comment for `std.fmt.Parser`
2024-11-18std.format: properly handle vectors of pointersgooncreeper
2024-10-30std.fmt: Fix compile error in Parser.peek() (#20532)Simon Ekström
2024-09-26remove formatted panicsAndrew Kelley
implements #17969
2024-09-08std.fmt: Update casing of a few functions to match naming style guideLinus Groh
2024-09-02std.fmt.fmtIntSize*: document when precision is ignoredfdfdjfk3
2024-08-28std: update `std.builtin.Type` fields to follow naming conventionsmlugg
The compiler actually doesn't need any functional changes for this: Sema does reification based on the tag indices of `std.builtin.Type` already! So, no zig1.wasm update is necessary. This change is necessary to disallow name clashes between fields and decls on a type, which is a prerequisite of #9938.
2024-07-20fix std.fmt.hexAndrew Kelley
2024-07-20add std.fmt.hexAndrew Kelley
converts an unsigned integer into an array
2024-07-17format: do not force user to provide an alignment field when it's not ↵eric-saintetienne
necessary (#19049) * format: fix default character when no alignment When no alignment is specified, the character that should be used is the fill character that is otherwise provided, not space. This is closer to the default that C programmers (and other languages) use: "04x" fills with zeroes (in zig as of today x:04 fills with spaces) Test: const std = @import("std"); const expectFmt = std.testing.expectFmt; test "fmt.defaultchar.no-alignment" { // as of today the following test passes: try expectFmt("0x00ff", "0x{x:0>4}", .{255}); // as of today the following test fails (returns "0x ff" instead) try expectFmt("0x00ff", "0x{x:04}", .{255}); } * non breaking improvement of string formatting * improved comment * simplify the code a little * small improvement around how characters identified as valid are consumed
2024-05-27Progress: fix compile errors on windowsJacob Young
Works for `zig build-exe`, IPC still not implemented yet.
2024-05-21use constant in formatTypeorvit
2024-04-23Update fmt.zig testsSean
Changed uses of `std.testing.expect` to `std.testing.expectEqual`, `std.testing.expectError`, and `std.testing.expectEqualStrings` where appropriate
2024-03-25compiler: implement analysis-local comptime-mutable memorymlugg
This commit changes how we represent comptime-mutable memory (`comptime var`) in the compiler in order to implement the intended behavior that references to such memory can only exist at comptime. It does *not* clean up the representation of mutable values, improve the representation of comptime-known pointers, or fix the many bugs in the comptime pointer access code. These will be future enhancements. Comptime memory lives for the duration of a single Sema, and is not permitted to escape that one analysis, either by becoming runtime-known or by becoming comptime-known to other analyses. These restrictions mean that we can represent comptime allocations not via Decl, but with state local to Sema - specifically, the new `Sema.comptime_allocs` field. All comptime-mutable allocations, as well as any comptime-known const allocs containing references to such memory, live in here. This allows for relatively fast checking of whether a value references any comptime-mtuable memory, since we need only traverse values up to pointers: pointers to Decls can never reference comptime-mutable memory, and pointers into `Sema.comptime_allocs` always do. This change exposed some faulty pointer access logic in `Value.zig`. I've fixed the important cases, but there are some TODOs I've put in which are definitely possible to hit with sufficiently esoteric code. I plan to resolve these by auditing all direct accesses to pointers (most of them ought to use Sema to perform the pointer access!), but for now this is sufficient for all realistic code and to get tests passing. This change eliminates `Zcu.tmp_hack_arena`, instead using the Sema arena for comptime memory mutations, which is possible since comptime memory is now local to the current Sema. This change should allow `Decl` to store only an `InternPool.Index` rather than a full-blown `ty: Type, val: Value`. This commit does not perform this refactor.
2024-03-24fix comptime float formattingMarc Tiehuis
Closes #19379 Closes #18046
2024-03-24std.fmt.fmtIntSize{Bin,Dec}: Don't add .0... to bytesBen Sinclair
These are the fundamental units so they can't have decimal places.
2024-03-21std: promote tests to doctestsAndrew Kelley
Now these show up as "example usage" in generated documentation.
2024-03-21rename ryu128 -> format_floatMarc Tiehuis
Symmetry with parse_float and to hide the implementation from the user. Additionally, we expose the entire namespace and provide some aliases so everything is available to a user. Closes #19366
2024-03-11Merge pull request #19229 from tiehuis/ryu-128Andrew Kelley
std.fmt: add ryu floating-point formatting implementation
2024-03-10improve documentation in stdAndrew Kelley
A lot of these "shorthand" doc comments were redundant, low quality filler content. Better to let the actual modules speak for themselves with top level doc comments rather than trying to document their aliases.
2024-03-09std.fmt: fix std-cases and perform round-trip check in ryu unit testsMarc Tiehuis