# New Ticket Created by  Cory Spencer 
# Please include the string:  [perl #64096]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=64096 >



The following patch adds a Perl 6 version of trim to Any.pm in the 
setting.
>From 20cb779b7eec5e37448c01e67888490eb755975e Mon Sep 17 00:00:00 2001
From: git <cspen...@sprocket.org>
Date: Sun, 22 Mar 2009 11:32:01 -0700
Subject: [PATCH] Added a Perl 6 version of trim to Any.pm in the setting.

---
 src/builtins/any-str.pir |   35 +----------------------------------
 src/setting/Any-str.pm   |    6 +++++-
 2 files changed, 6 insertions(+), 35 deletions(-)

diff --git a/src/builtins/any-str.pir b/src/builtins/any-str.pir
index 0369a40..4645410 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'('capitalize,chomp,chars,:d,:e,:f,index,rindex,ord,substr', 'from'=>$P0)
 .end
 
 
@@ -110,39 +110,6 @@ C<s:g/(\w+)/{ucfirst $1}/> on it.
        .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 )
diff --git a/src/setting/Any-str.pm b/src/setting/Any-str.pm
index a266921..ede1ad7 100644
--- a/src/setting/Any-str.pm
+++ b/src/setting/Any-str.pm
@@ -106,6 +106,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
@@ -117,7 +122,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) {
-- 
1.6.0.6

Reply via email to