struct HexEscape [src]
Fields
bytes: []const u8
charset: *const [16]u8
Members
- format (Function)
- lower_charset (Constant)
- upper_charset (Constant)
Source
pub const HexEscape = struct {
bytes: []const u8,
charset: *const [16]u8,
pub const upper_charset = "0123456789ABCDEF";
pub const lower_charset = "0123456789abcdef";
pub fn format(se: HexEscape, w: *std.Io.Writer) std.Io.Writer.Error!void {
const charset = se.charset;
var buf: [4]u8 = undefined;
buf[0] = '\\';
buf[1] = 'x';
for (se.bytes) |c| {
if (std.ascii.isPrint(c)) {
try w.writeByte(c);
} else {
buf[2] = charset[c >> 4];
buf[3] = charset[c & 15];
try w.writeAll(&buf);
}
}
}
}