| ... | ... | @@ -275,3 +275,16 @@ pub fn ensureFieldSubset(comptime L: type, comptime R: type) void { |
| 275 | 275 | if (!@hasField(R, item.name)) @compileError(std.fmt.comptimePrint("{s} is missing the {s} field from {s}", .{ R, item.name, L })); |
| 276 | 276 | } |
| 277 | 277 | } |
| 278 | |
| 279 | pub fn fmtReplacer(bytes: string, from: u8, to: u8) std.fmt.Formatter(formatReplacer) { |
| 280 | return .{ .data = .{ .bytes = bytes, .from = from, .to = to } }; |
| 281 | } |
| 282 | |
| 283 | const ReplacerData = struct { bytes: string, from: u8, to: u8 }; |
| 284 | fn formatReplacer(self: ReplacerData, comptime fmt: []const u8, options: std.fmt.FormatOptions, writer: anytype) !void { |
| 285 | _ = fmt; |
| 286 | _ = options; |
| 287 | for (self.bytes) |c| { |
| 288 | try writer.writeByte(if (c == self.from) self.to else @intCast(u8, c)); |
| 289 | } |
| 290 | } |