Skip to content

Commit

Permalink
implement samecase()
Browse files Browse the repository at this point in the history
  • Loading branch information
moritz committed Apr 24, 2010
1 parent ea91882 commit 73e8d42
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/core/Cool-str.pm
Expand Up @@ -48,6 +48,23 @@ augment class Cool {
}
}

multi method samecase($pattern) is export {
my $result = '';
my $p = '';
my @pattern = $pattern.comb;
for self.comb -> $s {
$p = @pattern.shift if @pattern;
if $p ~~ /<.upper>/ {
$result ~= $s.uc;
} elsif $p ~~ /<.lower>/ {
$result ~= $s.lc;
} else {
$result ~= $s;
}
}
$result;
}

multi method split(Regex $matcher, $limit = *, :$all) {
my $c = 0;
my $l = $limit ~~ ::Whatever ?? Inf !! $limit - 1;
Expand Down
2 changes: 1 addition & 1 deletion t/spectest.data
Expand Up @@ -513,7 +513,7 @@ S32-str/lc.t # icu
S32-str/p5chop.t
S32-str/pos.t
# S32-str/rindex.t
# S32-str/samecase.t # icu
S32-str/samecase.t # icu
# S32-str/split-simple.t
S32-str/split-simple2.t # CHEAT! simplified version of split-simple.t
S32-str/split.t
Expand Down

0 comments on commit 73e8d42

Please sign in to comment.