Skip to content
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-str.pir chomp implementation #352

Closed
p6rt opened this issue Oct 2, 2008 · 6 comments
Closed

any-str.pir chomp implementation #352

p6rt opened this issue Oct 2, 2008 · 6 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Oct 2, 2008

Migrated from rt.perl.org#59556 (status was 'resolved')

Searchable as RT59556$

@p6rt
Copy link
Author

p6rt commented Oct 2, 2008

From @azawawi

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

@p6rt
Copy link
Author

p6rt commented Oct 2, 2008

From @azawawi

Attaching the patch file

@p6rt
Copy link
Author

p6rt commented Oct 2, 2008

From @azawawi

str_chomp.patch
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

@p6rt
Copy link
Author

p6rt commented Oct 2, 2008

@azawawi - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Oct 2, 2008

From @moritz

On Thu Oct 02 06​:06​:47 2008, ahmadz wrote​:

Hello,

Here is the chomp patch that makes all chomp.t tests pass.

Probably not all, because chomp.t uses is_deeply, which is not
implemented in rakudo. But all that rakudo can run yet.

Patch applied as r31573 (+tests; removed two lines of the copied POD),
thank you very much.

Moritz

@p6rt
Copy link
Author

p6rt commented Oct 2, 2008

@moritz - Status changed from 'open' to 'resolved'

@p6rt p6rt closed this as completed Oct 2, 2008
@p6rt p6rt added the patch label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant