diff options
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/stringutils.cpp | 54 | ||||
-rw-r--r-- | src/utils/stringutils.h | 8 |
2 files changed, 62 insertions, 0 deletions
diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp index 0243c4315..317d88f2d 100644 --- a/src/utils/stringutils.cpp +++ b/src/utils/stringutils.cpp @@ -524,3 +524,57 @@ 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; +} diff --git a/src/utils/stringutils.h b/src/utils/stringutils.h index 4fe6369e9..25e038a89 100644 --- a/src/utils/stringutils.h +++ b/src/utils/stringutils.h @@ -193,4 +193,12 @@ 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); + #endif // UTILS_STRINGUTILS_H |