Anonymous user
String matching: Difference between revisions
→update example to work with current spec
Line 1,918:
# Index-based:
sub I_contains ( Str $_, Str $s2 ) { .index( $s2)
sub I_starts_with ( Str $_, Str $s2 ) { my $m = .index( $s2); $m.defined and $m == 0 },
sub I_ends_with ( Str $_, Str $s2 ) { my $m = .rindex($s2); $m.defined and $m == .chars - $s2.chars },
Line 1,924:
# Substr-based:
sub S_starts_with ( Str $_, Str $s2 ) { .substr(0, $s2.chars) eq $s2 },
sub S_ends_with ( Str $_, Str $s2 ) { .substr(
# Optional tasks:
Line 1,939:
say "'$str1' vs:".fmt('%15s '), @str2s.fmt('%-15s');
for [1, 4, 6], [2, 5, 7], [0, 3], [8, 9] {
say();
for @subs[.list] -> $sub {
say "{$sub.name}:".fmt('%15s '),
|