Function stringEscape [src]
Print the string as escaped contents of a double quoted string.
Prototype
pub fn stringEscape(bytes: []const u8, w: *Writer) Writer.Error!void
Parameters
bytes: []const u8
w: *Writer
Source
pub fn stringEscape(bytes: []const u8, w: *Writer) Writer.Error!void {
for (bytes) |byte| switch (byte) {
'\n' => try w.writeAll("\\n"),
'\r' => try w.writeAll("\\r"),
'\t' => try w.writeAll("\\t"),
'\\' => try w.writeAll("\\\\"),
'"' => try w.writeAll("\\\""),
'\'' => try w.writeByte('\''),
' ', '!', '#'...'&', '('...'[', ']'...'~' => try w.writeByte(byte),
else => {
try w.writeAll("\\x");
try w.printInt(byte, 16, .lower, .{ .width = 2, .fill = '0' });
},
};
}