util.ha (579B)
1 // License: MPL-2.0 2 // (c) 2021-2022 Drew DeVault <sir@cmpwn.com> 3 use strings; 4 5 fn getbytes(in: (str | *buffer)) []u8 = { 6 match (in) { 7 case let st: str => 8 return strings::toutf8(st); 9 case let buf: *buffer => 10 return buf.buf[..buf.end]; 11 }; 12 }; 13 14 fn getstring(in: (str | *buffer)) str = { 15 match (in) { 16 case let st: str => 17 return st; 18 case let buf: *buffer => 19 return string(buf); 20 }; 21 }; 22 23 // Returns true if a path is an absolute path. 24 export fn abs(path: str) bool = { 25 let path = getbytes(path); 26 if (len(path) == 0) { 27 return false; 28 }; 29 return path[0] == PATHSEP; 30 };