From d873f09705f13723474199671408857ca4e7431d Mon Sep 17 00:00:00 2001 From: matz Date: Thu, 13 Dec 2007 08:28:40 +0000 Subject: * string.c (rb_str_split_m): need not to check encoding if regexp is empty. * string.c (rb_str_justify): associate encoding of original to the result. * string.c (rb_str_chomp_bang): need to check encoding of record separator. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@14211 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- string.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'string.c') diff --git a/string.c b/string.c index d6c22dbfc..bacb18026 100644 --- a/string.c +++ b/string.c @@ -4091,7 +4091,9 @@ rb_str_split_m(int argc, VALUE *argv, VALUE str) int last_null = 0; struct re_registers *regs; - enc = rb_enc_check(str, spat); + if (RREGEXP(spat)->len != 0) { + enc = rb_enc_check(str, spat); + } while ((end = rb_reg_search(spat, str, start, 0)) >= 0) { regs = RMATCH(rb_backref_get())->regs; if (start == end && BEG(0) == END(0)) { @@ -4456,6 +4458,7 @@ rb_str_chomp_bang(int argc, VALUE *argv, VALUE str) } if (NIL_P(rs)) return Qnil; StringValue(rs); + rb_enc_check(str, rs); len = RSTRING_LEN(str); if (len == 0) return Qnil; p = RSTRING_PTR(str); @@ -4992,11 +4995,6 @@ rb_str_justify(int argc, VALUE *argv, VALUE str, char jflag) rb_raise(rb_eArgError, "zero width padding"); } } -#if 0 - else if (!m17n_asciicompat(enc)) { - rb_raise(rb_eArgError, "character encodings differ"); - } -#endif len = str_strlen(str, enc); if (width < 0 || len >= width) return rb_str_dup(str); n = width - len; @@ -5046,6 +5044,7 @@ rb_str_justify(int argc, VALUE *argv, VALUE str, char jflag) STR_SET_LEN(res, p-RSTRING_PTR(res)); OBJ_INFECT(res, str); if (!NIL_P(pad)) OBJ_INFECT(res, pad); + rb_enc_associate(res, enc); return res; } -- cgit