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 {...@@ -1270,6 +1270,8 @@ pub const Parser = struct {
1270 }1270 }
1271};1271};
12721272
1273/// Unescape a JSON string
1274/// Optimized for arena allocators, uses Allocator.shrink
1273pub fn unescapeStringAlloc(alloc: *Allocator, input: []const u8) ![]u8 {1275pub fn unescapeStringAlloc(alloc: *Allocator, input: []const u8) ![]u8 {
1274 var output = try alloc.alloc(u8, input.len);1276 var output = try alloc.alloc(u8, input.len);
1275 errdefer alloc.free(output);1277 errdefer alloc.free(output);
...@@ -1293,7 +1295,7 @@ pub fn unescapeStringAlloc(alloc: *Allocator, input: []const u8) ![]u8 {...@@ -1293,7 +1295,7 @@ pub fn unescapeStringAlloc(alloc: *Allocator, input: []const u8) ![]u8 {
1293 'f' => 12,1295 'f' => 12,
1294 'b' => 8,1296 'b' => 8,
1295 '"' => '"',1297 '"' => '"',
1296 else => return error.InvalidEscapeCharacter;1298 else => return error.InvalidEscapeCharacter
1297 }1299 }
1298 );1300 );
1299 inIndex += 2;1301 inIndex += 2;
...@@ -1306,7 +1308,7 @@ pub fn unescapeStringAlloc(alloc: *Allocator, input: []const u8) ![]u8 {...@@ -1306,7 +1308,7 @@ pub fn unescapeStringAlloc(alloc: *Allocator, input: []const u8) ![]u8 {
1306 }1308 }
1307 }1309 }
13081310
1309 return try alloc.realloc(unescaped, outIndex);1311 return alloc.shrink(output, outIndex);
1310}1312}
13111313
1312test "json.parser.dynamic" {1314test "json.parser.dynamic" {