[svn:parrot] r44496 - in trunk: src/string/charset t/op

coke at svn.parrot.org coke at svn.parrot.org
Fri Feb 26 15:47:24 UTC 2010


Author: coke
Date: Fri Feb 26 15:47:21 2010
New Revision: 44496
URL: https://trac.parrot.org/parrot/changeset/44496

Log:
Fix TT #1482

a partial match on the search string would not properly reset the source
string's iterator, causing a potential match further down the string to
be ignored.

pmichaud++ for the test.

Modified:
   trunk/src/string/charset/ascii.c
   trunk/t/op/string.t

Modified: trunk/src/string/charset/ascii.c
==============================================================================
--- trunk/src/string/charset/ascii.c	Fri Feb 26 14:42:32 2010	(r44495)
+++ trunk/src/string/charset/ascii.c	Fri Feb 26 15:47:21 2010	(r44496)
@@ -596,31 +596,37 @@
 {
     ASSERT_ARGS(mixed_cs_index)
     String_iter src_iter, search_iter;
-    UINTVAL len;
-    INTVAL start;
+    UINTVAL len, next_pos;
+    INTVAL found_at;
 
     ENCODING_ITER_INIT(interp, src, &src_iter);
     src_iter.set_position(interp, &src_iter, offs);
     ENCODING_ITER_INIT(interp, search, &search_iter);
     len = search->strlen;
 
-    start = -1;
-    for (; len && offs < src->strlen; ++offs) {
+    found_at = -1;
+    next_pos = offs;
+
+    for (; len && offs < src->strlen ;) {
         const UINTVAL c1 = src_iter.get_and_advance(interp, &src_iter);
         const UINTVAL c2 = search_iter.get_and_advance(interp, &search_iter);
+
         if (c1 == c2) {
             --len;
-            if (start == -1)
-                start = offs;
+            if (found_at == -1)
+                found_at = offs;
+            ++offs;
         }
         else {
             len = search->strlen;
-            start = -1;
+            found_at = -1;
+            offs = ++next_pos;
+            src_iter.set_position(interp, &src_iter, offs);
             search_iter.set_position(interp, &search_iter, 0);
         }
     }
     if (len == 0)
-        return start;
+        return found_at;
     return -1;
 }
 

Modified: trunk/t/op/string.t
==============================================================================
--- trunk/t/op/string.t	Fri Feb 26 14:42:32 2010	(r44495)
+++ trunk/t/op/string.t	Fri Feb 26 15:47:21 2010	(r44496)
@@ -19,7 +19,7 @@
 .sub main :main
     .include 'test_more.pir'
 
-    plan(411)
+    plan(412)
 
     set_s_s_sc()
     test_clone()
@@ -98,6 +98,7 @@
     index_three_arg_form()
     index_four_arg_form()
     index_four_arg_form_bug_twenty_two_thousand_seven_hundred_and_eighteen()
+    index_trac_1482()
     index_null_strings()
     index_embedded_nulls()
     index_big_strings()
@@ -982,6 +983,14 @@
     is( $I0, "2", 'index, 4-arg form, bug 22718' )
 .end
 
+.sub index_trac_1482
+    $S0 = unicode:"bubuc"
+    $S1 = unicode:"buc"
+
+    $I0 = index $S0, $S1, 0
+    is ($I0, 2, 'index, 4-arg, partial-match causes failure: TT #1482')
+.end
+
 .sub index_null_strings
     set $S0, "Parrot"
     set $S1, ""


More information about the parrot-commits mailing list