added path_fix_separators

This commit is contained in:
2026-06-07 21:55:13 +05:00
parent 82a6293f21
commit efa4a24304
5 changed files with 19 additions and 1 deletions

View File

@@ -31,6 +31,9 @@
#define path_notseps "\\"
#endif
// @brief replaces path_notsep with path_sep
void path_fix_separators(str* path);
/// @brief removes part of path after path_sep (including path_sep)
/// @return pointer to a segment of path.data or "." if no path_sep has been found
str path_dirname(str path);

View File

@@ -90,6 +90,10 @@ str hex_to_str(Array(u8) buf, bool uppercase);
void str_trim(str* line, bool set_zero_at_end);
/// replaces all occurences of `fragment` in `s` with `replacement`
void str_replaceChar(str* s, char fragment, char replacement);
///@return s[0..n]
static inline str str_sliceBefore(str s, u32 n){
return str_construct(s.data, n, false);

View File

@@ -35,7 +35,7 @@ OBJDIR="obj"
OUTDIR="bin"
STATIC_LIB_FILE="$PROJECT.a"
INCLUDE="-I./include"
INCLUDE="-Iinclude"
# OS-specific options
case "$OS" in

View File

@@ -6,6 +6,10 @@
#else
#endif
void path_fix_separators(str* path){
str_replaceChar(path, path_notsep, path_sep);
}
str path_dirname(str path){
if(path.len == 0)
return path;

View File

@@ -175,3 +175,10 @@ void str_trim(str* line, bool set_zero_at_end){
line->isZeroTerminated = true;
}
}
void str_replaceChar(str* s, char fragment, char replacement){
for(u32 i = 0; i < s->len; i++){
if(s->data[i] == fragment)
s->data[i] = replacement;
}
}