summaryrefslogtreecommitdiff
path: root/src/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/stringutils.cpp79
-rw-r--r--src/utils/stringutils.h15
2 files changed, 91 insertions, 3 deletions
diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp
index 13170092e..176c5499c 100644
--- a/src/utils/stringutils.cpp
+++ b/src/utils/stringutils.cpp
@@ -181,9 +181,9 @@ unsigned long findI(std::string str, std::string subStr)
return str.find(subStr);
}
-unsigned long findI(std::string str, std::vector<std::string> &list)
+unsigned long findI(std::string text, std::vector<std::string> &list)
{
- str = toLower(str);
+ std::string str = toLower(text);
unsigned long idx;
for (std::vector<std::string>::iterator i = list.begin();
i != list.end(); ++i)
@@ -414,6 +414,19 @@ std::list<std::string> splitToStringList(const std::string &text,
return tokens;
}
+void splitToStringVector(std::vector<std::string> &tokens,
+ const std::string &text, char separator)
+{
+ std::stringstream ss(text);
+ std::string item;
+ while(std::getline(ss, item, separator))
+ {
+ item = trim(item);
+ if (!item.empty())
+ tokens.push_back(item);
+ }
+}
+
std::string combineDye(std::string file, std::string dye)
{
if (dye.empty())
@@ -511,3 +524,65 @@ void deleteCharLeft(std::string &str, unsigned *pos)
break;
}
}
+
+bool findLast(std::string &str1, std::string str2)
+{
+ const unsigned s1 = str1.size();
+ const unsigned s2 = str2.size();
+ if (s1 < s2)
+ return false;
+ std::string tmp = str1.substr(s1 - s2);
+ if (tmp == str2)
+ return true;
+ return false;
+}
+
+bool findFirst(std::string &str1, std::string str2)
+{
+ const unsigned s1 = str1.size();
+ const unsigned s2 = str2.size();
+ if (s1 < s2)
+ return false;
+ std::string tmp = str1.substr(0, s2);
+ if (tmp == str2)
+ return true;
+ return false;
+}
+
+bool findCutLast(std::string &str1, std::string str2)
+{
+ const unsigned s1 = str1.size();
+ const unsigned s2 = str2.size();
+ if (s1 < s2)
+ return false;
+ std::string tmp = str1.substr(s1 - s2);
+ if (tmp == str2)
+ {
+ str1 = str1.substr(0, s1 - s2);
+ return true;
+ }
+ return false;
+}
+
+bool findCutFirst(std::string &str1, std::string str2)
+{
+ const unsigned s1 = str1.size();
+ const unsigned s2 = str2.size();
+ if (s1 < s2)
+ return false;
+ std::string tmp = str1.substr(0, s2);
+ if (tmp == str2)
+ {
+ str1 = str1.substr(s2);
+ return true;
+ }
+ return false;
+}
+
+std::string &removeProtocol(std::string &url)
+{
+ int i = url.find("://");
+ if (i != (int)std::string::npos)
+ url = url.substr(i + 3);
+ return url;
+}
diff --git a/src/utils/stringutils.h b/src/utils/stringutils.h
index 94747d2fe..25fe11e2d 100644
--- a/src/utils/stringutils.h
+++ b/src/utils/stringutils.h
@@ -133,7 +133,7 @@ bool isWordSeparator(char chr);
unsigned long findI(std::string str, std::string subStr);
-unsigned long findI(std::string str, std::vector<std::string> &list);
+unsigned long findI(std::string text, std::vector<std::string> &list);
const std::string encodeStr(unsigned int value, unsigned int size = 0);
@@ -176,6 +176,9 @@ std::list<int> splitToIntList(const std::string &text, char separator);
std::list<std::string> splitToStringList(const std::string &text,
char separator);
+void splitToStringVector(std::vector<std::string> &tokens,
+ const std::string &text, char separator);
+
std::string combineDye(std::string file, std::string dye);
std::string combineDye2(std::string file, std::string dye);
@@ -190,4 +193,14 @@ std::string stringToHexPath(const std::string &str);
void deleteCharLeft(std::string &str, unsigned *pos);
+bool findLast(std::string &str1, std::string str2);
+
+bool findFirst(std::string &str1, std::string str2);
+
+bool findCutLast(std::string &str1, std::string str2);
+
+bool findCutFirst(std::string &str1, std::string str2);
+
+std::string &removeProtocol(std::string &url);
+
#endif // UTILS_STRINGUTILS_H