Skip to content
Browse files

Str.lines

  • Loading branch information...
1 parent 6849c6f commit da00ab7343e5c997fbd8939bc4b2775486e44647 @moritz moritz committed
Showing with 12 additions and 1 deletion.
  1. +11 −0 src/core/Str.pm
  2. +1 −1 t/spectest.data
View
11 src/core/Str.pm
@@ -151,6 +151,17 @@ my class Str does Stringy {
my str $ns = nqp::unbox_s(self);
(^$c).map: { nqp::p6box_i(nqp::ord(nqp::substr($ns, $_, 1))) }
}
+
+ method lines(Str:D:) {
+ my $prev_pos = -1;
+ gather {
+ while defined(my $current_pos = self.index("\n", $prev_pos + 1)) {
+ take self.substr($prev_pos + 1, $current_pos - $prev_pos - 1);
+ $prev_pos = $current_pos;
+ }
+ take self.substr($prev_pos + 1) if $prev_pos + 1 < self.chars;
+ }
+ }
}
View
2 t/spectest.data
@@ -541,7 +541,7 @@ S32-str/flip.t
# S32-str/index.t # err: dies after test # 2
S32-str/lc.t # icu
S32-str/lcfirst.t # icu
-# S32-str/lines.t # err: Method 'lines' not found for invocant of class 'Str'
+S32-str/lines.t
S32-str/ords.t
# S32-str/p5chomp.t # err: Could not find sub &p5chomp
# S32-str/p5chop.t # err: Could not find sub &p5chop

0 comments on commit da00ab7

Please sign in to comment.
Something went wrong with that request. Please try again.