mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-05-19 21:59:17 +02:00
utf8 encoding chars on (display ch) for non-ASCI ch (issue #88)
This commit is contained in:
parent
1b23c0add0
commit
ebe2af486e
3 changed files with 12 additions and 9 deletions
8
eval.c
8
eval.c
|
@ -1469,14 +1469,6 @@ sexp sexp_string_utf8_index_ref (sexp ctx, sexp self, sexp_sint_t n, sexp str, s
|
|||
return sexp_string_utf8_ref(ctx, str, off);
|
||||
}
|
||||
|
||||
void sexp_write_utf8_char (sexp ctx, int c, sexp out) {
|
||||
unsigned char buf[8];
|
||||
int len = sexp_utf8_char_byte_count(c);
|
||||
sexp_utf8_encode_char(buf, len, c);
|
||||
buf[len] = 0;
|
||||
sexp_write_string(ctx, (char*)buf, out);
|
||||
}
|
||||
|
||||
sexp sexp_read_utf8_char (sexp ctx, sexp port, int i) {
|
||||
if (i >= 0x80) {
|
||||
if ((i < 0xC0) || (i > 0xF7)) {
|
||||
|
|
|
@ -1225,6 +1225,7 @@ SEXP_API void sexp_init(void);
|
|||
SEXP_API sexp sexp_string_index_to_offset (sexp ctx, sexp self, sexp_sint_t n, sexp str, sexp index);
|
||||
SEXP_API sexp sexp_utf8_substring_op (sexp ctx, sexp self, sexp_sint_t n, sexp str, sexp start, sexp end);
|
||||
SEXP_API void sexp_utf8_encode_char (unsigned char* p, int len, int c);
|
||||
SEXP_API void sexp_write_utf8_char (sexp ctx, int c, sexp out);
|
||||
#endif
|
||||
|
||||
#if SEXP_USE_GREEN_THREADS
|
||||
|
|
12
sexp.c
12
sexp.c
|
@ -1699,13 +1699,23 @@ sexp sexp_write_op (sexp ctx, sexp self, sexp_sint_t n, sexp obj, sexp out) {
|
|||
return sexp_write_one(ctx, obj, out);
|
||||
}
|
||||
|
||||
#if SEXP_USE_UTF8_STRINGS
|
||||
void sexp_write_utf8_char (sexp ctx, int c, sexp out) {
|
||||
unsigned char buf[8];
|
||||
int len = sexp_utf8_char_byte_count(c);
|
||||
sexp_utf8_encode_char(buf, len, c);
|
||||
buf[len] = 0;
|
||||
sexp_write_string(ctx, (char*)buf, out);
|
||||
}
|
||||
#endif
|
||||
|
||||
sexp sexp_display_op (sexp ctx, sexp self, sexp_sint_t n, sexp obj, sexp out) {
|
||||
sexp res=SEXP_VOID;
|
||||
sexp_assert_type(ctx, sexp_oportp, SEXP_OPORT, out);
|
||||
if (sexp_stringp(obj))
|
||||
sexp_write_string(ctx, sexp_string_data(obj), out);
|
||||
else if (sexp_charp(obj))
|
||||
sexp_write_char(ctx, sexp_unbox_character(obj), out);
|
||||
sexp_write_utf8_char(ctx, sexp_unbox_character(obj), out);
|
||||
else
|
||||
res = sexp_write_one(ctx, obj, out);
|
||||
return res;
|
||||
|
|
Loading…
Add table
Reference in a new issue