Skip to content

Commit

Permalink
[util] Add unicode output to NumParse
Browse files Browse the repository at this point in the history
  • Loading branch information
titzer committed Jul 26, 2024
1 parent afefccb commit f23d494
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion apps/NumParse/NumParse.v3
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@ def renderVal(vtype: Type, val: Val) {
}
if (v.val >= 0 || !x.signed) {
trace.tab().put_uleb32(bits).outln();
trace.tab().put_utf8(bits).outln();
if (Utf8.isValidCodepoint(bits)) {
trace.tab().put_utf8(bits).outln();
if (bits >= 32) trace.tab().put_unicode(bits).outln();
}
if (u7.?(bits)) {
trace.tab().put_ascii(u7.!(bits)).outln();
}
}
}
v: Box<long> => {
Expand Down Expand Up @@ -134,6 +140,22 @@ class TraceBuilder extends StringBuilder {
putx_8(utf8_buffer[i]);
}
}
def put_unicode(codepoint: u32) -> this {
puts("unicode: ");
var count = Utf8.encode(codepoint, utf8_buffer, 0);
putr(utf8_buffer[0 ... count]);
}
def put_ascii(val: u7) -> this {
puts("ascii: ");
match (byte.view(val)) {
'\r' => puts("\\r");
'\t' => puts("\\t");
'\n' => puts("\\n");
_ => {
if (val >= 32) putc(val);
}
}
}
def outln() -> this {
ln();
System.puts(extract());
Expand Down

0 comments on commit f23d494

Please sign in to comment.