strings.write_quoted_string

This commit is contained in:
gingerBill
2019-01-06 22:16:14 +00:00
parent 64f84ef9a3
commit 6295f6747f
2 changed files with 26 additions and 22 deletions
+1 -20
View File
@@ -601,26 +601,7 @@ fmt_string :: proc(fi: ^Info, s: string, verb: rune) {
strings.write_string(fi.buf, s);
case 'q': // quoted string
quote: byte = '"';
strings.write_byte(fi.buf, quote);
for width := 0; len(s) > 0; s = s[width:] {
r := rune(s[0]);
width = 1;
if r >= utf8.RUNE_SELF {
r, width = utf8.decode_rune_in_string(s);
}
if width == 1 && r == utf8.RUNE_ERROR {
strings.write_byte(fi.buf, '\\');
strings.write_byte(fi.buf, 'x');
strings.write_byte(fi.buf, __DIGITS_LOWER[s[0]>>4]);
strings.write_byte(fi.buf, __DIGITS_LOWER[s[0]&0xf]);
continue;
}
strings.write_escaped_rune(fi.buf, r, quote);
}
strings.write_byte(fi.buf, quote);
strings.write_quoted_string(fi.buf, s, '"');
case 'x', 'X':
space := fi.space;