From: Brendan Hansen Date: Sat, 13 May 2023 17:37:35 +0000 (-0500) Subject: added: `os.path_join` and `os.path_basename` X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=85a8c152bc25b3038752463eb9eb19cad3faa505;p=onyx.git added: `os.path_join` and `os.path_basename` --- diff --git a/core/os/path.onyx b/core/os/path.onyx new file mode 100644 index 00000000..9ecdb3d4 --- /dev/null +++ b/core/os/path.onyx @@ -0,0 +1,27 @@ +package core.os + +use runtime +use core.string +use core.conv + +#if runtime.compiler_os == .Windows { + PATH_SEP :: '\\' +} else { + PATH_SEP :: '/' +} + +path_join :: (parent: str, child: str, allocator := context.temp_allocator) -> str { + out := make(dyn_str, allocator=allocator); + if parent[parent.length - 1] == PATH_SEP { + return conv.format(&out, "{}{}", parent, child); + } else { + return conv.format(&out, "{}{}{}", parent, PATH_SEP, child); + } +} + +path_basename :: (path: str) -> str { + start := string.last_index_of(path, PATH_SEP); + end := string.last_index_of(path, '.'); + return path[start + 1 .. end]; +} + diff --git a/core/std.onyx b/core/std.onyx index 22b9fe0e..da8023d1 100644 --- a/core/std.onyx +++ b/core/std.onyx @@ -73,6 +73,7 @@ use runtime #if runtime.platform.Supports_Directories { #load "./os/dir" + #load "./os/path" } #if runtime.platform.Supports_Os {