New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
any-pir p5chomp implementation #353
Comments
From @azawawiHello, Here is the p5chomp patch that makes the first four tests to pass. ./perl6 t/spec/S29-str/p5chomp.t 2>&1 | head Thanks, Index: src/builtins/any-str.pir--- src/builtins/any-str.pir (revision 31564) @@ -99,7 +99,33 @@ +=item p5chomp + our Int multi P5emul::Str::p5chomp ( Str $string is rw ) Partial implementation for now, returns a list of strings |
From @azawawiAttaching the patch file |
From @azawawistr_p5chomp.patchIndex: 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 p5chomp chars index lc lcfirst rindex ord substr uc ucfirst', 'from'=>$P0)
.end
@@ -99,7 +99,33 @@
.return(retv)
.end
+=item p5chomp
+ our Int multi P5emul::Str::p5chomp ( Str $string is rw )
+ our Int multi P5emul::Str::p5chomp ( Str *@strings = ($+_) is rw )
+
+ Related to C<p5chop>, only removes trailing chars that match C</\n/>. In
+ either case, it returns the number of chars removed.
+
+=cut
+
+.sub 'p5chomp' :method :multi(_)
+ .local string tmps
+ .local string lastchar
+ .local pmc retv
+
+ tmps = self
+ retv = new 'Int'
+ retv = 0
+ lastchar = substr tmps,-1
+ if lastchar != "\n" goto done
+ chopn tmps, 1
+ self = tmps
+ retv += 1
+ done:
+ .return(retv)
+.end
+
=item comb()
Partial implementation for now, returns a list of strings
|
@azawawi - Status changed from 'new' to 'open' |
From @azawawiany-list.pir implementation. All p5chomp.t run ok (finally ;-) ./ahmad & |
From @azawawip5chomp_list.patchIndex: src/builtins/any-list.pir
===================================================================
--- src/builtins/any-list.pir (revision 31798)
+++ src/builtins/any-list.pir (working copy)
@@ -21,7 +21,7 @@
.namespace ['Any']
.sub 'onload' :anon :init :load
$P0 = get_hll_namespace ['Any']
- '!EXPORT'('abs', 'from'=>$P0)
+ '!EXPORT'('abs p5chomp', 'from'=>$P0)
.end
@@ -43,7 +43,33 @@
.return ($I0)
.end
+=item p5chomp
+=cut
+.namespace ['Any']
+.sub 'p5chomp' :method :multi(_)
+ .local string tmps
+ .local pmc it
+
+ $P0 = self.'list'()
+ it = $P0.'iterator'()
+ $N0 = 0
+ loop:
+ unless it goto done
+ $P0 = shift it
+ tmps = $P0
+ $S0 = substr tmps,-1
+ if $S0 != "\n" goto loop
+ chopn tmps, 1
+ $P0 = tmps
+ $N0 += 1
+ goto loop
+ done:
+ $P0 = new 'Int'
+ $P0 = $N0
+ .return($P0)
+.end
+
=item join
=cut
|
From @azawawiPlease use the latest any-list.pir patch. It works perfectly. On Wed Oct 08 14:50:33 2008, ahmadz wrote:
|
From @bacekOn Wed Oct 08 14:55:25 2008, ahmadz wrote:
One note. It should be $I0 instead of $N0. $In registers are integers, -- |
From @moritzWe now have a Perl 6 version of p5chomp in Rakudo (which wasn't possible Anyway, thanks for your contribution. Cheers, |
@moritz - Status changed from 'open' to 'rejected' |
Migrated from rt.perl.org#59560 (status was 'rejected')
Searchable as RT59560$
The text was updated successfully, but these errors were encountered: