diff options
| author | Karl Zylinski <karl@zylinski.se> | 2022-04-27 20:50:54 +0200 |
|---|---|---|
| committer | Karl Zylinski <karl@zylinski.se> | 2022-04-27 20:50:54 +0200 |
| commit | 5650087aa3561b5972dde34890de2639a3d3ca54 (patch) | |
| tree | 9905467b5376bc480da0e321643cd1761ae43319 /src/string.cpp | |
| parent | 67689ecb21bc1735871b36fdf1411fbffb02e8fb (diff) | |
| parent | c5982e52d57ceba420d70f1d8d9d10197f4c7d61 (diff) | |
Merge remote-tracking branch 'origin/master' into d3d12-binding-fixes
Diffstat (limited to 'src/string.cpp')
| -rw-r--r-- | src/string.cpp | 37 |
1 files changed, 2 insertions, 35 deletions
diff --git a/src/string.cpp b/src/string.cpp index d3dbc6904..616761265 100644 --- a/src/string.cpp +++ b/src/string.cpp @@ -245,15 +245,14 @@ gb_inline isize string_extension_position(String const &str) { return dot_pos; } -String path_extension(String const &str) { +String path_extension(String const &str, bool include_dot = true) { isize pos = string_extension_position(str); if (pos < 0) { return make_string(nullptr, 0); } - return substring(str, pos, str.len); + return substring(str, include_dot ? pos : pos + 1, str.len); } - String string_trim_whitespace(String str) { while (str.len > 0 && rune_is_whitespace(str[str.len-1])) { str.len--; @@ -299,38 +298,6 @@ String filename_from_path(String s) { return make_string(nullptr, 0); } -String remove_extension_from_path(String const &s) { - for (isize i = s.len-1; i >= 0; i--) { - if (s[i] == '.') { - return substring(s, 0, i); - } - } - return s; -} - -String remove_directory_from_path(String const &s) { - isize len = 0; - for (isize i = s.len-1; i >= 0; i--) { - if (s[i] == '/' || - s[i] == '\\') { - break; - } - len += 1; - } - return substring(s, s.len-len, s.len); -} - -String directory_from_path(String const &s) { - isize i = s.len-1; - for (; i >= 0; i--) { - if (s[i] == '/' || - s[i] == '\\') { - break; - } - } - return substring(s, 0, i); -} - String concatenate_strings(gbAllocator a, String const &x, String const &y) { isize len = x.len+y.len; u8 *data = gb_alloc_array(a, u8, len+1); |