aboutsummaryrefslogtreecommitdiffstats
path: root/re.c
diff options
context:
space:
mode:
Diffstat (limited to 're.c')
-rw-r--r--re.c36
1 files changed, 9 insertions, 27 deletions
diff --git a/re.c b/re.c
index 35ad59b1a3..3764d75bb8 100644
--- a/re.c
+++ b/re.c
@@ -1035,7 +1035,7 @@ rb_reg_search(VALUE re, VALUE str, int pos, int reverse)
int result;
VALUE match;
static struct re_registers regs;
- int range;
+ char *range = RSTRING_PTR(str);
rb_encoding *enc = rb_enc_get(str);
if (pos > RSTRING_LEN(str) || pos < 0) {
@@ -1045,33 +1045,15 @@ rb_reg_search(VALUE re, VALUE str, int pos, int reverse)
rb_reg_prepare_re(re, str);
- if (reverse) {
- char *p = RSTRING_PTR(str) + pos;
- while (1) {
- result = onig_match(RREGEXP(re)->ptr,
- (UChar*)(RSTRING_PTR(str)),
- ((UChar*)(RSTRING_PTR(str)) + RSTRING_LEN(str)),
- (UChar*)p,
- &regs,
- ONIG_OPTION_NONE);
- if (result != ONIG_MISMATCH) {
- result = p - RSTRING_PTR(str);
- break;
- }
- if (RSTRING_PTR(str) == p)
- break;
- p = rb_enc_prev_char(RSTRING_PTR(str), p, enc);
- }
- }
- else {
- range = RSTRING_LEN(str) - pos;
- result = onig_search(RREGEXP(re)->ptr,
- (UChar*)(RSTRING_PTR(str)),
- ((UChar*)(RSTRING_PTR(str)) + RSTRING_LEN(str)),
- ((UChar*)(RSTRING_PTR(str)) + pos),
- ((UChar*)(RSTRING_PTR(str)) + pos + range),
- &regs, ONIG_OPTION_NONE);
+ if (!reverse) {
+ range += RSTRING_LEN(str);
}
+ result = onig_search(RREGEXP(re)->ptr,
+ (UChar*)(RSTRING_PTR(str)),
+ ((UChar*)(RSTRING_PTR(str)) + RSTRING_LEN(str)),
+ ((UChar*)(RSTRING_PTR(str)) + pos),
+ ((UChar*)range),
+ &regs, ONIG_OPTION_NONE);
if (result < 0) {
if (result == ONIG_MISMATCH) {