hare

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

commit 76e8fad0f03bd09e201031300e795de589135008
parent ab0f65ccefd2b00ff38a9df755d596bfb0486148
Author: Drew DeVault <sir@cmpwn.com>
Date:   Thu, 25 Feb 2021 14:04:21 -0500

strio: add strio::concat

Diffstat:
Astrio/ops.ha | 26++++++++++++++++++++++++++
1 file changed, 26 insertions(+), 0 deletions(-)

diff --git a/strio/ops.ha b/strio/ops.ha @@ -0,0 +1,26 @@ +use io; +use strings; + +// Appends zero or more strings to an [io::stream]. The stream needn't be a +// strio stream, but it's often efficient if it is. +export fn concat(st: *io::stream, strs: str...) (size | io::error) = { + let n = 0z; + for (let i = 0z; i < len(strs); i += 1) { + let q = 0z; + let buf = strings::to_utf8(strs[i]); + for (q < len(buf)) { + let w = io::write(st, buf[q..])?; + n += w; + q -= w; + }; + }; + return n; +}; + +@test fn concat() void = { + let st = dynamic(); + defer io::close(st); + concat(st, "hello"); + concat(st, " ", "world"); + assert(string(st) == "hello world"); +};