diff options
author | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-09-15 05:27:29 +0000 |
---|---|---|
committer | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-09-15 05:27:29 +0000 |
commit | a8154060ab975888988607aad0ea6e9eceb120a9 (patch) | |
tree | 000107f03be24a24f0be0e5296ef42b39a616f3a | |
parent | c59abe419d77c6e9346467f47d9b2e60bd45d7fc (diff) | |
download | ruby-a8154060ab975888988607aad0ea6e9eceb120a9.tar.gz |
Use rb_isspace for ASCII-incompatible strings.
* string.c (rb_str_split_m): use rb_isspace when the string
may be ASCII-incompatible.
(rb_str_lstrip_bang): ditto.
(rb_str_rstrip_bang): ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24934 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | string.c | 8 | ||||
-rw-r--r-- | test/ruby/test_string.rb | 5 |
3 files changed, 18 insertions, 4 deletions
@@ -1,3 +1,12 @@ +Tue Sep 15 14:24:52 2009 NARUSE, Yui <naruse@ruby-lang.org> + + * string.c (rb_str_split_m): use rb_isspace when the + string may be ASCII-incompatible. + + * string.c (rb_str_lstrip_bang): ditto. + + * string.c (rb_str_rstrip_bang): ditto. + Tue Sep 15 12:12:27 2009 Nobuyoshi Nakada <nobu@ruby-lang.org> * configure.in (RUBY_USE_BUILTIN_FRAME_ADDRESS): check after real @@ -5669,7 +5669,7 @@ rb_str_split_m(int argc, VALUE *argv, VALUE str) c = rb_enc_codepoint_len(ptr, eptr, &n, enc); ptr += n; if (skip) { - if (ascii_isspace(c)) { + if (rb_isspace(c)) { beg = ptr - bptr; } else { @@ -5678,7 +5678,7 @@ rb_str_split_m(int argc, VALUE *argv, VALUE str) if (!NIL_P(limit) && lim <= i) break; } } - else if (ascii_isspace(c)) { + else if (rb_isspace(c)) { rb_ary_push(result, rb_str_subseq(str, beg, end-beg)); skip = 1; beg = ptr - bptr; @@ -6320,7 +6320,7 @@ rb_str_lstrip_bang(VALUE str) int n; unsigned int cc = rb_enc_codepoint_len(s, e, &n, enc); - if (!ascii_isspace(cc)) break; + if (!rb_isspace(cc)) break; s += n; } @@ -6389,7 +6389,7 @@ rb_str_rstrip_bang(VALUE str) while ((tp = rb_enc_prev_char(s, t, e, enc)) != NULL) { unsigned int c = rb_enc_codepoint(tp, e, enc); - if (c && !ascii_isspace(c)) break; + if (c && !rb_isspace(c)) break; t = tp; } } diff --git a/test/ruby/test_string.rb b/test/ruby/test_string.rb index 36a8f67442..f14e1e856d 100644 --- a/test/ruby/test_string.rb +++ b/test/ruby/test_string.rb @@ -1139,6 +1139,11 @@ class TestString < Test::Unit::TestCase def test_strip assert_equal(S("x"), S(" x ").strip) assert_equal(S("x"), S(" \n\r\t x \t\r\n\n ").strip) + + assert_equal("0b0 ".force_encoding("UTF-16BE"), + "\x00 0b0 ".force_encoding("UTF-16BE").strip) + assert_equal("0\x000b0 ".force_encoding("UTF-16BE"), + "0\x000b0 ".force_encoding("UTF-16BE").strip) end def test_strip! |