зеркало из https://github.com/github/ruby.git
* re.c (rb_reg_search): iterate onig_match for reverse mode.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14876 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
97751bbd5a
Коммит
52f9c1d2e1
|
@ -1,3 +1,7 @@
|
|||
Fri Jan 4 02:47:06 2008 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* re.c (rb_reg_search): iterate onig_match for reverse mode.
|
||||
|
||||
Fri Jan 4 01:20:21 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* win32.h: only VC6 needs extern "C++" for math.h. [ruby-talk:285660]
|
||||
|
|
21
re.c
21
re.c
|
@ -1036,6 +1036,7 @@ rb_reg_search(VALUE re, VALUE str, int pos, int reverse)
|
|||
VALUE match;
|
||||
static struct re_registers regs;
|
||||
int range;
|
||||
rb_encoding *enc = rb_enc_get(str);
|
||||
|
||||
if (pos > RSTRING_LEN(str) || pos < 0) {
|
||||
rb_backref_set(Qnil);
|
||||
|
@ -1045,18 +1046,32 @@ rb_reg_search(VALUE re, VALUE str, int pos, int reverse)
|
|||
rb_reg_prepare_re(re, str);
|
||||
|
||||
if (reverse) {
|
||||
range = -pos;
|
||||
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,
|
||||
®s,
|
||||
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),
|
||||
®s, ONIG_OPTION_NONE);
|
||||
}
|
||||
|
||||
if (result < 0) {
|
||||
if (result == ONIG_MISMATCH) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче