Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Change .match to support the new list approach for :nth.

  • Loading branch information...
commit 475d1c77fba6ff29c93c347336c51d203675b926 1 parent bafb6d9
@colomon colomon authored
Showing with 18 additions and 2 deletions.
  1. +18 −2 src/core/Cool-str.pm
View
20 src/core/Cool-str.pm
@@ -186,7 +186,7 @@ augment class Cool {
:g(:$global),
:pos(:$p),
:$x,
- Mu :$nth,
+ :$nth,
:ov(:$overlap)) {
if $continue ~~ Bool {
note ":c / :continue requires a position in the string";
@@ -206,13 +206,29 @@ augment class Cool {
}
if $global || $nth.defined || $overlap || ($x.defined && $x_upper > 1) {
+ my $next-index;
+ my $next-iterator;
+ if $nth.defined {
+ $next-iterator = $nth.list.iterator;
+ $next-index = $next-iterator.get;
+ return if $next-index ~~ EMPTY || +$next-index < 1;
+ }
+
my $taken = 0;
my $i = 1;
my @r = gather while my $m = Regex::Cursor.parse(self, :rule($pat), |%opts) {
my $m-copy = $m;
- if !$nth.defined || ($i ~~ any |$nth) {
+ if !$nth.defined || $i == $next-index {
take $m-copy;
$taken++;
+
+ if ($nth.defined) {
+ $next-index = $next-iterator.get;
+ while $next-index !~~ EMPTY && $next-index <= $i {
+ $next-index = $next-iterator.get;
+ }
+ last if $next-index ~~ EMPTY;
+ }
}
last if $taken == $x_upper;
Please sign in to comment.
Something went wrong with that request. Please try again.