Skip to content
Browse files

implement wordcase, deprecate capitalize

  • Loading branch information...
1 parent f488677 commit d1f4dc7b40e1e58dc9770698af3a66c520946705 @moritz moritz committed Sep 10, 2012
Showing with 22 additions and 4 deletions.
  1. +1 −0 docs/ChangeLog
  2. +6 −0 docs/deprecations
  3. +7 −2 src/core/Cool.pm
  4. +8 −2 src/core/Str.pm
View
1 docs/ChangeLog
@@ -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
View
6 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.
View
9 src/core/Cool.pm
@@ -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;
@@ -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 }
View
10 src/core/Str.pm
@@ -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;

0 comments on commit d1f4dc7

Please sign in to comment.
Something went wrong with that request. Please try again.