Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
implement wordcase, deprecate capitalize
  • Loading branch information
moritz committed Sep 10, 2012
1 parent f488677 commit d1f4dc7
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
1 change: 1 addition & 0 deletions docs/ChangeLog
Expand Up @@ -6,6 +6,7 @@ New in 2012.09
+ compiler now built with QAST-based NQP, which generates better code, thus
making the compiler a little faster
+ support for "is export" traits on constants
+ implemented Str.wordcase

New in 2012.08
+ tclc implemented
Expand Down
6 changes: 6 additions & 0 deletions docs/deprecations
@@ -1,3 +1,9 @@
Deprecations in 2012.09

Str.capitalize and &capitalize are deprecated in favor
of the the Str.wordcase and &wordcase routines.
They will uncondtionally warn in 2012.10, and be removed in 2012.11.

Deprecations in 2012.08

Parameters preceeded by a | or \ may not have a sigil anymore.
Expand Down
9 changes: 7 additions & 2 deletions src/core/Cool.pm
Expand Up @@ -90,7 +90,8 @@ my class Cool {
$self-str eq '' ?? '' !! $self-str.substr(0, 1).uc ~ $self-str.substr(1)
}

method capitalize() { self.Stringy.capitalize }
method capitalize() is DEPRECATED { self.Stringy.capitalize }
method wordcase() { self.Str.wordcase }

method chomp() {
self.Str.chomp;
Expand Down Expand Up @@ -213,10 +214,14 @@ multi sub ords(Cool $s) { ords($s.Stringy) }
proto sub comb(|) { * }
multi sub comb(Regex $matcher, Cool $input, $limit = *) { $input.comb($matcher, $limit) }

proto sub capitalize(|) { * }
proto sub capitalize(|) is DEPRECATED { * }
multi sub capitalize(Str:D $x) {$x.capitalize }
multi sub capitalize(Cool $x) {$x.Stringy.capitalize }

proto sub wordcase(|) { * }
multi sub wordcase(Str:D $x) {$x.wordcase }
multi sub wordcase(Cool $x) {$x.Str.wordcase }

proto sub tclc(|) { * }
multi sub tclc(Cool $x) { tclc $x.Str }

Expand Down
10 changes: 8 additions & 2 deletions src/core/Str.pm
Expand Up @@ -751,10 +751,16 @@ my class Str does Stringy {
$buf;
}

method capitalize(Str:D:) {
method capitalize(Str:D:) is DEPRECATED {
self.subst(:g, rx/\w+/, -> $_ { .Str.lc.ucfirst });
}

method wordcase(Str:D: :&filter = &tclc, :$where = True) {
my token identifier { [<:L> \w* ] *% <['\-]> }
self.subst(:g, / [<:L> \w* ] +% <['\-]> /, -> $m {
my Str $s = $m.Str;
$s ~~ $where ?? filter($s) !! $s;
});
}

my class LSM {
has Str $!source;
Expand Down

0 comments on commit d1f4dc7

Please sign in to comment.