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 › json › Scanner › nextAllocMax Public Function nextAllocMax Doc Source Public Function std.json.Scanner.nextAllocMax
pub fn nextAllocMax (self : *@This (), allocator : Allocator , when : AllocWhen , max_value_len : usize ) AllocError !Token Params File json/Scanner.zig: 130
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172 pub fn nextAllocMax (self : *@This (), allocator : Allocator , when : AllocWhen , max_value_len : usize ) AllocError !Token {
assert (self .is_end_of_input ); // This function is not available in streaming mode.
const token_type = self .peekNextTokenType () catch |e | switch (e ) {
error .BufferUnderrun => unreachable ,
else => |err | return err ,
};
switch (token_type ) {
.number , .string => {
var value_list = std .array_list .Managed (u8 ).init (allocator );
errdefer {
value_list .deinit ();
}
if (self .allocNextIntoArrayListMax (&value_list , when , max_value_len ) catch |e | switch (e ) {
error .BufferUnderrun => unreachable ,
else => |err | return err ,
}) |slice | {
return if (token_type == .number )
Token { .number = slice }
else
Token { .string = slice };
} else {
return if (token_type == .number )
Token { .allocated_number = try value_list .toOwnedSlice () }
else
Token { .allocated_string = try value_list .toOwnedSlice () };
}
},
// Simple tokens never alloc.
.object_begin ,
.object_end ,
.array_begin ,
.array_end ,
.true ,
.false ,
.null ,
.end_of_document ,
=> return self .next () catch |e | switch (e ) {
error .BufferUnderrun => unreachable ,
else => |err | return err ,
},
}
}
This function is only available after
endInput()(orinitCompleteInput()) has been called. See alsostd.json.Tokenfor documentation ofnextAlloc*()function behavior.