Skip to content

Commit 25709f6

Browse files
committed
Str.substr, Str.encode, Buf.decode
1 parent 7034ce6 commit 25709f6

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

lib/Buf.pod

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
class Buf does Positional { ... }
66
77
A C<Buf> (short for buffer) is a binary string, and generally returned from
8-
low-level IO operations. In the abstract it is just a list of integers, so
8+
low-level IO operations or from C<Str.encode>. In the abstract it is just
9+
a list of integers, so
910
for example indexing into a C<Buf> with C<.[$idx]> returns an C<Int>.
1011
1112
=head2 Methods
@@ -28,4 +29,10 @@ Returns C<False> if and only if the buffer is empty.
2829
2930
Returns the number of elements of the buffer.
3031
32+
=head3 decode
33+
34+
multi method decode(Buf:D: Str:D $encoding = 'UTF-8') returns Str:D
35+
36+
Applies an encoding to turn the buffer into a C<Str>
37+
3138
=end pod

lib/Str.pod

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,14 @@ Examples:
234234
multi sub substr(Str:D $s, Int:D $from, Int:D $chars = $s.chars - $from) returns Str:D
235235
multi method substr(Str:D $s: Int:D $from, Int:D $chars = $s.chars - $from) returns Str:D
236236
237-
TODO
237+
Returns a part of the string, starting from the character with index C<$from>
238+
(where the first character has index 0) and with length C<$chars>.
239+
240+
=head3 encode
241+
242+
multi method encode(Str:D: Str:D $encoding = 'UTF-8') returns Buf:D
243+
244+
Returns a buffer (ie a binary representation) of the string in the given
245+
encoding.
238246
239247
=end pod

0 commit comments

Comments
 (0)