Skip to content

Commit

Permalink
Add perl versions of trim() to setting (RT #64096).
Browse files Browse the repository at this point in the history
Patch courtesy Cory Spencer <cspencer@sprocket.org>.
  • Loading branch information
pmichaud committed Mar 26, 2009
1 parent 0f6354d commit 00cd1fd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 35 deletions.
35 changes: 1 addition & 34 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'('chomp,chars,:d,:e,:f,index,rindex,ord,substr,trim', 'from'=>$P0)
'!EXPORT'('chomp,chars,:d,:e,:f,index,rindex,ord,substr', 'from'=>$P0)
.end
Expand Down Expand Up @@ -68,39 +68,6 @@ the size of that file down and to emphasize their generic,
.return (retv)
.end
=item trim()
Remove leading and trailing whitespace from a string.
=cut
.sub 'trim' :method :multi(_)
.local string s
.local int start, end, temp, len
.local int is_whitespace
s = self
start = 0
end = length s
if end == 0 goto donetrailing
trimleading:
is_whitespace = is_cclass .CCLASS_WHITESPACE, s, start
unless is_whitespace goto doneleading
inc start
goto trimleading
doneleading:
temp = end
trimtrailing:
dec temp
is_whitespace = is_cclass .CCLASS_WHITESPACE, s, temp
unless is_whitespace goto donetrailing
end = temp
goto trimtrailing
donetrailing:
len = end - start
s = substr s, start, len
.return(s)
.end
=item ':d'()
our Bool multi Str::':d' ( Str $filename )
Expand Down
6 changes: 5 additions & 1 deletion src/setting/Any-str.pm
Expand Up @@ -86,6 +86,11 @@ class Any is also {
}
}

# TODO: signature not fully specced in S32 yet
our Str multi method trim is export {
(~self).subst(/(^\s+)|(\s+$)/, "", :g)
}

our Str multi method uc is export {
return Q:PIR {
$S0 = self
Expand All @@ -97,7 +102,6 @@ class Any is also {
our Str multi method ucfirst is export {
self gt '' ?? self.substr(0,1).uc ~ self.substr(1) !! ""
}
}
sub split($delimiter, $target, $limit = *) {
Expand Down

0 comments on commit 00cd1fd

Please sign in to comment.