aboutsummaryrefslogtreecommitdiffstats
path: root/transcode.c
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-02-04 13:01:12 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-02-04 13:01:12 +0000
commite193fa79d6a34e8afc74ce8be256d7dea743c0aa (patch)
tree74e855e3c46f42891c105263fa58bb7a123dd0d6 /transcode.c
parent54936663303d578c49fa2b5e4504800db7cce4ef (diff)
downloadruby-e193fa79d6a34e8afc74ce8be256d7dea743c0aa.tar.gz
* transcode.c (make_econv_exception): show U+XXXX form for undefined
conversion error from UTF-8. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22039 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'transcode.c')
-rw-r--r--transcode.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/transcode.c b/transcode.c
index 68fed6a1a6..0320590516 100644
--- a/transcode.c
+++ b/transcode.c
@@ -2009,9 +2009,23 @@ make_econv_exception(rb_econv_t *ec)
if (ec->last_error.result == econv_undefined_conversion) {
VALUE bytes = rb_str_new((const char *)ec->last_error.error_bytes_start,
ec->last_error.error_bytes_len);
- VALUE dumped;
+ VALUE dumped = Qnil;
int idx;
- dumped = rb_str_dump(bytes);
+ if (strcmp(ec->last_error.source_encoding, "UTF-8") == 0) {
+ rb_encoding *utf8 = rb_utf8_encoding();
+ const char *start, *end;
+ int n;
+ start = (const char *)ec->last_error.error_bytes_start;
+ end = start + ec->last_error.error_bytes_len;
+ n = rb_enc_precise_mbclen(start, end, utf8);
+ if (MBCLEN_CHARFOUND_P(n) &&
+ MBCLEN_CHARFOUND_LEN(n) == ec->last_error.error_bytes_len) {
+ unsigned int cc = rb_enc_codepoint(start, end, utf8);
+ dumped = rb_sprintf("U+%04X", cc);
+ }
+ }
+ if (dumped == Qnil)
+ dumped = rb_str_dump(bytes);
mesg = rb_sprintf("%s from %s to %s",
StringValueCStr(dumped),
ec->last_error.source_encoding,