mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-24 20:45:06 +02:00
Allow read-char to handle unicode characters
This commit is contained in:
parent
b1ea22c940
commit
734a6e1911
1 changed files with 8 additions and 4 deletions
12
runtime.c
12
runtime.c
|
@ -6319,17 +6319,21 @@ object Cyc_io_peek_char(void *data, object cont, object port)
|
||||||
object Cyc_io_read_char(void *data, object cont, object port)
|
object Cyc_io_read_char(void *data, object cont, object port)
|
||||||
{
|
{
|
||||||
port_type *p = (port_type *)port;
|
port_type *p = (port_type *)port;
|
||||||
int c;
|
|
||||||
Cyc_check_port(data, port);
|
Cyc_check_port(data, port);
|
||||||
if (p->fp == NULL) {
|
if (p->fp == NULL) {
|
||||||
Cyc_rt_raise2(data, "Unable to read from closed port: ", port);
|
Cyc_rt_raise2(data, "Unable to read from closed port: ", port);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
uint32_t state = CYC_UTF8_ACCEPT;
|
||||||
|
char_type codepoint;
|
||||||
|
int c;
|
||||||
set_thread_blocked(data, cont);
|
set_thread_blocked(data, cont);
|
||||||
_read_next_char(data, cont, p);
|
do {
|
||||||
c = p->mem_buf[p->buf_idx++];
|
_read_next_char(data, cont, p);
|
||||||
|
c = p->mem_buf[p->buf_idx++];
|
||||||
|
} while(Cyc_utf8_decode(&state, &codepoint, (uint8_t)c));
|
||||||
p->col_num++;
|
p->col_num++;
|
||||||
return_thread_runnable(data, (c != EOF) ? obj_char2obj(c) : Cyc_EOF);
|
return_thread_runnable(data, (c != EOF) ? obj_char2obj(codepoint) : Cyc_EOF);
|
||||||
}
|
}
|
||||||
return Cyc_EOF;
|
return Cyc_EOF;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue