aboutsummaryrefslogtreecommitdiffstats
path: root/re.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-12-12 02:56:12 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-12-12 02:56:12 +0000
commit2a425a78156585ab584cbc145b64eab44f0d0787 (patch)
tree85a4ba28f3d0b584438569244f45d12dedec138e /re.c
parent2565d1fedc8c81fec29e9da0cfb5ef5ca6855ad8 (diff)
downloadruby-2a425a78156585ab584cbc145b64eab44f0d0787.tar.gz
String#match? and Symbol#match?
* string.c (rb_str_match_m_p): inverse of Regexp#match?. based on the patch by Herwin Weststrate <herwin@snt.utwente.nl>. [Fix GH-1483] [Feature #12898] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57053 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 're.c')
-rw-r--r--re.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/re.c b/re.c
index 95ba903480..17893dd8e8 100644
--- a/re.c
+++ b/re.c
@@ -3225,19 +3225,22 @@ rb_reg_match_m(int argc, VALUE *argv, VALUE re)
static VALUE
rb_reg_match_m_p(int argc, VALUE *argv, VALUE re)
{
- VALUE str, initpos;
- long pos = 0;
+ long pos = rb_check_arity(argc, 1, 2) > 1 ? NUM2LONG(argv[1]) : 0;
+ return rb_reg_match_p(re, argv[0], pos);
+}
+
+VALUE
+rb_reg_match_p(VALUE re, VALUE str, long pos)
+{
regex_t *reg;
onig_errmsg_buffer err = "";
OnigPosition result;
const UChar *start, *end;
int tmpreg;
- rb_scan_args(argc, argv, "11", &str, &initpos);
if (NIL_P(str)) return Qfalse;
- str = SYMBOL_P(str) ? rb_sym2str(str) : rb_str_to_str(str);
- if (argc == 2) {
- pos = NUM2LONG(initpos);
+ str = SYMBOL_P(str) ? rb_sym2str(str) : StringValue(str);
+ if (pos) {
if (pos < 0) {
pos += NUM2LONG(rb_str_length(str));
if (pos < 0) return Qfalse;