diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-03-03 17:49:40 -0500 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-03-03 17:49:40 -0500 |
| commit | 0fe255a7c1ea7f8c324bfa58cdfb2c77f06bd823 (patch) | |
| tree | d99bc12b02696984dd68f53900ec5933a2031c7d /parse.c | |
| parent | 0c51ca73e0c41c98c31fd306d0ef6f3e8c37227d (diff) | |
Fix up unicode escapes
Diffstat (limited to 'parse.c')
| -rw-r--r-- | parse.c | 14 |
1 files changed, 12 insertions, 2 deletions
@@ -140,6 +140,15 @@ const char *unescape(const char **out) { if (unescapes[(int)escape[1]]) { *endpos = escape + 2; return heap_str(unescapes[(int)escape[1]]); + } else if (escape[1] == 'U' && escape[2]) { + char *endptr = NULL; + long codepoint = strtol(escape+2, &endptr, 16); + uint32_t ustr[2] = {codepoint, 0}; + size_t bufsize = 8; + uint8_t buf[bufsize]; + (void)u32_to_u8(ustr, bufsize, buf, &bufsize); + *endpos = endptr; + return heap_strn((char*)buf, bufsize); } else if (escape[1] == 'x' && escape[2] && escape[3]) { char *endptr = (char*)&escape[3+1]; char c = (char)strtol(escape+2, &endptr, 16); @@ -940,8 +949,9 @@ PARSER(parse_string) { if (*pos == '\\') { CORD cord = CORD_EMPTY; do { - char c = unescape(&pos)[0]; - cord = CORD_cat_char(cord, c); + const char *c = unescape(&pos); + cord = CORD_cat(cord, c); + // cord = CORD_cat_char(cord, c); } while (*pos == '\\'); return NewAST(ctx->file, start, pos, StringLiteral, .cord=cord); } |
