hare

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

commit f8e3bf486e99a8231d19cae1ad1076facd6e93ce
parent 8e87bce4bf91e0934563ed53f4ea0cd364dbead7
Author: Drew DeVault <sir@cmpwn.com>
Date:   Tue,  9 Mar 2021 21:56:22 -0500

path: add dup

Diffstat:
Mpath/util.ha | 11+++++++++++
1 file changed, 11 insertions(+), 0 deletions(-)

diff --git a/path/util.ha b/path/util.ha @@ -15,6 +15,17 @@ export fn path_free(p: path) void = match (p) { b: []u8 => free(b), }; +// Duplicates a path. +export fn dup(p: path) path = match (p) { + s: str => strings::dup(s), + b: []u8 => { + // TODO: alloc from another slice + let new: []u8 = alloc([], len(b)); + append(new, ...b); + new; + }, +}; + // Returns true if two paths are equal. export fn equal(a: path, b: path) bool = bytes::equal(pathbytes(a), pathbytes(b));