develooper Front page | perl.cvs.parrot | Postings from January 2009

[svn:parrot] r35459 - in trunk/languages/perl6: src/builtins t

From:
moritz
Date:
January 12, 2009 15:01
Subject:
[svn:parrot] r35459 - in trunk/languages/perl6: src/builtins t
Message ID:
20090112230148.5FA89CBC85@x12.develooper.com
Author: moritz
Date: Mon Jan 12 15:01:47 2009
New Revision: 35459

Modified:
   trunk/languages/perl6/src/builtins/any-str.pir
   trunk/languages/perl6/t/spectest.data

Log:
[rakudo] implement Str.trim, patch courtesy by Ovid++


Modified: trunk/languages/perl6/src/builtins/any-str.pir
==============================================================================
--- trunk/languages/perl6/src/builtins/any-str.pir	(original)
+++ trunk/languages/perl6/src/builtins/any-str.pir	Mon Jan 12 15:01:47 2009
@@ -18,10 +18,12 @@
 
 =cut
 
+.include 'cclass.pasm'
+
 .namespace []
 .sub 'onload' :anon :init :load
     $P0 = get_hll_namespace ['Any']
-    '!EXPORT'('capitalize,chop,chomp,chars,:d,:e,:f,index,lc,lcfirst,rindex,ord,substr,uc,ucfirst,unpack', 'from'=>$P0)
+    '!EXPORT'('capitalize,chop,chomp,chars,:d,:e,:f,index,lc,lcfirst,rindex,ord,substr,trim,uc,ucfirst,unpack', 'from'=>$P0)
 .end
 
 
@@ -128,6 +130,39 @@
        .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 comb()
 
 Partial implementation for now, returns a list of strings

Modified: trunk/languages/perl6/t/spectest.data
==============================================================================
--- trunk/languages/perl6/t/spectest.data	(original)
+++ trunk/languages/perl6/t/spectest.data	Mon Jan 12 15:01:47 2009
@@ -286,6 +286,7 @@
 S29-str/split-simple.t
 S29-str/sprintf.t
 S29-str/substr.t
+S29-str/trim.t
 S29-str/ucfirst.t
 S29-str/uc.t
 S29-str/unpack.t



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About