aboutsummaryrefslogtreecommitdiff
path: root/src/StringUtils.cpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2019-12-01 18:05:16 +0100
committerdec05eba <dec05eba@protonmail.com>2019-12-01 18:05:16 +0100
commit6c7adadf6d5c85d5e280e965d4dee1563bf46821 (patch)
treefecdef2d933e0e83e23e0d87bf42139820490bbc /src/StringUtils.cpp
parent129d842030fa993e800009ec0ab170f109e8e899 (diff)
Add 4chan posting
Diffstat (limited to 'src/StringUtils.cpp')
-rw-r--r--src/StringUtils.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/StringUtils.cpp b/src/StringUtils.cpp
index deb4949..16d3b48 100644
--- a/src/StringUtils.cpp
+++ b/src/StringUtils.cpp
@@ -14,4 +14,37 @@ namespace QuickMedia {
index = new_index + 1;
}
}
+
+ void string_replace_all(std::string &str, const std::string &old_str, const std::string &new_str) {
+ size_t index = 0;
+ while(true) {
+ index = str.find(old_str, index);
+ if(index == std::string::npos)
+ return;
+ str.replace(index, old_str.size(), new_str);
+ }
+ }
+
+ static bool is_whitespace(char c) {
+ return c == ' ' || c == '\n' || c == '\t' || c == '\v';
+ }
+
+ std::string strip(const std::string &str) {
+ if(str.empty())
+ return str;
+
+ int start = 0;
+ for(; start < (int)str.size(); ++start) {
+ if(!is_whitespace(str[start]))
+ break;
+ }
+
+ int end = str.size() - 1;
+ for(; end >= start; --end) {
+ if(!is_whitespace(str[end]))
+ break;
+ }
+
+ return str.substr(start, end - start + 1);
+ }
} \ No newline at end of file