added: `os.path_join` and `os.path_basename`
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Sat, 13 May 2023 17:37:35 +0000 (12:37 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Sat, 13 May 2023 17:37:35 +0000 (12:37 -0500)
core/os/path.onyx [new file with mode: 0644]
core/std.onyx

diff --git a/core/os/path.onyx b/core/os/path.onyx
new file mode 100644 (file)
index 0000000..9ecdb3d
--- /dev/null
@@ -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];
+}
+
index 22b9fe0eb996abfed839d91f2b69188ffd656a34..da8023d1384db176a00407b8ee66cbd95e01e1d8 100644 (file)
@@ -73,6 +73,7 @@ use runtime
 
 #if runtime.platform.Supports_Directories {
     #load "./os/dir"
+    #load "./os/path"
 }
 
 #if runtime.platform.Supports_Os {