diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2015-09-25 23:09:46 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2015-09-25 23:09:46 +0900 |
| commit | 524a038876657a9cb062ec1e27015662e648d45f (patch) | |
| tree | bce2022194d0fc2c943a98176f69c0db967095c7 | |
| parent | c069e5ff4003521181a336aace07d820de9aee31 (diff) | |
| download | mruby-524a038876657a9cb062ec1e27015662e648d45f.tar.gz mruby-524a038876657a9cb062ec1e27015662e648d45f.zip | |
inspect prints valid UTF-8 character without escaping
| -rw-r--r-- | src/string.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/string.c b/src/string.c index fbded91c0..94afb4787 100644 --- a/src/string.c +++ b/src/string.c @@ -2575,7 +2575,21 @@ mrb_str_inspect(mrb_state *mrb, mrb_value str) p = RSTRING_PTR(str); pend = RSTRING_END(str); for (;p < pend; p++) { unsigned char c, cc; +#ifdef MRB_UTF8_STRING + mrb_int clen; + + clen = utf8len(p, pend); + if (clen > 1) { + mrb_int i; + for (i=0; i<clen; i++) { + buf[i] = p[i]; + } + mrb_str_cat(mrb, result, buf, clen); + p += clen; + continue; + } +#endif c = *p; if (c == '"'|| c == '\\' || (c == '#' && IS_EVSTR(p, pend))) { buf[0] = '\\'; buf[1] = c; |
