authorgravatar for 14938807+xackus@users.noreply.github.comxackus <14938807+xackus@users.noreply.github.com> 2019-11-10 22:26:42+01:00
committergravatar for 14938807+xackus@users.noreply.github.comxackus <14938807+xackus@users.noreply.github.com> 2019-11-10 22:26:42+01:00
logf6d124418fdcd0387f079cee8e5e39c33ef91911
treec058dbf2b0255924fbb2dc6bc9c9daf3b22ba577
parent6d0cdf7cd79f3a06fc920c4da545d84a11ac0a6c

Fix and document


1 files changed, 4 insertions(+), 2 deletions(-)

lib/std/json.zig+4-2
......@@ -1270,6 +1270,8 @@ pub const Parser = struct {
12701270 }
12711271};
12721272
1273/// Unescape a JSON string
1274/// Optimized for arena allocators, uses Allocator.shrink
12731275pub fn unescapeStringAlloc(alloc: *Allocator, input: []const u8) ![]u8 {
12741276 var output = try alloc.alloc(u8, input.len);
12751277 errdefer alloc.free(output);
......@@ -1293,7 +1295,7 @@ pub fn unescapeStringAlloc(alloc: *Allocator, input: []const u8) ![]u8 {
12931295 'f' => 12,
12941296 'b' => 8,
12951297 '"' => '"',
1296 else => return error.InvalidEscapeCharacter;
1298 else => return error.InvalidEscapeCharacter
12971299 }
12981300 );
12991301 inIndex += 2;
......@@ -1306,7 +1308,7 @@ pub fn unescapeStringAlloc(alloc: *Allocator, input: []const u8) ![]u8 {
13061308 }
13071309 }
13081310
1309 return try alloc.realloc(unescaped, outIndex);
1311 return alloc.shrink(output, outIndex);
13101312}
13111313
13121314test "json.parser.dynamic" {