diff options
author | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-10-21 06:51:01 +0000 |
---|---|---|
committer | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-10-21 06:51:01 +0000 |
commit | 6187b0001b4df62ff38bb53b79f0501993570032 (patch) | |
tree | a70f09643462b6580960ff6949a1d642872b423b /string.c | |
parent | ae2578f6bc3f62bc4bc768be602067bd536fd3fe (diff) | |
download | ruby-6187b0001b4df62ff38bb53b79f0501993570032.tar.gz |
[Feature #13712] String#start_with? supports regexp
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60234 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r-- | string.c | 19 |
1 files changed, 14 insertions, 5 deletions
@@ -9219,11 +9219,20 @@ rb_str_start_with(int argc, VALUE *argv, VALUE str) for (i=0; i<argc; i++) { VALUE tmp = argv[i]; - StringValue(tmp); - rb_enc_check(str, tmp); - if (RSTRING_LEN(str) < RSTRING_LEN(tmp)) continue; - if (memcmp(RSTRING_PTR(str), RSTRING_PTR(tmp), RSTRING_LEN(tmp)) == 0) - return Qtrue; + switch (TYPE(tmp)) { + case T_REGEXP: + { + bool r = rb_reg_start_with_p(tmp, str); + if (r) return Qtrue; + } + break; + default: + StringValue(tmp); + rb_enc_check(str, tmp); + if (RSTRING_LEN(str) < RSTRING_LEN(tmp)) continue; + if (memcmp(RSTRING_PTR(str), RSTRING_PTR(tmp), RSTRING_LEN(tmp)) == 0) + return Qtrue; + } } return Qfalse; } |