diff options
Diffstat (limited to 'src/include/convert.h')
-rw-r--r-- | src/include/convert.h | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/include/convert.h b/src/include/convert.h index 0c7e703..030c1b5 100644 --- a/src/include/convert.h +++ b/src/include/convert.h @@ -15,6 +15,7 @@ #include <iomanip> #include <iostream> #include <string> +#include <string_view> #include <vector> #include <stdio.h> @@ -130,6 +131,22 @@ namespace Binc { chomp(s_in, chars); } + inline void trim(std::string_view &s_in, std::string_view chars = " \t\r\n") + { + size_t n = 0; + while (n < s_in.length() && chars.find(s_in[n]) != std::string_view::npos) { + n++; + } + s_in = s_in.substr(n); + + if (s_in.empty()) return; + + n = s_in.length(); + while (n > 0 && chars.find(s_in[--n]) != std::string_view::npos) { + } + s_in = s_in.substr(0, n + 1); + } + inline const std::string unfold(const std::string &a, bool removecomment = true) { std::string tmp; |