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

Slightly refactored 'Str.pir' #100

Closed
p6rt opened this issue May 24, 2008 · 4 comments
Closed

Slightly refactored 'Str.pir' #100

p6rt opened this issue May 24, 2008 · 4 comments
Labels

Comments

@p6rt
Copy link

p6rt commented May 24, 2008

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

Searchable as RT54766$

@p6rt
Copy link
Author

p6rt commented May 24, 2008

From @bacek

Hello.

Implementation for Str.substr method with correct handling of negative
length.

--
Bacek.

@p6rt
Copy link
Author

p6rt commented May 24, 2008

From @bacek

str.diff
Index: 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

@p6rt
Copy link
Author

p6rt commented May 28, 2008

From @pmichaud

Applied in r27874, thanks!

Pm

@p6rt
Copy link
Author

p6rt commented May 28, 2008

@pmichaud - Status changed from 'new' to 'resolved'

@p6rt p6rt closed this as completed May 28, 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