diff options
| author | gingerBill <bill@gingerbill.org> | 2024-04-16 13:15:23 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2024-04-16 13:15:23 +0100 |
| commit | 8a0f9ae108a75d9ca86b8a91fca2f2423e0a58df (patch) | |
| tree | ac9e6931e218363086c99fd11e7bfed0b356e24f /src/string.cpp | |
| parent | fd1eb17771a6d8bb196635141f517a3a7928a8f1 (diff) | |
Print to string buffer before printing errors
Diffstat (limited to 'src/string.cpp')
| -rw-r--r-- | src/string.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/string.cpp b/src/string.cpp index 4adec7a90..3747f4564 100644 --- a/src/string.cpp +++ b/src/string.cpp @@ -276,6 +276,43 @@ gb_internal String string_trim_whitespace(String str) { return str; } +gb_internal String string_trim_trailing_whitespace(String str) { + while (str.len > 0) { + u8 c = str[str.len-1]; + if (rune_is_whitespace(c) || c == 0) { + str.len -= 1; + } else { + break; + } + } + return str; +} + +gb_internal String split_lines_first_line_from_array(Array<u8> const &array, gbAllocator allocator) { + String_Iterator it = {{array.data, array.count}, 0}; + + String line = string_split_iterator(&it, '\n'); + line = string_trim_trailing_whitespace(line); + return line; +} + +gb_internal Array<String> split_lines_from_array(Array<u8> const &array, gbAllocator allocator) { + Array<String> lines = {}; + lines.allocator = allocator; + + String_Iterator it = {{array.data, array.count}, 0}; + + for (;;) { + String line = string_split_iterator(&it, '\n'); + if (line.len == 0) { + break; + } + line = string_trim_trailing_whitespace(line); + array_add(&lines, line); + } + + return lines; +} gb_internal bool string_contains_char(String const &s, u8 c) { isize i; |