Skip to content

Commit

Permalink
implement capitalize
Browse files Browse the repository at this point in the history
  • Loading branch information
moritz committed Aug 14, 2011
1 parent 1a442ef commit 0447cac
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/core/Cool.pm
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions src/core/Parcel.pm
Expand Up @@ -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() {
Expand Down
4 changes: 4 additions & 0 deletions src/core/Str.pm
Expand Up @@ -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 });
}
}


Expand Down
2 changes: 1 addition & 1 deletion t/spectest.data
Expand Up @@ -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
Expand Down

0 comments on commit 0447cac

Please sign in to comment.