Commit f6d124418f

xackus <14938807+xackus@users.noreply.github.com>
2019-11-10 22:26:42
Fix and document
1 parent 6d0cdf7
Changed files (1)
lib
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" {