diff options
Diffstat (limited to 'src/dom/html.zig')
| -rw-r--r-- | src/dom/html.zig | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/src/dom/html.zig b/src/dom/html.zig index 4b39a3f..47de020 100644 --- a/src/dom/html.zig +++ b/src/dom/html.zig @@ -1,32 +1,32 @@ const std = @import("std"); const eql = std.mem.eql; -pub fn escape(gpa: std.mem.Allocator, v: []const u8) ![]const u8 { - var acc = try std.ArrayList(u8).initCapacity(gpa, v.len); - errdefer acc.deinit(gpa); +pub fn escape(alloc: std.mem.Allocator, v: []const u8) ![]const u8 { + var acc = try std.ArrayList(u8).initCapacity(alloc, v.len); + errdefer acc.deinit(alloc); const view = try std.unicode.Utf8View.init(v); var iter = view.iterator(); while (iter.nextCodepointSlice()) |rune| { if (eql(u8, rune, "&")) { - try acc.appendSlice(gpa, "&"); + try acc.appendSlice(alloc, "&"); } else if (eql(u8, rune, "'")) { - try acc.appendSlice(gpa, "'"); + try acc.appendSlice(alloc, "'"); } else if (eql(u8, rune, "<")) { - try acc.appendSlice(gpa, "<"); + try acc.appendSlice(alloc, "<"); } else if (eql(u8, rune, ">")) { - try acc.appendSlice(gpa, ">"); + try acc.appendSlice(alloc, ">"); } else if (eql(u8, rune, "\"")) { - try acc.appendSlice(gpa, """); + try acc.appendSlice(alloc, """); } else { - try acc.appendSlice(gpa, rune); + try acc.appendSlice(alloc, rune); } } - return acc.toOwnedSlice(gpa); + return acc.toOwnedSlice(alloc); } -fn doTest(gpa: std.mem.Allocator, el: []const u8, exp: []const u8) !void { - const got = try escape(gpa, el); - defer gpa.free(got); +fn doTest(alloc: std.mem.Allocator, el: []const u8, exp: []const u8) !void { + const got = try escape(alloc, el); + defer alloc.free(got); std.testing.expect(eql(u8, got, exp)) catch |err| { std.debug.print("{s}\n", .{got}); return err; @@ -36,12 +36,12 @@ fn doTest(gpa: std.mem.Allocator, el: []const u8, exp: []const u8) !void { test "escaping html" { var arena = std.heap.DebugAllocator(.{}).init; defer _ = arena.deinit(); - const gpa = arena.allocator(); + const alloc = arena.allocator(); - try doTest(gpa, "hello world", "hello world"); - try doTest(gpa, "hello&world", "hello&world"); - try doTest(gpa, "hello'world", "hello'world"); - try doTest(gpa, "hello<world", "hello<world"); - try doTest(gpa, "hello>world", "hello>world"); - try doTest(gpa, "hello\"world", "hello"world"); + try doTest(alloc, "hello world", "hello world"); + try doTest(alloc, "hello&world", "hello&world"); + try doTest(alloc, "hello'world", "hello'world"); + try doTest(alloc, "hello<world", "hello<world"); + try doTest(alloc, "hello>world", "hello>world"); + try doTest(alloc, "hello\"world", "hello"world"); } |
