ruby-changes:12781
From: matz <ko1@a...>
Date: Wed, 12 Aug 2009 08:53:54 +0900 (JST)
Subject: [ruby-changes:12781] Ruby:r24507 (trunk): * sprintf.c (rb_str_format): should preserve format encoding
matz 2009-08-12 08:53:21 +0900 (Wed, 12 Aug 2009) New Revision: 24507 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=24507 Log: * sprintf.c (rb_str_format): should preserve format encoding before raising CompatibilityError. [ruby-list:46274] Modified files: trunk/ChangeLog trunk/sprintf.c Index: ChangeLog =================================================================== --- ChangeLog (revision 24506) +++ ChangeLog (revision 24507) @@ -1,3 +1,8 @@ +Wed Aug 12 08:39:15 2009 Yukihiro Matsumoto <matz@r...> + + * sprintf.c (rb_str_format): should preserve format encoding + before raising CompatibilityError. [ruby-list:46274] + Wed Aug 12 07:41:31 2009 NARUSE, Yui <naruse@r...> * encoding.c (rb_enc_compatible): If a string is empty and Index: sprintf.c =================================================================== --- sprintf.c (revision 24506) +++ sprintf.c (revision 24507) @@ -482,6 +482,10 @@ for (t = p; t < end && *t != '%'; t++) ; PUSH(p, t - p); + if (coderange != ENC_CODERANGE_BROKEN && scanned < blen) { + scanned = rb_str_coderange_scan_restartable(buf+scanned, buf+blen, enc, &coderange); + ENC_CODERANGE_SET(result, coderange); + } if (t >= end) { /* end of fmt string */ goto sprint_exit; @@ -673,7 +677,7 @@ (cr == ENC_CODERANGE_UNKNOWN ? ENC_CODERANGE_BROKEN : (coderange = cr))); } - enc = rb_enc_check(result, str); + enc = rb_enc_check((RSTRING_LEN(result) == 0 ? fmt : result), str); if (flags&(FPREC|FWIDTH)) { slen = rb_enc_strlen(RSTRING_PTR(str),RSTRING_END(str),enc); if (slen < 0) { @@ -1055,10 +1059,6 @@ if (RTEST(ruby_debug)) rb_raise(rb_eArgError, "%s", mesg); if (RTEST(ruby_verbose)) rb_warn("%s", mesg); } - if (scanned < blen) { - rb_str_coderange_scan_restartable(buf+scanned, buf+blen, enc, &coderange); - ENC_CODERANGE_SET(result, coderange); - } rb_str_resize(result, blen); if (tainted) OBJ_TAINT(result); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/