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
Implementation of Str.rindex. #277
Labels
Comments
From @bacekHello. Trivial implementation of Str.rindex (depends on #58308) -- |
From @bacekrakudo_str_rindex.diffcommit bbd7144bee1648f4516d61a98b48177b1370fe78
Author: Vasily Chekalkin <bacek@icebolt.(none)>
Date: Sun Aug 24 20:51:41 2008 +1000
Implement rindex
diff --git a/languages/perl6/src/builtins/any-str.pir b/languages/perl6/src/builtins/any-str.pir
index 77bb24c..84a62c6 100644
--- a/languages/perl6/src/builtins/any-str.pir
+++ b/languages/perl6/src/builtins/any-str.pir
@@ -21,7 +21,7 @@ the size of that file down and to emphasize their generic,
.namespace []
.sub 'onload' :anon :init :load
$P0 = get_hll_namespace ['Any']
- '!EXPORT'('chars index substr', 'from'=>$P0)
+ '!EXPORT'('chars index rindex substr', 'from'=>$P0)
.end
@@ -75,6 +75,44 @@ the size of that file down and to emphasize their generic,
.return ($P0)
.end
+=item rindex()
+
+=cut
+
+.namespace ['Any']
+.sub 'rindex' :method :multi(_)
+ .param string substring
+ .param int pos :optional
+ .param int has_pos :opt_flag
+ .local pmc retv
+
+ if has_pos goto have_pos
+ pos = 0
+ have_pos:
+
+ .local string s
+ s = self
+
+ check_substring:
+ if substring goto substring_search
+ $I0 = length s
+ if pos < $I0 goto done
+ pos = $I0
+ goto done
+
+ substring_search:
+ pos = rindex s, substring, pos
+ if pos < 0 goto fail
+
+ done:
+ $P0 = new 'Int'
+ $P0 = pos
+ .return ($P0)
+
+ fail:
+ $P0 = new 'Failure'
+ .return ($P0)
+.end
=item substr()
=cut
|
From @bacekFixed version of rindex. Now all non-fudged tests from S29-str/rindex.t -- |
From @bacekrakudo_str_rindex2.diffdiff --git a/languages/perl6/src/builtins/any-str.pir b/languages/perl6/src/builtins/any-str.pir
index 77bb24c..317656b 100644
--- a/languages/perl6/src/builtins/any-str.pir
+++ b/languages/perl6/src/builtins/any-str.pir
@@ -21,7 +21,7 @@ the size of that file down and to emphasize their generic,
.namespace []
.sub 'onload' :anon :init :load
$P0 = get_hll_namespace ['Any']
- '!EXPORT'('chars index substr', 'from'=>$P0)
+ '!EXPORT'('chars index rindex substr', 'from'=>$P0)
.end
@@ -75,6 +75,48 @@ the size of that file down and to emphasize their generic,
.return ($P0)
.end
+=item rindex()
+
+=cut
+
+.namespace ['Any']
+.sub 'rindex' :method :multi(_)
+ .param string substring
+ .param int pos :optional
+ .param int has_pos :opt_flag
+ .local pmc retv
+
+ .local string s
+ s = self
+
+ check_substring:
+ if substring goto substring_search
+
+ # we do not have substring return pos or length
+ if has_pos goto have_pos
+ pos = length s
+ goto done
+ have_pos:
+ $I0 = length s
+ if pos < $I0 goto done
+ pos = $I0
+ goto done
+
+
+
+ substring_search:
+ pos = rindex s, substring, pos
+ if pos < 0 goto fail
+
+ done:
+ $P0 = new 'Int'
+ $P0 = pos
+ .return ($P0)
+
+ fail:
+ $P0 = new 'Failure'
+ .return ($P0)
+.end
=item substr()
=cut
|
@bacek - Status changed from 'new' to 'open' |
@moritz - Status changed from 'open' 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#58310 (status was 'resolved')
Searchable as RT58310$
The text was updated successfully, but these errors were encountered: