diff options
| author | gingerBill <bill@gingerbill.org> | 2021-02-27 11:30:43 +0000 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2021-02-27 11:30:43 +0000 |
| commit | a2557142ccb6ec33d53f54333bcd79bdfeaa43a2 (patch) | |
| tree | 242313b725f28ac6bfdbcba67ec7e886eb7c0c4b /core/path | |
| parent | fa09640e7e8cdb8dfcbf91c23f9d82a0b7701454 (diff) | |
Update package os for package path/filepath support on macOS
Diffstat (limited to 'core/path')
| -rw-r--r-- | core/path/filepath/path.odin | 101 | ||||
| -rw-r--r-- | core/path/filepath/path_unix.odin | 23 | ||||
| -rw-r--r-- | core/path/filepath/path_windows.odin | 50 |
3 files changed, 93 insertions, 81 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 diff --git a/core/path/filepath/path_unix.odin b/core/path/filepath/path_unix.odin index faf1d9568..8db5064d2 100644 --- a/core/path/filepath/path_unix.odin +++ b/core/path/filepath/path_unix.odin @@ -8,6 +8,14 @@ SEPARATOR :: '/'; SEPARATOR_STRING :: `/`; LIST_SEPARATOR :: ':'; +is_reserved_name :: proc(path: string) -> bool { + return false; +} + +is_abs :: proc(path: string) -> bool { + return strings.has_prefix(path, "/"); +} + abs :: proc(path: string, allocator := context.allocator) -> (string, bool) { full_path, err := os.absolute_path_from_relative(path); if err != os.ERROR_NONE { @@ -17,10 +25,11 @@ abs :: proc(path: string, allocator := context.allocator) -> (string, bool) { } join :: proc(elems: ..string, allocator := context.allocator) -> string { - s := strings.join(elems, SEPARATOR_STRING); - return s; -} - -is_abs :: proc(path: string) -> bool { - return (path[0] == '/'); -} + for e, i in elems { + if e != "" { + p := strings.join(elems[i:], SEPARATOR_STRING, context.temp_allocator); + return clean(p, allocator); + } + } + return ""; +}
\ No newline at end of file diff --git a/core/path/filepath/path_windows.odin b/core/path/filepath/path_windows.odin index 39db7de14..a0908be67 100644 --- a/core/path/filepath/path_windows.odin +++ b/core/path/filepath/path_windows.odin @@ -87,56 +87,6 @@ abs :: proc(path: string, allocator := context.allocator) -> (string, bool) { return p, true; } -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; -} - - - join :: proc(elems: ..string, allocator := context.allocator) -> string { for e, i in elems { |