string.c: $; name in error message
* string.c (rb_str_split_m): show $; name in error message when it is a wrong object. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55986 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
4e5114b0d1
commit
bd6fe32691
@ -1,3 +1,8 @@
|
|||||||
|
Tue Aug 23 02:09:57 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* string.c (rb_str_split_m): show $; name in error message when it
|
||||||
|
is a wrong object.
|
||||||
|
|
||||||
Mon Aug 22 16:29:52 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Mon Aug 22 16:29:52 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* lib/csv.rb (CSV#shift): store partial quoted strings in an array
|
* lib/csv.rb (CSV#shift): store partial quoted strings in an array
|
||||||
|
25
string.c
25
string.c
@ -7003,6 +7003,16 @@ rb_str_count(int argc, VALUE *argv, VALUE str)
|
|||||||
return INT2NUM(i);
|
return INT2NUM(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static VALUE
|
||||||
|
rb_fs_check(VALUE val)
|
||||||
|
{
|
||||||
|
if (!NIL_P(val) && !RB_TYPE_P(val, T_STRING) && !RB_TYPE_P(val, T_REGEXP)) {
|
||||||
|
val = rb_check_string_type(val);
|
||||||
|
if (NIL_P(val)) return 0;
|
||||||
|
}
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
static const char isspacetable[256] = {
|
static const char isspacetable[256] = {
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
@ -7094,11 +7104,17 @@ rb_str_split_m(int argc, VALUE *argv, VALUE str)
|
|||||||
}
|
}
|
||||||
|
|
||||||
enc = STR_ENC_GET(str);
|
enc = STR_ENC_GET(str);
|
||||||
if (NIL_P(spat) && NIL_P(spat = rb_fs)) {
|
split_type = regexp;
|
||||||
|
if (!NIL_P(spat)) {
|
||||||
|
spat = get_pat_quoted(spat, 0);
|
||||||
|
}
|
||||||
|
else if (NIL_P(spat = rb_fs)) {
|
||||||
split_type = awk;
|
split_type = awk;
|
||||||
}
|
}
|
||||||
else {
|
else if (!(spat = rb_fs_check(spat))) {
|
||||||
spat = get_pat_quoted(spat, 0);
|
rb_raise(rb_eTypeError, "value of $; must be String or Regexp");
|
||||||
|
}
|
||||||
|
if (split_type != awk) {
|
||||||
if (BUILTIN_TYPE(spat) == T_STRING) {
|
if (BUILTIN_TYPE(spat) == T_STRING) {
|
||||||
rb_encoding *enc2 = STR_ENC_GET(spat);
|
rb_encoding *enc2 = STR_ENC_GET(spat);
|
||||||
|
|
||||||
@ -7122,9 +7138,6 @@ rb_str_split_m(int argc, VALUE *argv, VALUE str)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
split_type = regexp;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
result = rb_ary_new();
|
result = rb_ary_new();
|
||||||
|
@ -1365,7 +1365,7 @@ CODE
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_split
|
def test_split
|
||||||
assert_nil($;)
|
fs, $; = $;, nil
|
||||||
assert_equal([S("a"), S("b"), S("c")], S(" a b\t c ").split)
|
assert_equal([S("a"), S("b"), S("c")], S(" a b\t c ").split)
|
||||||
assert_equal([S("a"), S("b"), S("c")], S(" a b\t c ").split(S(" ")))
|
assert_equal([S("a"), S("b"), S("c")], S(" a b\t c ").split(S(" ")))
|
||||||
|
|
||||||
@ -1389,6 +1389,13 @@ CODE
|
|||||||
assert_equal([], "".split(//, 1))
|
assert_equal([], "".split(//, 1))
|
||||||
|
|
||||||
assert_equal("[2, 3]", [1,2,3].slice!(1,10000).inspect, "moved from btest/knownbug")
|
assert_equal("[2, 3]", [1,2,3].slice!(1,10000).inspect, "moved from btest/knownbug")
|
||||||
|
|
||||||
|
$; = []
|
||||||
|
assert_raise_with_message(TypeError, /\$;/) {
|
||||||
|
"".split
|
||||||
|
}
|
||||||
|
ensure
|
||||||
|
$; = fs
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_split_encoding
|
def test_split_encoding
|
||||||
|
Loading…
x
Reference in New Issue
Block a user