[macruby-changes] [4956] MacRuby/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Mon Nov 29 20:34:56 PST 2010
Revision: 4956
http://trac.macosforge.org/projects/ruby/changeset/4956
Author: watson1978 at gmail.com
Date: 2010-11-29 20:34:52 -0800 (Mon, 29 Nov 2010)
Log Message:
-----------
will support the \G of Regexp. fixed the #1012.
Modified Paths:
--------------
MacRuby/trunk/re.c
MacRuby/trunk/re.h
Modified: MacRuby/trunk/re.c
===================================================================
--- MacRuby/trunk/re.c 2010-11-30 02:11:47 UTC (rev 4955)
+++ MacRuby/trunk/re.c 2010-11-30 04:34:52 UTC (rev 4956)
@@ -747,8 +747,8 @@
xfree((void *)matcher);
}
-int
-rb_reg_matcher_search(VALUE re, VALUE matcher, int pos, bool reverse)
+static int
+rb_reg_matcher_search_find(VALUE re, VALUE matcher, int pos, bool reverse, bool findFirst)
{
rb_regexp_matcher_t *re_matcher = (rb_regexp_matcher_t *)matcher;
@@ -763,7 +763,7 @@
if (chars_len < 0) {
chars_len = 0;
}
-
+
if (pos > chars_len || pos < 0) {
rb_backref_set(Qnil);
return -1;
@@ -785,10 +785,15 @@
return -1;
}
}
- else if (!uregex_find(re_matcher->pattern, pos, &status)) {
- // No match.
- rb_backref_set(Qnil);
- return -1;
+ else {
+ if (findFirst) {
+ uregex_setRegion(re_matcher->pattern, pos, chars_len, &status);
+ }
+ if (!uregex_findNext(re_matcher->pattern, &status)) {
+ // No match.
+ rb_backref_set(Qnil);
+ return -1;
+ }
}
// Match found.
@@ -839,6 +844,18 @@
return res[0].beg;
}
+int
+rb_reg_matcher_search_first(VALUE re, VALUE matcher, int pos, bool reverse)
+{
+ return rb_reg_matcher_search_find(re, matcher, pos, reverse, true);
+}
+
+int
+rb_reg_matcher_search_next(VALUE re, VALUE matcher, int pos, bool reverse)
+{
+ return rb_reg_matcher_search_find(re, matcher, pos, reverse, false);
+}
+
static long
reg_match_pos(VALUE re, VALUE *strp, long pos)
{
Modified: MacRuby/trunk/re.h
===================================================================
--- MacRuby/trunk/re.h 2010-11-30 02:11:47 UTC (rev 4955)
+++ MacRuby/trunk/re.h 2010-11-30 04:34:52 UTC (rev 4956)
@@ -25,13 +25,15 @@
VALUE rb_reg_matcher_new(VALUE re, VALUE str);
void rb_reg_matcher_destroy(VALUE matcher);
-int rb_reg_matcher_search(VALUE re, VALUE matcher, int pos, bool reverse);
+int rb_reg_matcher_search_first(VALUE re, VALUE matcher, int pos, bool reverse);
+int rb_reg_matcher_search_next(VALUE re, VALUE matcher, int pos, bool reverse);
+#define rb_reg_matcher_search rb_reg_matcher_search_next
static inline int
rb_reg_search(VALUE re, VALUE str, int pos, bool reverse)
{
VALUE matcher = rb_reg_matcher_new(re, str);
- const int res = rb_reg_matcher_search(re, matcher, pos, reverse);
+ const int res = rb_reg_matcher_search_first(re, matcher, pos, reverse);
rb_reg_matcher_destroy(matcher);
return res;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20101129/68dfa78e/attachment.html>
More information about the macruby-changes
mailing list