harec

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 21fadeeb2d4b70e4f9cad170d1fe7d3acf55b872
parent 8a8f11ac25f985aac5b3f2d88f0c04856826f161
Author: Steven Guikal <void@fluix.one>
Date:   Wed,  2 Jun 2021 19:42:59 -0400

rune_unparse: add \U

Diffstat:
Msrc/lex.c | 6++++--
Mtests/00-constants.ha | 3++-
2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/src/lex.c b/src/lex.c @@ -1009,7 +1009,7 @@ lexical_token_str(enum lexical_token tok) static const char * rune_unparse(uint32_t c) { - static char buf[7]; + static char buf[11]; switch (c) { case '\0': snprintf(buf, sizeof(buf), "\\0"); @@ -1045,7 +1045,9 @@ rune_unparse(uint32_t c) snprintf(buf, sizeof(buf), "\\\""); break; default: - if (c > 0x7F) { + if (c > 0xffff) { + snprintf(buf, sizeof(buf), "\\U%08x", c); + } else if (c > 0x7F) { snprintf(buf, sizeof(buf), "\\u%04x", c); } else if (!isprint(c)) { snprintf(buf, sizeof(buf), "\\x%02x", c); diff --git a/tests/00-constants.ha b/tests/00-constants.ha @@ -6,7 +6,8 @@ export fn main() void = { let p1: nullable *int = null; let r1 = 'x', r2 = '\x0A', r3 = '\u1234', r4 = '\0', r5 = '\a', r6 = '\b', r7 = '\f', r8 = '\n', r9 = '\r', r10 = '\t', - r11 = '\v', r12 = '\\', r13 = '\'', r14 = '\"'; + r11 = '\v', r12 = '\\', r13 = '\'', r14 = '\"', + r15 = '\U12345678'; let f1 = 1.0, f2 = 1f32, f3 = 1.0e2, f4 = 1.0f64; let f5 = 1.23e+45, f6 = 9.87e-65, f7 = 1e-7; };