summaryrefslogtreecommitdiff
path: root/src/ninep/events.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/ninep/events.zig')
-rw-r--r--src/ninep/events.zig25
1 files changed, 20 insertions, 5 deletions
diff --git a/src/ninep/events.zig b/src/ninep/events.zig
index 1ffbaab9..9d59e6cc 100644
--- a/src/ninep/events.zig
+++ b/src/ninep/events.zig
@@ -337,9 +337,10 @@ fn sanitize(record: []const u8, out: []u8) []u8 {
/// `text` as one line of UTF-8 a reader can split and decode, as /log and
/// /index show names: a backslash is `\\`, a newline `\n` (a name with one
-/// stays readable as what it is, not run into the next), any other control
-/// character, DEL or C1 control (U+0080-U+009F) a space, and a byte that
-/// is not UTF-8 `\xNN`. `out` of 4 bytes a byte of `text` holds it all.
+/// stays readable as what it is, not run into the next), and any other
+/// control character, DEL, C1 control (U+0080-U+009F) or byte that is not
+/// UTF-8 `\xNN`, so a name read there decodes to the bytes it is. `out` of
+/// 4 bytes a byte of `text` holds it all.
pub fn shown(text: []const u8, out: []u8) []u8 {
return shownAs(text, out, true);
}
@@ -365,8 +366,15 @@ fn shownAs(text: []const u8, out: []u8, escape_newline: bool) []u8 {
continue;
}
if (c < ' ' or c == 0x7f) {
- out[w] = ' ';
- w += 1;
+ // A name's (escape_newline) is `\xNN`, so it reads back as the
+ // byte it was; a message's a space.
+ if (escape_newline) {
+ _ = std.fmt.bufPrint(out[w..], "\\x{x:0>2}", .{c}) catch break;
+ w += 4;
+ } else {
+ out[w] = ' ';
+ w += 1;
+ }
i += 1;
continue;
}
@@ -378,6 +386,13 @@ fn shownAs(text: []const u8, out: []u8, escape_newline: bool) []u8 {
continue;
}
if (n == 2 and c == 0xC2 and body[i + 1] <= 0x9F) {
+ if (escape_newline) {
+ if (w + 8 > out.len) break;
+ _ = std.fmt.bufPrint(out[w..], "\\xc2\\x{x:0>2}", .{body[i + 1]}) catch break;
+ w += 8;
+ i += 2;
+ continue;
+ }
out[w] = ' ';
w += 1;
i += 2;