hare

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

commit 3fdfbe28993972680bdfb1598b29a711963e2409
parent 3e2c4b167fadac4461ce863100a3e42c819d4ffe
Author: Humm <hummsmith42@gmail.com>
Date:   Mon, 10 Jan 2022 15:45:18 +0000

path::doappend: append separator to short buffer

When appending to a buffer that had exactly one octet in it, no path
separator would be placed before the new element:

	path::join("a", "b", "c") == "ab/c"

Signed-off-by: Humm <hummsmith42@gmail.com>

Diffstat:
Mpath/buffer.ha | 23++++++++++++++---------
1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/path/buffer.ha b/path/buffer.ha @@ -129,7 +129,7 @@ fn doappend(buf: *buffer, elem: []u8) (void | errors::overflow) = { if (len(buf.cur) + len(elem) + 1 >= PATH_MAX) { return errors::overflow; }; - if (len(buf.cur) > 1 && buf.cur[len(buf.cur) - 1] != PATHSEP) { + if (len(buf.cur) > 0 && buf.cur[len(buf.cur) - 1] != PATHSEP) { static append(buf.cur, PATHSEP); }; static append(buf.cur, elem...); @@ -193,12 +193,17 @@ fn doappend(buf: *buffer, elem: []u8) (void | errors::overflow) = { appendnorm(&buf, "..")!; assert(string(&buf) == "../.."); - set(&buf, "foo", "bar")!; - assert(string(&buf) == "foo/bar"); - set(&buf, "foo", "bar/")!; - assert(string(&buf) == "foo/bar/"); - set(&buf, "foo", "bar", "/")!; - assert(string(&buf) == "foo/bar/"); - add(&buf, "/baz")!; - assert(string(&buf) == "foo/bar/baz"); + set(&buf, "foo", "bar")!; + assert(string(&buf) == "foo/bar"); + set(&buf, "foo", "bar/")!; + assert(string(&buf) == "foo/bar/"); + set(&buf, "foo", "bar", "/")!; + assert(string(&buf) == "foo/bar/"); + add(&buf, "/baz")!; + assert(string(&buf) == "foo/bar/baz"); + + reset(&buf); + appendnorm(&buf, "a")!; + appendnorm(&buf, "b")!; + assert(string(&buf) == "a/b"); };