# New Ticket Created by  "Chris Davaz" 
# Please include the string:  [perl #58952]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=58952 >


Here is the implementation of the second argument to the comb method as
described in S29. Here is a test I wrote (which I'll commit to the pugs test
suite later):

my Str $hair = "Th3r3 4r3 s0m3 numb3rs 1n th1s str1ng";
say $hair.comb(/\d+/);
say $hair.comb(/\d+/, -10);
say $hair.comb(/\d+/, 0);
say $hair.comb(/\d+/, 1);
say $hair.comb(/\d+/, 3);
say $hair.comb(/\d+/, 9);
say $hair.comb(/\d+/, 10000000000000000);

The output being:

3343033111


3
334
334303311
3343033111
Index: src/builtins/any-str.pir
===================================================================
--- src/builtins/any-str.pir	(revision 31199)
+++ src/builtins/any-str.pir	(working copy)
@@ -45,6 +45,8 @@
 
 .sub comb :method :multi(_)
     .param pmc regex
+    .param int count        :optional
+    .param int has_count    :opt_flag
     .local pmc retv, match
     .local string s
 
@@ -54,6 +56,10 @@
   do_match:
     match = regex.'ACCEPTS'(s)
     unless match goto done
+    unless has_count goto skip_count
+    count -= 1
+    if count < 0 goto done
+  skip_count:
     # shouldn't have to coerce to Str here, but see RT #55962
     $S0 = match
     retv.'push'($S0)

Reply via email to