From 85a8c152bc25b3038752463eb9eb19cad3faa505 Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Sat, 13 May 2023 12:37:35 -0500 Subject: [PATCH] added: `os.path_join` and `os.path_basename` --- core/os/path.onyx | 27 +++++++++++++++++++++++++++ core/std.onyx | 1 + 2 files changed, 28 insertions(+) create mode 100644 core/os/path.onyx 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 { -- 2.25.1