From f6d124418fdcd0387f079cee8e5e39c33ef91911 Mon Sep 17 00:00:00 2001 From: xackus <14938807+xackus@users.noreply.github.com> Date: Sun, 10 Nov 2019 22:26:42 +0100 Subject: [PATCH] Fix and document --- lib/std/json.zig | 6 ++++-- 1 file 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" {