hare

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

commit a48194508062e2f60eb956273f52052d6efe7ffe
parent baf3b6bdad164b9e05ced89eda3cdb9e8ff087b8
Author: Drew DeVault <sir@cmpwn.com>
Date:   Sat,  8 Jan 2022 11:26:32 +0100

path::iter: accept *path::buffer as input

Signed-off-by: Drew DeVault <sir@cmpwn.com>

Diffstat:
Mpath/iter.ha | 19++++++++++++-------
Mpath/join.ha | 2+-
2 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/path/iter.ha b/path/iter.ha @@ -15,19 +15,24 @@ let pathsep: []u8 = [PATHSEP]; // Returns an iterator which yields each component of a path. If the path is // absolute, the first component will be the root path (e.g. "/"). -export fn iter(path: str) iterator = { +export fn iter(path: (str | *buffer)) iterator = { + let path = match (path) { + case let s: str => + yield strings::toutf8(s); + case let b: *buffer => + yield b.cur; + }; let flags = iflags::NONE; - let pb = strings::toutf8(path); - if (len(pb) > 0 && pb[0] == PATHSEP) { + if (len(path) > 0 && path[0] == PATHSEP) { flags |= iflags::ABSOLUTE; - pb = pb[1..]; + path = path[1..]; }; - if (len(pb) > 1 && pb[len(pb) - 1] == PATHSEP) { - pb = pb[..len(pb) - 1]; + if (len(path) > 1 && path[len(path) - 1] == PATHSEP) { + path = path[..len(path) - 1]; }; return iterator { - tok = bytes::tokenize(pb, pathsep), + tok = bytes::tokenize(path, pathsep), flags = flags, }; }; diff --git a/path/join.ha b/path/join.ha @@ -2,7 +2,7 @@ use bytes; use errors; use strings; -// Joins several path elements together and appends them to a path buffer. +// Joins several path elements together and copies them into a path buffer. export fn add(buf: *buffer, items: str...) (void | errors::overflow) = { for (let i = 0z; i < len(items); i += 1) { const elem = strings::toutf8(items[i]);