[前][次][番号順一覧][スレッド一覧]

ruby-changes:3383

From: ko1@a...
Date: 4 Jan 2008 02:48:29 +0900
Subject: [ruby-changes:3383] akr - Ruby:r14876 (trunk): * re.c (rb_reg_search): iterate onig_match for reverse mode.

akr	2008-01-04 02:48:06 +0900 (Fri, 04 Jan 2008)

  New Revision: 14876

  Modified files:
    trunk/ChangeLog
    trunk/re.c

  Log:
    * re.c (rb_reg_search): iterate onig_match for reverse mode.


  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=14876&r2=14875&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/re.c?r1=14876&r2=14875&diff_format=u

Index: re.c
===================================================================
--- re.c	(revision 14875)
+++ re.c	(revision 14876)
@@ -1036,6 +1036,7 @@
     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,19 +1046,33 @@
     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,
+                                &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);
     }
 
-    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 (result < 0) {
 	if (result == ONIG_MISMATCH) {
 	    rb_backref_set(Qnil);
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 14875)
+++ ChangeLog	(revision 14876)
@@ -1,3 +1,7 @@
+Fri Jan  4 02:47:06 2008  Tanaka Akira  <akr@f...>
+
+	* re.c (rb_reg_search): iterate onig_match for reverse mode.
+
 Fri Jan  4 01:20:21 2008  Nobuyoshi Nakada  <nobu@r...>
 
 	* win32.h: only VC6 needs extern "C++" for math.h.  [ruby-talk:285660]

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml

[前][次][番号順一覧][スレッド一覧]