diff --git a/include/tlibc/filesystem.h b/include/tlibc/filesystem.h index d8f1954..74fb2a5 100644 --- a/include/tlibc/filesystem.h +++ b/include/tlibc/filesystem.h @@ -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); diff --git a/include/tlibc/string/str.h b/include/tlibc/string/str.h index 69c1b95..c047937 100755 --- a/include/tlibc/string/str.h +++ b/include/tlibc/string/str.h @@ -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); diff --git a/project.config b/project.config index ddb9a81..a84ab45 100644 --- a/project.config +++ b/project.config @@ -35,7 +35,7 @@ OBJDIR="obj" OUTDIR="bin" STATIC_LIB_FILE="$PROJECT.a" -INCLUDE="-I./include" +INCLUDE="-Iinclude" # OS-specific options case "$OS" in diff --git a/src/filesystem/path.c b/src/filesystem/path.c index 9bce84c..e05b95a 100644 --- a/src/filesystem/path.c +++ b/src/filesystem/path.c @@ -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; diff --git a/src/string/str.c b/src/string/str.c index dbd553f..7c83152 100755 --- a/src/string/str.c +++ b/src/string/str.c @@ -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; + } +}