From 220d07d2fcf5b8d66327e2c78770448c43c33db5 Mon Sep 17 00:00:00 2001 From: naruse Date: Wed, 24 Nov 2010 02:20:11 +0000 Subject: [PATCH] * string.c (rb_str_inspect): treat UTF-16 and UTF-32 as BE or LE. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29896 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 4 ++++ string.c | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/ChangeLog b/ChangeLog index 0152c3e62a..152613bee8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Wed Nov 24 11:19:13 2010 NARUSE, Yui + + * string.c (rb_str_inspect): treat UTF-16 and UTF-32 as BE or LE. + Wed Nov 24 06:35:32 2010 NARUSE, Yui * enc/trans/utf_16_32.trans: add the UTF-32 converter. diff --git a/string.c b/string.c index 7c5ddbdbd4..385b05f5b1 100644 --- a/string.c +++ b/string.c @@ -4202,7 +4202,10 @@ rb_str_inspect(VALUE str) rb_encoding *resenc = rb_default_internal_encoding(); int unicode_p = rb_enc_unicode_p(enc); int asciicompat = rb_enc_asciicompat(enc); + static rb_encoding *utf16, *utf32; + if (!utf16) utf16 = rb_enc_find("UTF-16"); + if (!utf32) utf32 = rb_enc_find("UTF-32"); if (resenc == NULL) resenc = rb_default_external_encoding(); if (!rb_enc_asciicompat(resenc)) resenc = rb_usascii_encoding(); rb_enc_associate(result, resenc); @@ -4210,6 +4213,12 @@ rb_str_inspect(VALUE str) p = RSTRING_PTR(str); pend = RSTRING_END(str); prev = p; + if (enc == utf16) { + enc = *p == (char)0xFF ? rb_enc_find("UTF-16LE") : rb_enc_find("UTF-16BE"); + } + else if (enc == utf32) { + enc = *p == (char)0xFF ? rb_enc_find("UTF-32LE") : rb_enc_find("UTF-32BE"); + } while (p < pend) { unsigned int c, cc; int n;