mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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
This commit is contained in:
parent
c59abe419d
commit
a8154060ab
3 changed files with 18 additions and 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>
|
Tue Sep 15 12:12:27 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* configure.in (RUBY_USE_BUILTIN_FRAME_ADDRESS): check after real
|
* configure.in (RUBY_USE_BUILTIN_FRAME_ADDRESS): check after real
|
||||||
|
|
8
string.c
8
string.c
|
@ -5669,7 +5669,7 @@ rb_str_split_m(int argc, VALUE *argv, VALUE str)
|
||||||
c = rb_enc_codepoint_len(ptr, eptr, &n, enc);
|
c = rb_enc_codepoint_len(ptr, eptr, &n, enc);
|
||||||
ptr += n;
|
ptr += n;
|
||||||
if (skip) {
|
if (skip) {
|
||||||
if (ascii_isspace(c)) {
|
if (rb_isspace(c)) {
|
||||||
beg = ptr - bptr;
|
beg = ptr - bptr;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -5678,7 +5678,7 @@ rb_str_split_m(int argc, VALUE *argv, VALUE str)
|
||||||
if (!NIL_P(limit) && lim <= i) break;
|
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));
|
rb_ary_push(result, rb_str_subseq(str, beg, end-beg));
|
||||||
skip = 1;
|
skip = 1;
|
||||||
beg = ptr - bptr;
|
beg = ptr - bptr;
|
||||||
|
@ -6320,7 +6320,7 @@ rb_str_lstrip_bang(VALUE str)
|
||||||
int n;
|
int n;
|
||||||
unsigned int cc = rb_enc_codepoint_len(s, e, &n, enc);
|
unsigned int cc = rb_enc_codepoint_len(s, e, &n, enc);
|
||||||
|
|
||||||
if (!ascii_isspace(cc)) break;
|
if (!rb_isspace(cc)) break;
|
||||||
s += n;
|
s += n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6389,7 +6389,7 @@ rb_str_rstrip_bang(VALUE str)
|
||||||
|
|
||||||
while ((tp = rb_enc_prev_char(s, t, e, enc)) != NULL) {
|
while ((tp = rb_enc_prev_char(s, t, e, enc)) != NULL) {
|
||||||
unsigned int c = rb_enc_codepoint(tp, e, enc);
|
unsigned int c = rb_enc_codepoint(tp, e, enc);
|
||||||
if (c && !ascii_isspace(c)) break;
|
if (c && !rb_isspace(c)) break;
|
||||||
t = tp;
|
t = tp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1139,6 +1139,11 @@ class TestString < Test::Unit::TestCase
|
||||||
def test_strip
|
def test_strip
|
||||||
assert_equal(S("x"), S(" x ").strip)
|
assert_equal(S("x"), S(" x ").strip)
|
||||||
assert_equal(S("x"), S(" \n\r\t x \t\r\n\n ").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
|
end
|
||||||
|
|
||||||
def test_strip!
|
def test_strip!
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue