diff options
Diffstat (limited to 'src/support/string.h')
-rw-r--r-- | src/support/string.h | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/support/string.h b/src/support/string.h index 72bbdb509..b3d12c6ae 100644 --- a/src/support/string.h +++ b/src/support/string.h @@ -21,6 +21,7 @@ #ifndef wasm_support_string_h #define wasm_support_string_h +#include <cctype> #include <string> #include <vector> @@ -104,6 +105,15 @@ inline bool wildcardMatch(const std::string& pattern, return value.size() == pattern.size(); } +// Removes any extra whitespace or \0. +inline std::string trim(const std::string& input) { + size_t size = input.size(); + while (size > 0 && (isspace(input[size - 1]) || input[size - 1] == '\0')) { + size--; + } + return input.substr(0, size); +} + } // namespace String } // namespace wasm |