Skip to content

Commit

Permalink
0.0.27
Browse files Browse the repository at this point in the history
  • Loading branch information
lizmat committed Aug 18, 2024
1 parent a953daf commit c93c58b
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 7 deletions.
4 changes: 4 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ Revision history for String-Utils

{{$NEXT}}

0.0.27 2024-08-18T12:20:10+02:00
- Add support for ":Pair" named argument to "paragraphs" to set
the class with which to create the objects

0.0.26 2024-08-16T13:53:24+02:00
- Add support for "regexify"

Expand Down
2 changes: 1 addition & 1 deletion META6.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@
],
"test-depends": [
],
"version": "0.0.26"
"version": "0.0.27"
}
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,13 @@ Lazily produces a `Seq` of `Pairs` with paragraphs from a `Seq` or string in whi

The optional second argument can be used to indicate the ordinal number of the first line in the string.

```raku
my class A is Pair { }
.say for paragraphs("a\n\nb", 1, :Pair(A)); # 1 => a␤3 => b␤
```

Also takes an optional named argument `:Pair` that indicates the class with which the objects should be created. This defailts to the core `Pair` class.

regexify
--------

Expand Down
11 changes: 11 additions & 0 deletions doc/String-Utils.rakudoc
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,17 @@ and the value is the paragraph (without trailing newline).
The optional second argument can be used to indicate the ordinal number
of the first line in the string.

=begin code :lang<raku>

my class A is Pair { }
.say for paragraphs("a\n\nb", 1, :Pair(A)); # 1 => a␤3 => b␤

=end code

Also takes an optional named argument C<:Pair> that indicates the class
with which the objects should be created. This defailts to the core
C<Pair> class.

=head2 regexify

=begin code :lang<raku>
Expand Down
14 changes: 8 additions & 6 deletions lib/String/Utils.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -396,15 +396,17 @@ my sub all-same(str $string) {
}

my proto sub paragraphs(|) {*}
my multi sub paragraphs(@source, Int:D $initial = 0) {
my multi sub paragraphs(@source, Int:D $initial = 0, :$Pair = Pair) {
my class Paragraphs does Iterator {
has $!iterator;
has int $!line;
has $!Pair;

method new($iterator, int $line) {
method new($iterator, int $line, $Pair) {
my $self := nqp::create(self);
nqp::bindattr( $self,Paragraphs,'$!iterator',$iterator);
nqp::bindattr_i($self,Paragraphs,'$!line', $line - 1);
nqp::bindattr( $self,Paragraphs,'$!Pair', $Pair);
$self
}

Expand All @@ -419,7 +421,7 @@ my multi sub paragraphs(@source, Int:D $initial = 0) {
my sub paragraph() {
$!line = $line;

Pair.new(
$!Pair.new(
$line - nqp::elems($collected),
nqp::join("\n", $collected)
)
Expand Down Expand Up @@ -456,10 +458,10 @@ my multi sub paragraphs(@source, Int:D $initial = 0) {
}

# Produce the sequence
Seq.new: Paragraphs.new(@source.iterator, $initial)
Seq.new: Paragraphs.new(@source.iterator, $initial, $Pair)
}
my multi sub paragraphs(Cool:D $string, Int:D $initial = 0) {
paragraphs $string.Str.lines, $initial
my multi sub paragraphs(Cool:D $string, Int:D $initial = 0, :$Pair = Pair) {
paragraphs $string.Str.lines, $initial, :$Pair
}

my sub regexify(str $spec, *%_) {
Expand Down

0 comments on commit c93c58b

Please sign in to comment.