aboutsummaryrefslogtreecommitdiff
path: root/core/path/filepath/path.odin
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2021-02-27 11:30:43 +0000
committergingerBill <bill@gingerbill.org>2021-02-27 11:30:43 +0000
commita2557142ccb6ec33d53f54333bcd79bdfeaa43a2 (patch)
tree242313b725f28ac6bfdbcba67ec7e886eb7c0c4b /core/path/filepath/path.odin
parentfa09640e7e8cdb8dfcbf91c23f9d82a0b7701454 (diff)
Update package os for package path/filepath support on macOS
Diffstat (limited to 'core/path/filepath/path.odin')
-rw-r--r--core/path/filepath/path.odin101
1 files changed, 77 insertions, 24 deletions
diff --git a/core/path/filepath/path.odin b/core/path/filepath/path.odin
index f19a10d46..5ec28c2ec 100644
--- a/core/path/filepath/path.odin
+++ b/core/path/filepath/path.odin
@@ -32,36 +32,38 @@ volume_name :: proc(path: string) -> string {
}
volume_name_len :: proc(path: string) -> int {
- if len(path) < 2 {
- return 0;
- }
- c := path[0];
- if path[1] == ':' {
- switch c {
- case 'a'..'z', 'A'..'Z':
- return 2;
+ if ODIN_OS == "windows" {
+ if len(path) < 2 {
+ return 0;
+ }
+ c := path[0];
+ if path[1] == ':' {
+ switch c {
+ case 'a'..'z', 'A'..'Z':
+ return 2;
+ }
}
- }
- // URL: https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx
- if l := len(path); l >= 5 && is_slash(path[0]) && is_slash(path[1]) &&
- !is_slash(path[2]) && path[2] != '.' {
- for n := 3; n < l-1; n += 1 {
- if is_slash(path[n]) {
- n += 1;
- if !is_slash(path[n]) {
- if path[n] == '.' {
- break;
+ // URL: https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx
+ if l := len(path); l >= 5 && is_slash(path[0]) && is_slash(path[1]) &&
+ !is_slash(path[2]) && path[2] != '.' {
+ for n := 3; n < l-1; n += 1 {
+ if is_slash(path[n]) {
+ n += 1;
+ if !is_slash(path[n]) {
+ if path[n] == '.' {
+ break;
+ }
}
- }
- for ; n < l; n += 1 {
- if is_slash(path[n]) {
- break;
+ for ; n < l; n += 1 {
+ if is_slash(path[n]) {
+ break;
+ }
}
+ return n;
}
- return n;
+ break;
}
- break;
}
}
return 0;
@@ -296,6 +298,57 @@ dir :: proc(path: string, allocator := context.allocator) -> string {
+split_list :: proc(path: string, allocator := context.allocator) -> []string {
+ if path == "" {
+ return nil;
+ }
+
+ start: int;
+ quote: bool;
+
+ start, quote = 0, false;
+ count := 0;
+
+ for i := 0; i < len(path); i += 1 {
+ c := path[i];
+ switch {
+ case c == '"':
+ quote = !quote;
+ case c == LIST_SEPARATOR && !quote:
+ count += 1;
+ }
+ }
+
+ start, quote = 0, false;
+ list := make([]string, count, allocator);
+ index := 0;
+ for i := 0; i < len(path); i += 1 {
+ c := path[i];
+ switch {
+ case c == '"':
+ quote = !quote;
+ case c == LIST_SEPARATOR && !quote:
+ list[index] = path[start:i];
+ index += 1;
+ start = i + 1;
+ }
+ }
+ assert(index == count);
+
+ for s0, i in list {
+ s, new := strings.replace_all(s0, `"`, ``, allocator);
+ if !new {
+ s = strings.clone(s, allocator);
+ }
+ list[i] = s;
+ }
+
+ return list;
+}
+
+
+
+
/*
Lazy_Buffer is a lazily made path buffer
When it does allocate, it uses the context.allocator