diff options
| author | Joel Klinghed <the_jk@spawned.biz> | 2025-09-27 20:11:32 +0200 |
|---|---|---|
| committer | Joel Klinghed <the_jk@spawned.biz> | 2025-09-28 22:48:24 +0200 |
| commit | c1ae5d53fb0fa7ceb9d6fc7a60c87df958ce37fe (patch) | |
| tree | f028a04619aa1b69f8b0aa72a5154f6ba1c09775 /src/str.cc | |
| parent | 2f13baa843bd1fb5db6630a2823681ffaff9fb11 (diff) | |
WIPWIP
Diffstat (limited to 'src/str.cc')
| -rw-r--r-- | src/str.cc | 19 |
1 files changed, 19 insertions, 0 deletions
@@ -6,6 +6,15 @@ namespace str { +namespace { + +[[nodiscard]] +inline bool is_space(char c) { + return c == ' ' || c == '\t' || c == '\r' || c == '\n'; +} + +} // namespace + void split(std::string_view str, std::vector<std::string_view>& out, char separator, bool keep_empty) { out.clear(); @@ -31,4 +40,14 @@ std::vector<std::string_view> split(std::string_view str, char separator, return vec; } +std::string_view trim(std::string_view str) { + size_t s = 0; + size_t e = str.size(); + while (s < e && is_space(str[s])) + ++s; + while (e > s && is_space(str[e - 1])) + --e; + return str.substr(s, e - s); +} + } // namespace str |
