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