aboutsummaryrefslogtreecommitdiff
path: root/src/StringUtils.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/StringUtils.cpp')
-rw-r--r--src/StringUtils.cpp21
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);