Skip to content

Commit

Permalink
Merge branch 'master' of git@github.com:rakudo/rakudo
Browse files Browse the repository at this point in the history
  • Loading branch information
jnthn committed Mar 25, 2009
2 parents a572337 + 7b3f8c4 commit 0f50d4f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 43 deletions.
44 changes: 1 addition & 43 deletions src/builtins/any-str.pir
Expand Up @@ -23,7 +23,7 @@ the size of that file down and to emphasize their generic,
.namespace []
.sub 'onload' :anon :init :load
$P0 = get_hll_namespace ['Any']
'!EXPORT'('capitalize,chomp,chars,:d,:e,:f,index,rindex,ord,substr,trim', 'from'=>$P0)
'!EXPORT'('chomp,chars,:d,:e,:f,index,rindex,ord,substr,trim', 'from'=>$P0)
.end
Expand All @@ -33,48 +33,6 @@ the size of that file down and to emphasize their generic,
.namespace ['Any']
=item capitalize
our Str multi Str::capitalize ( Str $string )
Has the effect of first doing an C<lc> on the entire string, then performing a
C<s:g/(\w+)/{ucfirst $1}/> on it.
=cut
.sub 'capitalize' :method :multi(_)
.local string tmps
.local pmc retv
.local int len
retv = new 'Str'
tmps = self
len = length tmps
if len == 0 goto done
downcase tmps
.local int pos
.local string s1
pos = 0
next_word:
pos = find_cclass .CCLASS_LOWERCASE, tmps, pos, len
s1 = substr tmps, pos, 1
upcase s1
substr tmps, pos, 1, s1
len = length tmps
pos+=1
if pos == len goto done
pos = find_not_cclass .CCLASS_LOWERCASE, tmps, pos, len
if pos == len goto done
goto next_word
done:
retv = tmps
.return (retv)
.end
.sub 'chars' :method :multi(_)
$S0 = self
$I0 = length $S0
Expand Down
4 changes: 4 additions & 0 deletions src/setting/Any-str.pm
@@ -1,4 +1,8 @@
class Any is also {
our Str multi method capitalize() is export {
self.lc.subst(/\w+/, { .ucfirst }, :global)
}

our Str multi method chop is export {
self.substr(0, -1)
}
Expand Down

0 comments on commit 0f50d4f

Please sign in to comment.