feature. See also
. The project being documented here (as the example) is the Zig library itself.
dynamic.handleCompleteValue
fn handleCompleteValue(stack: *Array, allocator: Allocator, source: anytype, value_: Value, options: ParseOptions) !?Value
File
Code
fn handleCompleteValue(stack: *Array, allocator: Allocator, source: anytype, value_: Value, options: ParseOptions) !?Value {
if (stack.items.len == 0) return value_;
var value = value_;
while (true) {
debug.assert(stack.items[stack.items.len - 1] == .array or
(stack.items[stack.items.len - 2] == .object and stack.items[stack.items.len - 1] == .string));
switch (stack.items[stack.items.len - 1]) {
.string => |key| {
_ = stack.pop();
var object = &stack.items[stack.items.len - 1].object;
const gop = try object.getOrPut(allocator, key);
if (gop.found_existing) {
switch (options.duplicate_field_behavior) {
.use_first => {},
.@"error" => return error.DuplicateField,
.use_last => {
gop.value_ptr.* = value;
},
}
} else {
gop.value_ptr.* = value;
}
// so we have to process the next token before we return.
switch (try source.nextAllocMax(allocator, .alloc_always, options.max_value_len.?)) {
.object_end => {
value = stack.pop().?;
if (stack.items.len == 0) return value;
continue;
},
.allocated_string => |next_key| {
try stack.append(Value{ .string = next_key });
return null;
},
else => unreachable,
}
},
.array => |*array| {
try array.append(value);
return null;
},
else => unreachable,
}
}
}