| ... | ... | @@ -84,13 +84,7 @@ inline fn do(comptime Ctx: type, alloc: std.mem.Allocator, writer: anytype, comp |
| 84 | 84 | return; |
| 85 | 85 | } |
| 86 | 86 | const s = std.mem.trimRight(u8, x, "\n"); |
| 87 | | for (s) |c| { |
| 88 | | if (entityLookupBefore(&[_]u8{c})) |ent| { |
| 89 | | try writer.writeAll(ent.entity); |
| 90 | | } else { |
| 91 | | try writer.writeAll(&[_]u8{c}); |
| 92 | | } |
| 93 | | } |
| 87 | try writeEscaped(s, writer); |
| 94 | 88 | return; |
| 95 | 89 | } |
| 96 | 90 | if (TI == .Int or TI == .Float or TI == .ComptimeInt or TI == .ComptimeFloat) { |
| ... | ... | @@ -209,6 +203,16 @@ fn Field(comptime T: type, comptime field_name: string) type { |
| 209 | 203 | @compileError(std.fmt.comptimePrint("pek: unknown field {s} on type {s}", .{ field_name, @typeName(T) })); |
| 210 | 204 | } |
| 211 | 205 | |
| 206 | pub fn writeEscaped(s: string, writer: anytype) !void { |
| 207 | for (s) |c| { |
| 208 | if (entityLookupBefore(&[_]u8{c})) |ent| { |
| 209 | try writer.writeAll(ent.entity); |
| 210 | } else { |
| 211 | try writer.writeAll(&[_]u8{c}); |
| 212 | } |
| 213 | } |
| 214 | } |
| 215 | |
| 212 | 216 | fn entityLookupBefore(in: string) ?htmlentities.Entity { |
| 213 | 217 | for (htmlentities.ENTITIES) |e| { |
| 214 | 218 | if (!std.mem.endsWith(u8, e.entity, ";")) { |