diff options
Diffstat (limited to 'src/StringUtils.cpp')
-rw-r--r-- | src/StringUtils.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/StringUtils.cpp b/src/StringUtils.cpp index 8d8b62e..81ea1eb 100644 --- a/src/StringUtils.cpp +++ b/src/StringUtils.cpp @@ -90,6 +90,27 @@ namespace QuickMedia { return str.substr(start, end - start + 1); } + void strip(const char *str, size_t size, size_t *new_size) { + if(size == 0) { + *new_size = 0; + return; + } + + int start = 0; + for(; start < (int)size; ++start) { + if(!is_whitespace(str[start])) + break; + } + + int end = (int)size - 1; + for(; end >= start; --end) { + if(!is_whitespace(str[end])) + break; + } + + *new_size = end - start + 1; + } + bool string_starts_with(const std::string &str, const char *sub) { size_t sub_len = strlen(sub); return sub_len == 0 || (str.size() >= sub_len && memcmp(str.c_str(), sub, sub_len) == 0); |