ruby-changes:3619
From: ko1@a...
Date: Fri, 18 Jan 2008 13:51:35 +0900 (JST)
Subject: [ruby-changes:3619] matz - Ruby:r15108 (trunk): * string.c (rb_str_dump): preserve the encoding of source string
matz 2008-01-18 13:49:14 +0900 (Fri, 18 Jan 2008) New Revision: 15108 Modified files: trunk/ChangeLog trunk/string.c Log: * string.c (rb_str_dump): preserve the encoding of source string if it is ASCII compatible. otherwise, add '.force_encoding()' for ugly work around. maybe we should implement some other way to keep non ASCII encoding in dumped string. [ruby-dev:33142] http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/string.c?r1=15108&r2=15107&diff_format=u http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=15108&r2=15107&diff_format=u Index: ChangeLog =================================================================== --- ChangeLog (revision 15107) +++ ChangeLog (revision 15108) @@ -98,6 +98,13 @@ * lib/date.rb, lib/date/format.rb: some trivial changes. +Thu Jan 17 13:07:18 2008 Yukihiro Matsumoto <matz@r...> + + * string.c (rb_str_dump): preserve the encoding of source string + if it is ASCII compatible. otherwise, add '.force_encoding()' + for ugly work around. maybe we should implement some other way + to keep non ASCII encoding in dumped string. [ruby-dev:33142] + Thu Jan 17 10:30:32 2008 Yukihiro Matsumoto <matz@r...> * io.c (io_fwrite): always flush IO on tty, even without newlines. Index: string.c =================================================================== --- string.c (revision 15107) +++ string.c (revision 15108) @@ -3210,6 +3210,7 @@ VALUE rb_str_dump(VALUE str) { + rb_encoding *enc0 = rb_enc_get(str); rb_encoding *enc = rb_enc_from_index(0); long len; char *p, *pend; @@ -3242,6 +3243,10 @@ break; } } + if (!rb_enc_asciicompat(enc0)) { + len += 19; /* ".force_encoding('')" */ + len += strlen(enc0->name); + } result = rb_str_new5(str, 0, len); p = RSTRING_PTR(str); pend = p + RSTRING_LEN(str); @@ -3301,10 +3306,14 @@ } } *q++ = '"'; + if (!rb_enc_asciicompat(enc0)) { + sprintf(q, ".force_encoding(\"%s\")", enc0->name); + enc0 = enc; + } OBJ_INFECT(result, str); /* result from dump is ASCII */ - rb_enc_associate(result, enc); + rb_enc_associate(result, enc0); return result; } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/