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
Slightly refactored 'Str.pir' #100
Labels
Comments
From @bacekHello. Implementation for Str.substr method with correct handling of negative -- |
From @bacekstr.diffIndex: src/classes/Str.pir
===================================================================
--- src/classes/Str.pir (revision 27780)
+++ src/classes/Str.pir (working copy)
@@ -229,6 +229,33 @@
.return ($S0)
.end
+=item substr()
+
+
+=cut
+
+.sub 'substr' :method
+ .param int start
+ .param int len :optional
+ .param int has_len :opt_flag
+ .local pmc s
+
+ if has_len goto check_len
+ len = self.'chars'()
+
+ check_len:
+ if len > 0 goto end
+ $I0 = self.'chars'()
+ len = $I0 + len
+ len = len - start
+
+ end:
+ $S0 = substr self, start, len
+ s = new 'Perl6Str'
+ s = $S0
+ .return (s)
+.end
+
=back
=head1 Functions
@@ -414,17 +441,11 @@
.param string x
.param int start
.param int len :optional
- .param int has_len :opt_flag
.local pmc s
- if has_len goto end
s = new 'Perl6Str'
s = x
- len = s.'chars'()
-
- end:
- $S0 = substr x, start, len
- .return ($S0)
+ .return s.'substr'(start, len)
.end
=item chop
|
From @pmichaudApplied in r27874, thanks! Pm |
@pmichaud - Status changed from 'new' to 'resolved' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Migrated from rt.perl.org#54766 (status was 'resolved')
Searchable as RT54766$
The text was updated successfully, but these errors were encountered: