diff options
| author | xackus <14938807+xackus@users.noreply.github.com> | 2019-11-10 22:26:42 +0100 |
|---|---|---|
| committer | xackus <14938807+xackus@users.noreply.github.com> | 2019-11-10 22:26:42 +0100 |
| commit | f6d124418fdcd0387f079cee8e5e39c33ef91911 (patch) | |
| tree | c058dbf2b0255924fbb2dc6bc9c9daf3b22ba577 /lib/std/json.zig | |
| parent | 6d0cdf7cd79f3a06fc920c4da545d84a11ac0a6c (diff) | |
| download | zig-f6d124418fdcd0387f079cee8e5e39c33ef91911.tar.gz zig-f6d124418fdcd0387f079cee8e5e39c33ef91911.zip | |
Fix and document
Diffstat (limited to 'lib/std/json.zig')
| -rw-r--r-- | lib/std/json.zig | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/lib/std/json.zig b/lib/std/json.zig index 1bb7c9f78c..c1d8a89963 100644 --- a/lib/std/json.zig +++ b/lib/std/json.zig @@ -1270,6 +1270,8 @@ pub const Parser = struct { } }; +/// Unescape a JSON string +/// Optimized for arena allocators, uses Allocator.shrink pub fn unescapeStringAlloc(alloc: *Allocator, input: []const u8) ![]u8 { var output = try alloc.alloc(u8, input.len); errdefer alloc.free(output); @@ -1293,7 +1295,7 @@ pub fn unescapeStringAlloc(alloc: *Allocator, input: []const u8) ![]u8 { 'f' => 12, 'b' => 8, '"' => '"', - else => return error.InvalidEscapeCharacter; + else => return error.InvalidEscapeCharacter } ); inIndex += 2; @@ -1306,7 +1308,7 @@ pub fn unescapeStringAlloc(alloc: *Allocator, input: []const u8) ![]u8 { } } - return try alloc.realloc(unescaped, outIndex); + return alloc.shrink(output, outIndex); } test "json.parser.dynamic" { |
