diff options
| author | gingerBill <bill@gingerbill.org> | 2018-02-25 11:49:44 +0000 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2018-02-25 11:49:44 +0000 |
| commit | e14e2c3b4d460887056c68f3926f2b96f276777a (patch) | |
| tree | 3a17aeb7cef0b569e7d7f7d0d5b45394a4a841f0 /src/string.cpp | |
| parent | f96a8978212dabaf4f6a5267b8f098d356d1ffe2 (diff) | |
`-out` and generate executable in the current working directory
Diffstat (limited to 'src/string.cpp')
| -rw-r--r-- | src/string.cpp | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/src/string.cpp b/src/string.cpp index 822a386d7..333e1aa05 100644 --- a/src/string.cpp +++ b/src/string.cpp @@ -84,7 +84,7 @@ gb_inline String make_string_c(char *text) { String substring(String s, isize lo, isize hi) { isize max = s.len; - GB_ASSERT(lo <= hi && hi <= max); + GB_ASSERT_MSG(lo <= hi && hi <= max, "%td..%td..%td", lo, hi, max); return make_string(s.text+lo, hi-lo); } @@ -211,6 +211,15 @@ gb_inline isize string_extension_position(String str) { return dot_pos; } +String path_extension(String str) { + isize pos = string_extension_position(str); + if (pos < 0) { + return make_string(nullptr, 0); + } + return substring(str, pos, str.len); +} + + String string_trim_whitespace(String str) { while (str.len > 0 && rune_is_whitespace(str[str.len-1])) { str.len--; @@ -239,17 +248,16 @@ bool string_contains_char(String s, u8 c) { String filename_from_path(String s) { isize i = string_extension_position(s); + s = substring(s, 0, i); if (i > 0) { isize j = 0; - s.len = i; - for (j = i-1; j >= 0; j--) { + for (j = s.len-1; j >= 0; j--) { if (s[j] == '/' || s[j] == '\\') { break; } } - s.text += j+1; - s.len = i-j-1; + return substring(s, j+1, s.len); } return make_string(nullptr, 0); } |