Skip to content

Instantly share code, notes, and snippets.

@dogbert17
Last active May 14, 2017 18:03
Show Gist options
  • Save dogbert17/d76977c986df929f5febd14ea308ea74 to your computer and use it in GitHub Desktop.
Save dogbert17/d76977c986df929f5febd14ea308ea74 to your computer and use it in GitHub Desktop.
Attempt to document Str.indices
=head2 method indices
Defined as:
multi method indices(Str:D: Str:D $needle, :$overlap --> List:D)
multi method indices(Str:D: Str:D $needle, Int:D $start, :$overlap --> List:D)
Searches for all occurances of C<$needle> in the string starting from position
C<$start>, or zero if it is not specified, and returns a List with all offsets
in the string where C<$needle> was found, or an empty list if it was not found.
If the optional parameter C<:overlap> is specified the search continues from the
index directly following the previous match, otherwise the search will continue
from the first index after the previous match.
say "banana".indices("a"); # OUTPUT: «(1 3 5)␤»
say "banana".indices("ana"); # OUTPUT: «(1)␤»
say "banana".indices("ana", :overlap); # OUTPUT: «(1 3)␤»
say "banana".indices("ana", 2); # OUTPUT: «(3)␤»
@the-eater
Copy link

I don't know how you feel about it, but I feel like it's easier to read otherwise the search will continue after the previous match. instead of otherwise the search will continue from the first index after the previous match.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment