mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-07-07 13:16:36 +02:00
Supporting unicode characters in \x string escapes.
This commit is contained in:
parent
2f5f7f73c7
commit
4ffcba797c
1 changed files with 12 additions and 1 deletions
13
sexp.c
13
sexp.c
|
@ -2115,6 +2115,9 @@ sexp sexp_flush_output_op (sexp ctx, sexp self, sexp_sint_t n, sexp out) {
|
|||
#define INIT_STRING_BUFFER_SIZE 128
|
||||
|
||||
sexp sexp_read_string (sexp ctx, sexp in, int sentinel) {
|
||||
#if SEXP_USE_UTF8_STRINGS
|
||||
int len;
|
||||
#endif
|
||||
int c, i=0;
|
||||
sexp_sint_t size=INIT_STRING_BUFFER_SIZE;
|
||||
char initbuf[INIT_STRING_BUFFER_SIZE];
|
||||
|
@ -2142,6 +2145,14 @@ sexp sexp_read_string (sexp ctx, sexp in, int sentinel) {
|
|||
#endif
|
||||
}
|
||||
c = sexp_unbox_fixnum(res);
|
||||
#if SEXP_USE_UTF8_STRINGS
|
||||
if ((unsigned)c > 0x80) {
|
||||
len = sexp_utf8_char_byte_count(c);
|
||||
sexp_utf8_encode_char((unsigned char*)buf + i, len, c);
|
||||
i += len;
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
#if SEXP_USE_ESCAPE_NEWLINE
|
||||
|
@ -2157,7 +2168,7 @@ sexp sexp_read_string (sexp ctx, sexp in, int sentinel) {
|
|||
break;
|
||||
}
|
||||
buf[i++] = c;
|
||||
if (i >= size) { /* expand buffer w/ malloc(), later free() it */
|
||||
if (i+4 >= size) { /* expand buffer w/ malloc(), later free() it */
|
||||
tmp = (char*) sexp_malloc(size*2);
|
||||
if (!tmp) {res = sexp_global(ctx, SEXP_G_OOM_ERROR); break;}
|
||||
memcpy(tmp, buf, i);
|
||||
|
|
Loading…
Add table
Reference in a new issue