hare

The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit b72c4e29dc1db52d098155ebb2f86dc41de77bad
parent da1cbf036eeb10ec9e57451d4bbb12290d85fd94
Author: Drew DeVault <sir@cmpwn.com>
Date:   Sat, 10 Apr 2021 09:23:52 -0400

bufio::unreadrune: support several unreads

Diffstat:
Mbufio/buffered.ha | 8+++++++-
1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/bufio/buffered.ha b/bufio/buffered.ha @@ -117,7 +117,13 @@ export fn unread(s: *io::stream, buf: []u8) void = { export fn unreadrune(s: *io::stream, rn: rune) void = { assert(isbuffered(s), "bufio: unread used on non-buffered stream"); let s = s: *bufstream; - append(s.unread, ...utf8::encoderune(rn)); + const buf = utf8::encoderune(rn); + + let new: []u8 = alloc([], len(s.unread) + len(buf)); + append(new, ...buf); + append(new, ...s.unread); + free(s.unread); + s.unread = new; }; fn buffered_close(s: *io::stream) void = {