# New Ticket Created by  Patrick R. Michaud 
# Please include the string:  [perl #35410]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org/rt3/Ticket/Display.html?id=35410 >


The attached patch modifies find_cclass and find_not_cclass
to return the length of the string when no matching character
is found (previously these ops returned -1).  

The patch also updates the tests in t/op/string_cclass.t to
test the new behavior.

Pm
Index: charset/iso-8859-1.c
===================================================================
--- charset/iso-8859-1.c        (revision 8056)
+++ charset/iso-8859-1.c        (working copy)
@@ -347,7 +347,7 @@
             return pos;
         }
     }
-    return -1;
+    return end;
 }
 
 static INTVAL
@@ -365,7 +365,7 @@
             return pos;
         }
     }
-    return -1;
+    return end;
 }
 
 
Index: charset/ascii.c
===================================================================
--- charset/ascii.c     (revision 8056)
+++ charset/ascii.c     (working copy)
@@ -580,7 +580,7 @@
             return pos;
         }
     }
-    return -1;
+    return end;
 }
 
 static INTVAL
@@ -598,7 +598,7 @@
             return pos;
         }
     }
-    return -1;
+    return end;
 }
 
 /*
Index: t/op/string_cclass.t
===================================================================
--- t/op/string_cclass.t        (revision 8056)
+++ t/op/string_cclass.t        (working copy)
@@ -35,30 +35,30 @@
     .param string str
     .param int flags
     $I0 = 0
+    $I2 = length str
 loop:
-    $I0 = find_cclass flags, str, $I0, 100
-    if $I0 == -1 goto end
-    print $I0
+    $I1 = find_cclass flags, str, $I0, 100
+    print $I1
     print ";"
     inc $I0
-    branch loop
+    if $I0 <= $I2 goto loop
 end:
     print "\n"
 .end
 CODE
-0;1;2;3;4;5;6;7;8;10;
-6;7;
-0;1;
-4;8;12;
+0;1;2;3;4;5;6;7;8;10;10;12;12;
+6;6;6;6;6;6;6;7;13;13;13;13;13;13;
+0;1;13;13;13;13;13;13;13;13;13;13;13;13;
+4;4;4;4;4;8;8;8;8;12;12;12;12;13;
 OUT
 
-pir_output_is(<<'CODE', <<'OUT', "find_cclass, iso-8859-1");
+pir_output_is(<<'CODE', <<'OUT', "find_not_cclass, ascii");
 .include "cclass.pasm"
 .sub main @MAIN
-    $S0 = iso-8859-1:"test_func(1)"
+    $S0 = ascii:"test_func(1)"
     test( .CCLASS_WORD, $S0 )
     
-    $S0 = iso-8859-1:"ab\nC_X34.\0 \t!"
+    $S0 = ascii:"ab\nC_X34.\0 \t!"
     test( .CCLASS_NUMERIC, $S0 )
     test( .CCLASS_LOWERCASE, $S0 )
     test( .CCLASS_PUNCTUATION, $S0 )
@@ -67,30 +67,30 @@
     .param string str
     .param int flags
     $I0 = 0
+    $I2 = length str
 loop:
-    $I0 = find_cclass flags, str, $I0, 100
-    if $I0 == -1 goto end
-    print $I0
+    $I1 = find_not_cclass flags, str, $I0, 100
+    print $I1
     print ";"
     inc $I0
-    branch loop
+    if $I0 <= $I2 goto loop
 end:
     print "\n"
 .end
 CODE
-0;1;2;3;4;5;6;7;8;10;
-6;7;
-0;1;
-4;8;12;
+9;9;9;9;9;9;9;9;9;9;11;11;12;
+0;1;2;3;4;5;8;8;8;9;10;11;12;13;
+2;2;2;3;4;5;6;7;8;9;10;11;12;13;
+0;1;2;3;5;5;6;7;9;9;10;11;13;13;
 OUT
 
-pir_output_is(<<'CODE', <<'OUT', "find_not_cclass, ascii");
+pir_output_is(<<'CODE', <<'OUT', "find_cclass, iso-8859-1");
 .include "cclass.pasm"
 .sub main @MAIN
-    $S0 = ascii:"test_func(1)"
+    $S0 = iso-8859-1:"test_func(1)"
     test( .CCLASS_WORD, $S0 )
     
-    $S0 = ascii:"ab\nC_X34.\0 \t!"
+    $S0 = iso-8859-1:"ab\nC_X34.\0 \t!"
     test( .CCLASS_NUMERIC, $S0 )
     test( .CCLASS_LOWERCASE, $S0 )
     test( .CCLASS_PUNCTUATION, $S0 )
@@ -99,21 +99,21 @@
     .param string str
     .param int flags
     $I0 = 0
+    $I2 = length str
 loop:
-    $I0 = find_not_cclass flags, str, $I0, 100
-    if $I0 == -1 goto end
-    print $I0
+    $I1 = find_cclass flags, str, $I0, 100
+    print $I1
     print ";"
     inc $I0
-    branch loop
+    if $I0 <= $I2 goto loop
 end:
     print "\n"
 .end
 CODE
-9;11;
-0;1;2;3;4;5;8;9;10;11;12;
-2;3;4;5;6;7;8;9;10;11;12;
-0;1;2;3;5;6;7;9;10;11;
+0;1;2;3;4;5;6;7;8;10;10;12;12;
+6;6;6;6;6;6;6;7;13;13;13;13;13;13;
+0;1;13;13;13;13;13;13;13;13;13;13;13;13;
+4;4;4;4;4;8;8;8;8;12;12;12;12;13;
 OUT
 
 pir_output_is(<<'CODE', <<'OUT', "find_not_cclass, iso-8859-1");
@@ -131,21 +131,21 @@
     .param string str
     .param int flags
     $I0 = 0
+    $I2 = length str
 loop:
-    $I0 = find_not_cclass flags, str, $I0, 100
-    if $I0 == -1 goto end
-    print $I0
+    $I1 = find_not_cclass flags, str, $I0, 100
+    print $I1
     print ";"
     inc $I0
-    branch loop
+    if $I0 <= $I2 goto loop
 end:
     print "\n"
 .end
 CODE
-9;11;
-0;1;2;3;4;5;8;9;10;11;12;
-2;3;4;5;6;7;8;9;10;11;12;
-0;1;2;3;5;6;7;9;10;11;
+9;9;9;9;9;9;9;9;9;9;11;11;12;
+0;1;2;3;4;5;8;8;8;9;10;11;12;13;
+2;2;2;3;4;5;6;7;8;9;10;11;12;13;
+0;1;2;3;5;5;6;7;9;9;10;11;13;13;
 OUT
 
 pir_output_is(<<'CODE', <<'OUT', "is_cclass, ascii");

Reply via email to