Permalink
Browse files

implement capitalize

  • Loading branch information...
1 parent 1a442ef commit 0447cac8f793dd697f7d90403bed500dcbb66674 @moritz moritz committed Aug 14, 2011
Showing with 12 additions and 1 deletion.
  1. +6 −0 src/core/Cool.pm
  2. +1 −0 src/core/Parcel.pm
  3. +4 −0 src/core/Str.pm
  4. +1 −1 t/spectest.data
View
@@ -54,6 +54,8 @@ my class Cool {
$self-str eq '' ?? '' !! $self-str.substr(0, 1).lc ~ $self-str.substr(1)
}
+ method capitalize() { self.Stringy.capitalize }
+
method chomp() {
self.Str.chomp;
}
@@ -145,6 +147,10 @@ multi sub ords(Cool $s) { ords($s.Stringy) }
proto sub comb(|$) { * }
multi sub comb(Regex $matcher, Cool $input) { $input.comb($matcher) }
+proto sub capitalize(|$) { * }
+multi sub capitalize(Str:D $x) {$x.capitalize }
+multi sub capitalize(Cool $x) {$x.Stringy.capitalize }
+
sub sprintf(Cool $format, *@args) {
@args.gimme(*);
nqp::p6box_s(
View
@@ -6,6 +6,7 @@ my class Parcel does Positional {
multi method Bool(Parcel:D:) { nqp::p6bool($!storage) }
multi method Numeric(Parcel:D:) { self.flat.elems }
multi method Str(Parcel:D:) { self.flat.Str }
+# multi method Int(Parcel:D:) { self.flat.elems }
multi method ACCEPTS(Parcel:D: $topic) { self.list.ACCEPTS($topic) }
method Capture() {
View
@@ -433,6 +433,10 @@ my class Str does Stringy {
method words(Str:D: Int $limit = *) {
self.comb( / \S+ /, $limit );
}
+
+ method capitalize(Str:D:) {
+ self.subst(:g, rx/\w+/, -> $_ { .Str.lc.ucfirst });
+ }
}
View
@@ -536,7 +536,7 @@ S32-scalar/defined.t
S32-scalar/undef.t
S32-str/append.t
S32-str/bool.t
-# S32-str/capitalize.t # err: Could not find sub &capitalize #icu
+S32-str/capitalize.t
S32-str/chomp.t
S32-str/chop.t
S32-str/comb.t # icu

0 comments on commit 0447cac

Please sign in to comment.