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 › Placeholder › parse Public Function parse Doc Source Public Function std.fmt.Placeholder.parse
pub fn parse (comptime bytes : []const u8 ) Placeholder Params File fmt.zig: 83
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148 pub fn parse (comptime bytes : []const u8 ) Placeholder {
var parser : Parser = .{ .bytes = bytes , .i = 0 };
const arg = parser .specifier () catch |err | @compileError (@errorName (err ));
const specifier_arg = parser .until (':' );
if (parser .char ()) |b | {
if (b != ':' ) @compileError ("expected : or }, found '" ++ &[1 ]u8 {b } ++ "'" );
}
// Parse the fill byte, if present.
//
// When the width field is also specified, the fill byte must
// be followed by an alignment specifier, unless it's '0' (zero)
// (in which case it's handled as part of the width specifier).
var fill : ?u8 = if (parser .peek (1 )) |b |
switch (b ) {
'<' , '^' , '>' => parser .char (),
else => null ,
}
else
null ;
// Parse the alignment parameter
const alignment : ?Alignment = if (parser .peek (0 )) |b | init : {
switch (b ) {
'<' , '^' , '>' => {
// consume the character
break :init switch (parser .char ().?) {
'<' => .left ,
'^' => .center ,
else => .right ,
};
},
else => break :init null ,
}
} else null ;
// When none of the fill character and the alignment specifier have
// been provided, check whether the width starts with a zero.
if (fill == null and alignment == null ) {
fill = if (parser .peek (0 ) == '0' ) '0' else null ;
}
// Parse the width parameter
const width = parser .specifier () catch |err | @compileError (@errorName (err ));
// Skip the dot, if present
if (parser .char ()) |b | {
if (b != '.' ) @compileError ("expected . or }, found '" ++ &[1 ]u8 {b } ++ "'" );
}
// Parse the precision parameter
const precision = parser .specifier () catch |err | @compileError (@errorName (err ));
if (parser .char ()) |b | @compileError ("extraneous trailing character '" ++ &[1 ]u8 {b } ++ "'" );
const specifier_array = specifier_arg [0 ..specifier_arg .len ].*;
return .{
.specifier_arg = &specifier_array ,
.fill = fill orelse default_fill_char ,
.alignment = alignment orelse default_alignment ,
.arg = arg ,
.width = width ,
.precision = precision ,
};
}