diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-08-22 17:10:00 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-08-22 17:10:00 +0000 |
commit | bd6fe32691d7f71facd96c7e059161bd98946887 (patch) | |
tree | 1685c7f9a014271bcaa5fff7bbf2c2782aae33bc /string.c | |
parent | 4e5114b0d17aff091267656705c3586ed24b9e1c (diff) | |
download | ruby-bd6fe32691d7f71facd96c7e059161bd98946887.tar.gz |
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
Diffstat (limited to 'string.c')
-rw-r--r-- | string.c | 25 |
1 files changed, 19 insertions, 6 deletions
@@ -7003,6 +7003,16 @@ rb_str_count(int argc, VALUE *argv, VALUE str) 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] = { 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, @@ -7094,11 +7104,17 @@ rb_str_split_m(int argc, VALUE *argv, VALUE 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; } - else { - spat = get_pat_quoted(spat, 0); + else if (!(spat = rb_fs_check(spat))) { + rb_raise(rb_eTypeError, "value of $; must be String or Regexp"); + } + if (split_type != awk) { if (BUILTIN_TYPE(spat) == T_STRING) { 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(); |