mirror of
https://github.com/odin-lang/Odin.git
synced 2026-05-05 04:24:41 +00:00
Update package os for package path/filepath support on macOS
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
return n;
|
||||
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;
|
||||
}
|
||||
}
|
||||
for ; n < l; n += 1 {
|
||||
if is_slash(path[n]) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
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
|
||||
|
||||
@@ -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 "";
|
||||
}
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user