zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 1f37b70344d547a6dce2c3357a4ac3a92fa3402f (tree)
parent b2030cb9abf73886e1c896ee8d56a3156b6fd3c2
Author: Andrew Barchuk <andrew@raindev.io>
Date:   Mon, 25 Nov 2024 00:09:36 +0100

Remove unused `buf` field from `std.fmt.Parser` (#21994)

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`
Diffstat:
Mlib/std/fmt.zig | 8+++++---
1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/lib/std/fmt.zig b/lib/std/fmt.zig @@ -224,7 +224,6 @@ pub const Placeholder = struct { pub fn parse(comptime str: anytype) Placeholder { const view = std.unicode.Utf8View.initComptime(&str); comptime var parser = Parser{ - .buf = &str, .iter = view.iterator(), }; @@ -311,10 +310,13 @@ pub const Specifier = union(enum) { named: []const u8, }; +/// A stream based parser for format strings. +/// +/// Allows to implement formatters compatible with std.fmt without replicating +/// the standard library behavior. pub const Parser = struct { - buf: []const u8, pos: usize = 0, - iter: std.unicode.Utf8Iterator = undefined, + iter: std.unicode.Utf8Iterator, // Returns a decimal number or null if the current character is not a // digit