From d874dde2827e96dbbb09f89f4d9e671c43725eef Mon Sep 17 00:00:00 2001 From: matz Date: Wed, 19 Dec 2007 17:46:17 +0000 Subject: [PATCH] * string.c (rb_str_each_line): should consider rslen. * string.c (rb_str_buf_append): should propagate encoding. * string.c (rb_str_each_line): ditto. * test/ruby/test_m17n.rb (TestM17N::test_str_each_line): should check encoding as well. * test/ruby/test_m17n.rb (TestM17N::test_str_each_line): empty array can not propagate encoding; should not check. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14343 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 12 ++++++++++++ string.c | 7 ++++++- test/ruby/test_m17n.rb | 5 ++++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index bbdd00b82a..253ac87e3e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -47,6 +47,18 @@ Wed Dec 19 22:59:52 2007 Yukihiro Matsumoto * test/ruby/test_m17n.rb (TestM17N::test_str_insert): test updated to check negative offset behavior. + * string.c (rb_str_each_line): should consider rslen. + + * string.c (rb_str_buf_append): should propagate encoding. + + * string.c (rb_str_each_line): ditto. + + * test/ruby/test_m17n.rb (TestM17N::test_str_each_line): should + check encoding as well. + + * test/ruby/test_m17n.rb (TestM17N::test_str_each_line): empty + array can not propagate encoding; should not check. + Wed Dec 19 21:42:18 2007 Nobuyoshi Nakada * re.c (rb_reg_regsub): should set checked encoding. diff --git a/string.c b/string.c index 2646c8ed30..5e6e0ae626 100644 --- a/string.c +++ b/string.c @@ -1007,8 +1007,10 @@ rb_str_cat2(VALUE str, const char *ptr) VALUE rb_str_buf_append(VALUE str, VALUE str2) { + rb_encoding *enc; long capa, len; + enc = rb_enc_check(str, str2); rb_str_modify(str); if (STR_ASSOC_P(str)) { FL_UNSET(str, STR_ASSOC); @@ -1031,6 +1033,7 @@ rb_str_buf_append(VALUE str, VALUE str2) RSTRING_PTR(str2), RSTRING_LEN(str2)+1); STR_SET_LEN(str, len); OBJ_INFECT(str, str2); + rb_enc_associate(str, enc); return str; } @@ -4288,9 +4291,10 @@ rb_str_each_line(int argc, VALUE *argv, VALUE str) (rslen <= 1 || memcmp(RSTRING_PTR(rs), p, rslen) == 0)) { line = rb_str_new5(str, s, p - s + (rslen ? rslen : n)); OBJ_INFECT(line, str); + rb_enc_copy(line, str); rb_yield(line); str_mod_check(str, ptr, len); - s = p + n; + s = p + (rslen ? rslen : n); } p += n; } @@ -4299,6 +4303,7 @@ rb_str_each_line(int argc, VALUE *argv, VALUE str) if (p > pend) p = pend; line = rb_str_new5(str, s, p - s); OBJ_INFECT(line, str); + rb_enc_copy(line, str); rb_yield(line); } diff --git a/test/ruby/test_m17n.rb b/test/ruby/test_m17n.rb index d723470dd2..a0f3428c3d 100644 --- a/test/ruby/test_m17n.rb +++ b/test/ruby/test_m17n.rb @@ -1201,7 +1201,10 @@ class TestM17N < Test::Unit::TestCase assert_equal(s1.encoding, line.encoding) lines << line } - assert_equal(s1, lines.join('')) + next if lines.size == 0 + s2 = lines.join('') + assert_equal(s1.encoding, s2.encoding) + assert_equal(s1, s2) } end