# New Ticket Created by Clinton Gormley # Please include the string: [perl #64060] # in the subject line of all future correspondence about this issue. # <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=64060 >
The attached patch moves capitalize from builtins/any-str.pir to setting/Any-str.pm, and removes a redundant line where the string length was being checked multiple times, even though it wouldn't have changed.
diff --git a/src/builtins/any-str.pir b/src/builtins/any-str.pir index 0369a40..066ff56 100644 --- a/src/builtins/any-str.pir +++ b/src/builtins/any-str.pir @@ -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 @@ -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 diff --git a/src/setting/Any-str.pm b/src/setting/Any-str.pm index bbf28a3..49855d1 100644 --- a/src/setting/Any-str.pm +++ b/src/setting/Any-str.pm @@ -19,6 +19,38 @@ class Any is also { self gt '' ?? self.substr(0,1).lc ~ self.substr(1) !! "" } + our Str multi method capitalize is export { + return Q:PIR { + $S0 = self + .local int len + + len = length $S0 + if len == 0 goto done + + downcase $S0 + + .local int pos + .local string s1 + pos = 0 + + next_word: + pos = find_cclass .CCLASS_LOWERCASE, $S0, pos, len + s1 = substr $S0, pos, 1 + upcase s1 + substr $S0, pos, 1, s1 + pos+=1 + if pos == len goto done + + pos = find_not_cclass .CCLASS_LOWERCASE, $S0, pos, len + if pos == len goto done + goto next_word + + done: + %r = box $S0 + } + + } + our List multi method split(Code $delimiter, $limit = *) { my $s = ~self; my $l = $limit ~~ Whatever ?? Inf !! $limit;