diff options
author | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-02-24 07:40:44 +0000 |
---|---|---|
committer | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-02-24 07:40:44 +0000 |
commit | 6d90e595620d1b150aaf7c543ac4d56666d841b3 (patch) | |
tree | 6d5e160cddb9a70dd25bcdfed489f61339faf148 /string.c | |
parent | e6d4a21cb1242187cd6b06005b57ba637be2c694 (diff) |
merge revision(s) 49706: [Backport #10893]
* string.c (chompped_length): enable smart chomp for all non-dummy
encoding strings, not only default_rs.
[ruby-core:68258] [Bug #10893]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_2@49718 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r-- | string.c | 12 |
1 files changed, 7 insertions, 5 deletions
@@ -7109,9 +7109,9 @@ chompped_length(VALUE str, VALUE rs) if (len == 0) return 0; e = p + len; - enc = rb_enc_get(str); if (rs == rb_default_rs) { smart_chomp: + enc = rb_enc_get(str); if (rb_enc_mbminlen(enc) > 1) { pp = rb_enc_left_char_head(p, e-rb_enc_mbminlen(enc), e, enc); if (rb_enc_is_newline(pp, e, enc)) { @@ -7140,6 +7140,7 @@ chompped_length(VALUE str, VALUE rs) return e - p; } + enc = rb_enc_get(str); RSTRING_GETMEM(rs, rsptr, rslen); if (rslen == 0) { if (rb_enc_mbminlen(enc) > 1) { @@ -7167,10 +7168,7 @@ chompped_length(VALUE str, VALUE rs) } if (rslen > len) return len; - enc = rb_enc_check(str, rs); - if (is_broken_string(rs)) { - return len; - } + enc = rb_enc_get(rs); newline = rsptr[rslen-1]; if (rslen == rb_enc_mbminlen(enc)) { if (rslen == 1) { @@ -7183,6 +7181,10 @@ chompped_length(VALUE str, VALUE rs) } } + enc = rb_enc_check(str, rs); + if (is_broken_string(rs)) { + return len; + } pp = e - rslen; if (p[len-1] == newline && (rslen <= 1 || |