diff options
| author | Jeroen van Rijn <Kelimion@users.noreply.github.com> | 2025-10-31 14:24:30 +0100 |
|---|---|---|
| committer | Jeroen van Rijn <Kelimion@users.noreply.github.com> | 2026-02-08 12:51:29 +0100 |
| commit | 691dc44719700add54f1ec86fbed9f9a93183855 (patch) | |
| tree | 9e99af8d650bac17ee894c9b8d57481b16af8034 | |
| parent | cc50be1a6cea7587656124ad3fc0917e1ad9f737 (diff) | |
Add `glob` + `match` to os2
| -rw-r--r-- | core/os/os2/path.odin | 30 | ||||
| -rw-r--r-- | tests/core/os/os2/path.odin | 8 |
2 files changed, 30 insertions, 8 deletions
diff --git a/core/os/os2/path.odin b/core/os/os2/path.odin index 55659d88f..c3effe69e 100644 --- a/core/os/os2/path.odin +++ b/core/os/os2/path.odin @@ -22,6 +22,11 @@ is_path_separator :: proc(c: byte) -> bool { return _is_path_separator(c) } +@(private) +is_slash :: proc(c: byte) -> bool { + return c == '\\' || c == '/' +} + mkdir :: make_directory /* @@ -668,6 +673,15 @@ match :: proc(pattern, name: string) -> (matched: bool, err: Error) { // glob ignores file system errors // glob :: proc(pattern: string, allocator := context.allocator) -> (matches: []string, err: Error) { + _split :: proc(path: string) -> (dir, file: string) { + vol := volume_name(path) + i := len(path) - 1 + for i >= len(vol) && !is_path_separator(path[i]) { + i -= 1 + } + return path[:i+1], path[i+1:] + } + context.allocator = allocator if !has_meta(pattern) { @@ -677,13 +691,14 @@ glob :: proc(pattern: string, allocator := context.allocator) -> (matches: []str return m[:], nil } - dir, file := split_path(pattern) + // NOTE(Jeroen): For `glob`, we need this version of `split`, which leaves the trailing `/` on `dir`. + dir, file := _split(pattern) - volume_len: int - temp_buf: [8]byte - volume_len, dir = _clean_glob_path(dir, temp_buf[:]) + temp_buf: [8]byte + vol_len: int + vol_len, dir = clean_glob_path(dir, temp_buf[:]) - if !has_meta(dir[volume_len:]) { + if !has_meta(dir[vol_len:]) { m, e := _glob(dir, file, nil) return m[:], e } @@ -904,10 +919,9 @@ has_meta :: proc(path: string) -> bool { } @(private) -_clean_glob_path :: proc(path: string, temp_buf: []byte) -> (prefix_len: int, cleaned: string) { +clean_glob_path :: proc(path: string, temp_buf: []byte) -> (int, string) { when ODIN_OS == .Windows { vol_len := _volume_name_len(path) - switch { case path == "": return 0, "." @@ -927,7 +941,7 @@ _clean_glob_path :: proc(path: string, temp_buf: []byte) -> (prefix_len: int, cl switch path { case "": return 0, "." - case _Path_Separator_String: + case Path_Separator_String: return 0, path } return 0, path[:len(path)-1] diff --git a/tests/core/os/os2/path.odin b/tests/core/os/os2/path.odin index 7b1cb0146..1a470396b 100644 --- a/tests/core/os/os2/path.odin +++ b/tests/core/os/os2/path.odin @@ -375,3 +375,11 @@ test_split_path_list :: proc(t: ^testing.T) { } } } + +@(test) +test_glob :: proc(t: ^testing.T) { + + + + +}
\ No newline at end of file |