From e7042330fb9c162f0ed619b8e423691c7eb6309d Mon Sep 17 00:00:00 2001 From: Andrew Barchuk Date: Fri, 15 Nov 2024 15:29:43 +0100 Subject: [PATCH 1/3] std: remove unused std.fmt.Parser buf field And make the initialization less error prone by removing a default for iter, which is required for a functional parser --- lib/std/fmt.zig | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/std/fmt.zig b/lib/std/fmt.zig index 8deef118c01a..4dcd60ad5bcd 100644 --- 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(), }; @@ -312,9 +311,8 @@ pub const Specifier = union(enum) { }; 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 From 44d9deef5ac6e8944d4914ff7ec40eead1ebfcc9 Mon Sep 17 00:00:00 2001 From: Andrew Barchuk Date: Fri, 15 Nov 2024 21:06:59 +0100 Subject: [PATCH 2/3] std: Add a brief doc comment for `std.fmt.Parser` --- lib/std/fmt.zig | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/std/fmt.zig b/lib/std/fmt.zig index 4dcd60ad5bcd..445948c79af8 100644 --- a/lib/std/fmt.zig +++ b/lib/std/fmt.zig @@ -310,6 +310,8 @@ pub const Specifier = union(enum) { named: []const u8, }; +/// Intended for parsing std.fmt format strings without having to replicate the +/// standard library behavior. pub const Parser = struct { pos: usize = 0, iter: std.unicode.Utf8Iterator, From 5b569b48e09814650ebc25622d1efee6f2c9775e Mon Sep 17 00:00:00 2001 From: Andrew Barchuk Date: Fri, 15 Nov 2024 21:29:53 +0100 Subject: [PATCH 3/3] std: improve std.fmt.Parser doc --- lib/std/fmt.zig | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/std/fmt.zig b/lib/std/fmt.zig index 445948c79af8..7018995e0541 100644 --- a/lib/std/fmt.zig +++ b/lib/std/fmt.zig @@ -310,8 +310,10 @@ pub const Specifier = union(enum) { named: []const u8, }; -/// Intended for parsing std.fmt format strings without having to replicate the -/// standard library behavior. +/// 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 { pos: usize = 0, iter: std.unicode.Utf8Iterator,