Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Update nqp-setting with fixed C<split>.

  • Loading branch information...
commit 125d94c41cff60e4c1b36fb47a973360e6cb34e7 1 parent 82cab12
@bacek bacek authored
Showing with 32 additions and 25 deletions.
  1. +32 −25 ext/nqp-rx/src/stage0/nqp-setting.nqp
View
57 ext/nqp-rx/src/stage0/nqp-setting.nqp
@@ -37,7 +37,7 @@ module ResizablePMCArray {
Return all elements joined by $sep.
=end item
- method join ($separator) {
+ method join ($separator = '') {
pir::join($separator, self);
}
@@ -217,31 +217,38 @@ our sub subst ($text, $regex, $repl, :$global?) {
Splits C<$text> on occurences of C<$regex>
=end item
-# our sub split ($regex, $text) {
-# my $pos := 0;
-# my @result;
-# my $looking := 1;
-# while $looking {
-# my $match :=
-# Regex::Cursor.parse($text, :rule($regex), :c($pos)) ;
-#
-# if ?$match {
-# my $from := $match.from();
-# my $to := $match.to();
-# my $prefix := pir::substr__sPii($text, $pos, $from-$pos);
-# @result.push($prefix);
-# $pos := $match.to();
-# } else {
-# my $len := pir::length($text);
-# if $pos < $len {
-# @result.push(pir::substr__ssi($text, $pos) );
-# }
-# $looking := 0;
-# }
-# }
-# return @result;
-# }
+our multi sub split (Regex::Regex $regex, $text) {
+ my $pos := 0;
+ my @result;
+ my $looking := 1;
+ while $looking {
+ my $match :=
+ Regex::Cursor.parse($text, :rule($regex), :c($pos)) ;
+
+ if ?$match {
+ my $from := $match.from();
+ my $to := $match.to();
+ my $prefix := pir::substr__sPii($text, $pos, $from-$pos);
+ @result.push($prefix);
+ $pos := $match.to();
+ } else {
+ my $len := pir::length($text);
+ if $pos < $len {
+ @result.push(pir::substr__ssi($text, $pos) );
+ }
+ $looking := 0;
+ }
+ }
+ return @result;
+}
+# Use parrot's split for plain strings.
+our multi sub split($string, $text) {
+ # op split produces RSA. So, convert it to RPA.
+ my @res;
+ @res.push($_) for pir::split($string, $text);
+ @res;
+}
# vim: ft=perl6
# From src/setting/IO.pm
Please sign in to comment.
Something went wrong with that request. Please try again.