Permalink
Browse files

Use multi-dispatch to split on plain strings in setting

  • Loading branch information...
1 parent 7809892 commit feb29e6a337b3cd8c2a388e08df23b704eae2c67 @bacek bacek committed Jan 27, 2011
Showing with 14 additions and 2 deletions.
  1. +8 −1 src/setting/Regex.pm
  2. +6 −1 t/setting/04-regex.t
View
9 src/setting/Regex.pm
@@ -60,7 +60,7 @@ our sub subst ($text, $regex, $repl, :$global?) {
Splits C<$text> on occurences of C<$regex>
=end item
-our sub split ($regex, $text) {
+our multi sub split (Regex::Regex $regex, $text) {
my $pos := 0;
my @result;
my $looking := 1;
@@ -85,5 +85,12 @@ our sub split ($regex, $text) {
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
View
7 t/setting/04-regex.t
@@ -2,10 +2,15 @@
pir::load_bytecode('nqp-setting.pbc');
-plan(2);
+plan(4);
my @a := split(/\d/, 'a23b5d');
ok(+@a == 4, 'split produced 4 chunks');
ok((@a.join('!') eq 'a!!b!d'), 'got right chunks');
+@a := split('/', 'foo/bar/baz');
+ok(+@a == 3, 'split produced 3 chunks');
+ok((@a.join('!') eq 'foo!bar!baz'), 'got right chunks');
+
+
# vim: ft=perl6

0 comments on commit feb29e6

Please sign in to comment.