Zig 0.17.0-dev (Split by item) This is an example of documentation generated by
ZigDoc , an alternative to Zig's built-in
Auto Doc feature. See also
examples in other modes/formats . The project being documented here (as the example) is the Zig standard library.
std › fmt › Parser Public Struct Parser Doc Source Public Struct std.fmt.Parser
pub const Parser = struct Fields bytes : []const u8 i : usize Functions pub fn number (self : *@This ()) ?usize pub fn until (self : *@This (), delimiter : u8 ) []const u8 pub fn char (self : *@This ()) ?u8 pub fn maybe (self : *@This (), byte : u8 ) bool pub fn specifier (self : *@This ()) !Specifier pub fn peek (self : *@This (), i : usize ) ?u8 File fmt.zig: 161
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217 pub const Parser = struct {
bytes : []const u8 ,
i : usize ,
pub fn number (self : *@This ()) ?usize {
var r : ?usize = null ;
while (self .peek (0 )) |byte | {
switch (byte ) {
'0' ...'9' => {
if (r == null ) r = 0 ;
r .? *= 10 ;
r .? += byte - '0' ;
},
else => break ,
}
self .i += 1 ;
}
return r ;
}
pub fn until (self : *@This (), delimiter : u8 ) []const u8 {
const start = self .i ;
self .i = std .mem .findScalarPos (u8 , self .bytes , self .i , delimiter ) orelse self .bytes .len ;
return self .bytes [start ..self .i ];
}
pub fn char (self : *@This ()) ?u8 {
const i = self .i ;
if (self .bytes .len - i == 0 ) return null ;
self .i = i + 1 ;
return self .bytes [i ];
}
pub fn maybe (self : *@This (), byte : u8 ) bool {
if (self .peek (0 ) == byte ) {
self .i += 1 ;
return true ;
}
return false ;
}
pub fn specifier (self : *@This ()) !Specifier {
if (self .maybe ('[' )) {
const arg_name = self .until (']' );
if (!self .maybe (']' )) return error .@"Expected closing ]" ;
return .{ .named = arg_name };
}
if (self .number ()) |i | return .{ .number = i };
return .{ .none = {} };
}
pub fn peek (self : *@This (), i : usize ) ?u8 {
const peek_index = self .i + i ;
if (peek_index >= self .bytes .len ) return null ;
return self .bytes [peek_index ];
}
}
A stream based parser for format strings.
Allows to implement formatters compatible with std.fmt without replicating the standard library behavior.