Merge pull request #5706 from wrathdoesthat/master

Unify filepath.join return between unix/windows
This commit is contained in:
gingerBill
2025-09-25 09:29:38 +01:00
committed by GitHub
+13 -16
View File
@@ -32,7 +32,6 @@ is_UNC :: proc(path: string) -> bool {
return volume_name_len(path) > 2 return volume_name_len(path) > 2
} }
is_abs :: proc(path: string) -> bool { is_abs :: proc(path: string) -> bool {
if is_reserved_name(path) { if is_reserved_name(path) {
return true return true
@@ -50,7 +49,6 @@ is_abs :: proc(path: string) -> bool {
return is_slash(path[0]) return is_slash(path[0])
} }
@(private) @(private)
temp_full_path :: proc(name: string) -> (path: string, err: os.Error) { temp_full_path :: proc(name: string) -> (path: string, err: os.Error) {
ta := context.temp_allocator ta := context.temp_allocator
@@ -76,8 +74,6 @@ temp_full_path :: proc(name: string) -> (path: string, err: os.Error) {
return win32.utf16_to_utf8(buf[:n], ta) return win32.utf16_to_utf8(buf[:n], ta)
} }
abs :: proc(path: string, allocator := context.allocator) -> (string, bool) { abs :: proc(path: string, allocator := context.allocator) -> (string, bool) {
runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD(ignore = allocator == context.temp_allocator) runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD(ignore = allocator == context.temp_allocator)
full_path, err := temp_full_path(path) full_path, err := temp_full_path(path)
@@ -88,17 +84,16 @@ abs :: proc(path: string, allocator := context.allocator) -> (string, bool) {
return p, true return p, true
} }
join :: proc(elems: []string, allocator := context.allocator) -> (string, runtime.Allocator_Error) #optional_allocator_error {
join :: proc(elems: []string, allocator := context.allocator) -> string {
for e, i in elems { for e, i in elems {
if e != "" { if e != "" {
return join_non_empty(elems[i:], allocator) return join_non_empty(elems[i:], allocator)
} }
} }
return "" return "", nil
} }
join_non_empty :: proc(elems: []string, allocator := context.allocator) -> string { join_non_empty :: proc(elems: []string, allocator := context.allocator) -> (joined: string, err: runtime.Allocator_Error) {
context.allocator = allocator context.allocator = allocator
runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD(ignore = allocator == context.temp_allocator) runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD(ignore = allocator == context.temp_allocator)
@@ -110,23 +105,25 @@ join_non_empty :: proc(elems: []string, allocator := context.allocator) -> strin
break break
} }
} }
s := strings.join(elems[i:], SEPARATOR_STRING, context.temp_allocator) s := strings.join(elems[i:], SEPARATOR_STRING, context.temp_allocator) or_return
s = strings.concatenate({elems[0], s}, context.temp_allocator) s = strings.concatenate({elems[0], s}, context.temp_allocator) or_return
return clean(s) return clean(s)
} }
p := clean(strings.join(elems, SEPARATOR_STRING, context.temp_allocator)) p := strings.join(elems, SEPARATOR_STRING, context.temp_allocator) or_return
p = clean(p) or_return
if !is_UNC(p) { if !is_UNC(p) {
return p return p, nil
} }
head := clean(elems[0], context.temp_allocator) head := clean(elems[0], context.temp_allocator) or_return
if is_UNC(head) { if is_UNC(head) {
return p return p, nil
} }
delete(p) // It is not needed now delete(p) // It is not needed now
tail := clean(strings.join(elems[1:], SEPARATOR_STRING, context.temp_allocator), context.temp_allocator) tail := strings.join(elems[1:], SEPARATOR_STRING, context.temp_allocator) or_return
tail = clean(tail, context.temp_allocator) or_return
if head[len(head)-1] == SEPARATOR { if head[len(head)-1] == SEPARATOR {
return strings.concatenate({head, tail}) return strings.concatenate({head, tail})
} }