mirror of
https://github.com/justinethier/cyclone.git
synced 2025-07-14 00:07:36 +02:00
Allow read_return_character to parse UTF8 chars
This commit is contained in:
parent
3aa2a159b7
commit
bbe8fbb970
1 changed files with 17 additions and 3 deletions
20
runtime.c
20
runtime.c
|
@ -6118,9 +6118,23 @@ void _read_return_character(void *data, port_type *p)
|
|||
char_type result = strtol(buf, NULL, 16);
|
||||
return_thread_runnable(data, obj_char2obj(result));
|
||||
} else {
|
||||
char buf[31];
|
||||
snprintf(buf, 30, "Unable to parse character %s", p->tok_buf);
|
||||
_read_error(data, p, buf);
|
||||
uint32_t state = CYC_UTF8_ACCEPT;
|
||||
char_type codepoint;
|
||||
uint8_t *s = (uint8_t *)p->tok_buf;
|
||||
while(s) {
|
||||
if (!Cyc_utf8_decode(&state, &codepoint, *s)) {
|
||||
s++;
|
||||
break;
|
||||
}
|
||||
s++;
|
||||
}
|
||||
if (state == CYC_UTF8_ACCEPT && *s == '\0') {
|
||||
return_thread_runnable(data, obj_char2obj(codepoint));
|
||||
} else {
|
||||
char buf[31];
|
||||
snprintf(buf, 30, "Unable to parse character %s", p->tok_buf);
|
||||
_read_error(data, p, buf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue