diff --git a/eval.c b/eval.c index 734afe97..ead0f323 100644 --- a/eval.c +++ b/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)) { diff --git a/include/chibi/sexp.h b/include/chibi/sexp.h index bb558cb7..32b7c1c5 100755 --- a/include/chibi/sexp.h +++ b/include/chibi/sexp.h @@ -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 diff --git a/sexp.c b/sexp.c index 9216ed60..2ba3da20 100644 --- a/sexp.c +++ b/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;