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


Hello,

Here is the chomp patch that makes all chomp.t tests pass.
To test it, please use the following command:

./perl6 t/spec/S29-str/chomp.t 2>&1 | head

Thanks,
Ahmad Zawawi

Index: src/builtins/any-str.pir
===================================================================
--- src/builtins/any-str.pir    (revision 31564)
+++ src/builtins/any-str.pir    (working copy)
@@ -21,7 +21,7 @@
 .namespace []
 .sub 'onload' :anon :init :load
     $P0 = get_hll_namespace ['Any']
-    '!EXPORT'('capitalize chop chars index lc lcfirst rindex ord
substr uc ucfirst', 'from'=>$P0)
+    '!EXPORT'('capitalize chop chomp chars index lc lcfirst rindex
ord substr uc ucfirst', 'from'=>$P0)
 .end


@@ -99,7 +99,35 @@
     .return(retv)
 .end

+=item chomp
+
+ our Str method Str::chomp ( Str $string: )
+
+ Returns string with newline removed from the end.  An arbitrary
+ terminator can be removed if the input filehandle has marked the
+ string for where the "newline" begins.  (Presumably this is stored
+ as a property of the string.)  Otherwise a standard newline is removed.
+
+ Note: Most users should just let their I/O handles autochomp instead.
+ (Autochomping is the default.)
+
+=cut

+.sub 'chomp' :method :multi(_)
+    .local string tmps
+    .local string lastchar
+    .local pmc retv
+
+    tmps = self
+    lastchar = substr tmps,-1
+    if lastchar != "\n" goto done
+    chopn tmps, 1
+  done:
+       retv = new 'Perl6Str'
+       retv = tmps
+       .return (retv)
+.end
+
 =item comb()

 Partial implementation for now, returns a list of strings

Reply via email to