Combined from primary sources listed below.
See primary docmentation in context for routine subbuf.
multi subbuf-rw(Buf:D \b) is rw
multi subbuf-rw(Buf:D \b, Int() $from) is rw
multi subbuf-rw(Buf:D \b, $from, $elems) is rw
Returns a writable reference to a part of a buffer. Invokes the subbuf-rw method on the specified Buf:
my Buf $bú .= new(1,2,3);
subbuf-rw($bú,2,1) = Buf.new(42);
say $bú.raku; # OUTPUT: «Buf.new(1,2,42)»
See primary docmentation in context for method subbuf.
method subbuf-rw($from = 0, $elems = self.elems - $from) is rw
A mutable version of subbuf that returns a Proxy functioning as a writable reference to a part of a buffer. Its first argument, $from specifies the index in the buffer from which a substitution should occur, and its last argument, $elems specifies how many elements are to be replaced.
For example, to replace one element at index 3 with two elements, 100 and 101:
my Buf $bú .= new(0..5);
$bú.subbuf-rw(3,1) = Buf.new(100, 101);
say $bú.raku; # OUTPUT: «Buf.new(0,1,2,100,101,4,5)»
In the case the $elems argument is not specified, the substitution happens at the specified index $from removing all trailing elements:
my Buf $bú .= new(0..5);
$bú.subbuf-rw(3) = Buf.new(200);
say $bú.raku; # OUTPUT: «Buf.new(0,1,2,200)»
In the case the $from argument is not specified, the substitution happens from the very beginning of the buffer:
my Buf $bú .= new(0..5);
$bú.subbuf-rw = Buf.new(123, 123);
say $bú.raku; # OUTPUT: «Buf.new(123, 123)»
See primary docmentation in context for method subbuf.
multi method subbuf(Int $from, Int $len = self.elems --> Blob:D)
multi method subbuf(Range $range --> Blob:D)
multi method subbuf(Blob:D: &From)
multi method subbuf(Blob:D: Int:D $From, &End)
multi method subbuf(Blob:D: &From, &End)
multi method subbuf(Blob:D: \from, Whatever)
multi method subbuf(Blob:D: \from, Numeric \length)
Extracts a part of the invocant buffer, starting from the index with elements $from, and taking $len elements (or less if the buffer is shorter), and creates a new buffer as the result.
say Blob.new(1..10).subbuf(2, 4); # OUTPUT: «Blob:0x<03 04 05 06>»
say Blob.new(1..10).subbuf(*-2); # OUTPUT: «Blob:0x<09 0a>»
say Blob.new(1..10).subbuf(*-5,2); # OUTPUT: «Blob:0x<06 07>»
For convenience, also allows a Range to be specified to indicate which part of the invocant buffer you would like:
say Blob.new(1..10).subbuf(2..5); # OUTPUT: «Blob:0x<03 04 05 06>»