ruby-changes:17882
From: naruse <ko1@a...>
Date: Wed, 24 Nov 2010 11:20:21 +0900 (JST)
Subject: [ruby-changes:17882] Ruby:r29896 (trunk): * string.c (rb_str_inspect): treat UTF-16 and UTF-32 as BE or LE.
naruse 2010-11-24 11:20:11 +0900 (Wed, 24 Nov 2010) New Revision: 29896 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=29896 Log: * string.c (rb_str_inspect): treat UTF-16 and UTF-32 as BE or LE. Modified files: trunk/ChangeLog trunk/string.c Index: ChangeLog =================================================================== --- ChangeLog (revision 29895) +++ ChangeLog (revision 29896) @@ -1,3 +1,7 @@ +Wed Nov 24 11:19:13 2010 NARUSE, Yui <naruse@r...> + + * string.c (rb_str_inspect): treat UTF-16 and UTF-32 as BE or LE. + Wed Nov 24 06:35:32 2010 NARUSE, Yui <naruse@r...> * enc/trans/utf_16_32.trans: add the UTF-32 converter. Index: string.c =================================================================== --- string.c (revision 29895) +++ string.c (revision 29896) @@ -4202,7 +4202,10 @@ 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 @@ 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; -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/