From 6b7b84edc7168786408b0757e2eb53728d1b71a6 Mon Sep 17 00:00:00 2001 From: matz Date: Wed, 6 May 1998 03:09:03 +0000 Subject: new exception model git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1r@202 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- re.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 're.c') diff --git a/re.c b/re.c index daf285708c..d4455c349b 100644 --- a/re.c +++ b/re.c @@ -411,37 +411,38 @@ reg_prepare_re(reg) } int -reg_search(reg, str, start, regs) +reg_search(reg, str, start, reverse) VALUE reg, str; - int start; - struct re_registers *regs; + int start, reverse; { int result; int casefold = RTEST(ignorecase); VALUE match = 0; - struct re_registers *regs0 = 0; + struct re_registers *regs = 0; + int range; int need_recompile = 0; if (start > RSTRING(str)->len) return -1; reg_prepare_re(reg); - if (regs == (struct re_registers*)-1) { - regs = 0; + if (matchcache) { + match = matchcache; + matchcache = 0; } else { - if (matchcache) { - match = matchcache; - matchcache = 0; - } - else { - match = match_alloc(); - } - regs0 = RMATCH(match)->regs; + match = match_alloc(); } + regs = RMATCH(match)->regs; + if (reverse) { + range = -start; + } + else { + range = RSTRING(str)->len-start; + } result = re_search(RREGEXP(reg)->ptr,RSTRING(str)->ptr,RSTRING(str)->len, - start,RSTRING(str)->len-start,regs0); + start, range, regs); kcode_reset_option(); if (start == -2) { @@ -456,7 +457,6 @@ reg_search(reg, str, start, regs) RMATCH(match)->str = str_new4(str); backref_set(match); } - if (regs && regs0) re_copy_registers(regs, regs0); return result; } @@ -725,7 +725,7 @@ reg_match(re, str) { int start; - if (TYPE(str) != T_STRING) return FALSE; + str = str_to_str(str); start = reg_search(re, str, 0, 0); if (start < 0) { return FALSE; -- cgit v1.2.3