rewritten Array and List, changed str.size -> .len
This commit is contained in:
@@ -141,7 +141,7 @@ Result(void) file_readWhole(FILE* f, Array(u8)* out_buf){
|
||||
bool success = false;
|
||||
|
||||
try(i64 f_size, i, file_getSize(f));
|
||||
Array(u8) buf = Array_alloc(u8, f_size);
|
||||
Array(u8) buf = Array_u8_alloc(f_size);
|
||||
Defer(if(!success) free(buf.data));
|
||||
try_void(file_readBytesArray(f, buf));
|
||||
|
||||
|
||||
@@ -1,36 +1,36 @@
|
||||
#include "tlibc/filesystem.h"
|
||||
|
||||
str path_dirname(str path){
|
||||
if(path.size == 0)
|
||||
if(path.len == 0)
|
||||
return path;
|
||||
|
||||
// remove trailing slash (name/)
|
||||
if(path.data[path.size - 1] == path_sep){
|
||||
path.size -= 1;
|
||||
if(path.data[path.len - 1] == path_sep){
|
||||
path.len -= 1;
|
||||
}
|
||||
|
||||
i32 sepIndex = str_seekCharReverse(path, path_sep, -1);
|
||||
if(sepIndex < 0)
|
||||
return STR(".");
|
||||
|
||||
path.size = sepIndex;
|
||||
path.len = sepIndex;
|
||||
path.isZeroTerminated = false;
|
||||
return path;
|
||||
}
|
||||
|
||||
str path_basename(str path, bool remove_ext){
|
||||
if(path.size == 0)
|
||||
if(path.len == 0)
|
||||
return path;
|
||||
|
||||
// remove trailing slash (name/)
|
||||
if(path.data[path.size - 1] == path_sep){
|
||||
path.size -= 1;
|
||||
if(path.data[path.len - 1] == path_sep){
|
||||
path.len -= 1;
|
||||
}
|
||||
|
||||
i32 nameIndex = str_seekCharReverse(path, path_sep, -1) + 1;
|
||||
if((u32)nameIndex != 0){
|
||||
path.data += nameIndex;
|
||||
path.size -= nameIndex;
|
||||
path.len -= nameIndex;
|
||||
}
|
||||
|
||||
if(!remove_ext)
|
||||
@@ -38,7 +38,7 @@ str path_basename(str path, bool remove_ext){
|
||||
|
||||
i32 extIndex = str_seekCharReverse(path, '.', -1);
|
||||
if(extIndex > 0){
|
||||
path.size = extIndex;
|
||||
path.len = extIndex;
|
||||
path.isZeroTerminated = false;
|
||||
}
|
||||
return path;
|
||||
|
||||
Reference in New Issue
Block a user