1const std = @import("std");
2const string = []const u8;
3const extras = @import("./lib.zig");
4
5pub fn fmtReplacer(bytes: string, from: u8, to: u8) std.fmt.Alt(FormatData, formatReplacer) {
6 return .{ .data = .{
7 .bytes = bytes,
8 .from = from,
9 .to = to,
10 } };
11}
12
13const FormatData = struct {
14 bytes: string,
15 from: u8,
16 to: u8,
17};
18
19fn formatReplacer(
20 self: FormatData,
21 writer: *std.Io.Writer,
22) !void {
23 for (self.bytes) |c| {
24 try writer.writeByte(if (c == self.from) self.to else @intCast(c));
25 }
26}
27
28test {
29 const in = "C:\\Program Files\\Custom Utilities\\StringFinder.exe";
30 const out = "C:/Program Files/Custom Utilities/StringFinder.exe";
31 try std.testing.expectFmt(out, "{f}", .{fmtReplacer(in, '\\', '/')});
32}