[macruby-changes] [3816] MacRuby/trunk/re.cpp

source_changes at macosforge.org source_changes at macosforge.org
Thu Mar 18 19:10:22 PDT 2010


Revision: 3816
          http://trac.macosforge.org/projects/ruby/changeset/3816
Author:   lsansonetti at apple.com
Date:     2010-03-18 19:10:21 -0700 (Thu, 18 Mar 2010)
Log Message:
-----------
added support for reverse regexps (naive but working)

Modified Paths:
--------------
    MacRuby/trunk/re.cpp

Modified: MacRuby/trunk/re.cpp
===================================================================
--- MacRuby/trunk/re.cpp	2010-03-19 02:09:47 UTC (rev 3815)
+++ MacRuby/trunk/re.cpp	2010-03-19 02:10:21 UTC (rev 3816)
@@ -553,10 +553,6 @@
 int
 rb_reg_search(VALUE re, VALUE str, int pos, bool reverse)
 {
-    if (reverse) {
-	rb_raise(rb_eRuntimeError, "reverse searching is not implemented yet");
-    }
-
     const long len = rb_str_chars_len(str);
     if (pos > len || pos < 0) {
 	rb_backref_set(Qnil);
@@ -576,8 +572,24 @@
 		u_errorName(status));
     }
 
-    if (!matcher->find(pos, status)) {
+    if (reverse) {
+	const int orig = pos;
+	while (pos >= 0) {
+	    if (matcher->find(pos, status)) {
+		if (matcher->start(status) <= orig) {
+		    break;
+		}
+	    }
+	    pos--;
+	}
+	if (pos < 0) {
+	    // No match.
+	    goto no_match;
+	}
+    }
+    else if (!matcher->find(pos, status)) {
 	// No match.
+no_match:
 	rb_backref_set(Qnil);
 	delete matcher;
 	delete unistr;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20100318/6166ecff/attachment.html>


More information about the macruby-changes mailing list