Skip to content

Commit 69b25a3

Browse files
committed
document Buf subbuf-rw routine and method
closes #1148
1 parent 54cb760 commit 69b25a3

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

doc/Type/Buf.pod6

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,31 @@ A C<Buf> is a mutable sequence of (usually unsigned) integers.
1111
my $b = Buf.new(1, 2, 3);
1212
$b[1] = 42;
1313
14+
=head1 Methods
15+
16+
=head2 method subbuf-rw
17+
18+
method subbuf-rw($from, $length?)
19+
20+
A mutable version of C<subbuf> that returns a L<Proxy|/type/Proxy> functioning as a
21+
writable reference to a part of a buffer. Its first argument, C<$from>
22+
specifies the index in the buffer from which a substitution should occur, and
23+
its last argument, C<$length> specifies how many elements are to be replaced.
24+
25+
For example, to replace one element at index 3 with two elements, C<100> and C<101>:
26+
27+
my Buf $b .= new(0..5);
28+
$b.subbuf-rw(3,1) = Buf.new(100, 101);
29+
dd $b; # OUTPUT: Buf $b = Buf.new(0,1,2,100,101,4,5)
30+
31+
=head2 routine subbuf-rw
32+
33+
sub subbuf-rw(Buf:D $buf, $from, $length?)
34+
35+
Returns a writable reference to a part of a buffer. Similar to the C<subbuf-rw> method:
36+
37+
my Buf $b .= new(1,2,3);
38+
subbuf-rw($b,2,1) = Buf.new(42);
39+
dd $b; # OUTPUT: Buf $b = Buf.new(1,2,42)
40+
1441
=end pod

0 commit comments

Comments
 (0)