diff options
author | Andrei Karas <akaras@inbox.ru> | 2019-03-07 02:11:23 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2019-03-07 04:43:13 +0300 |
commit | 6b7551264a65f4e9d330a79a9a917a3febd2de44 (patch) | |
tree | ee2a50dbb4c61a2438b285cf6970a50fc811b911 /src/utils | |
parent | d459087cfef054b9172836dde6c2f433d2aecbc7 (diff) | |
download | manaverse-6b7551264a65f4e9d330a79a9a917a3febd2de44.tar.gz manaverse-6b7551264a65f4e9d330a79a9a917a3febd2de44.tar.bz2 manaverse-6b7551264a65f4e9d330a79a9a917a3febd2de44.tar.xz manaverse-6b7551264a65f4e9d330a79a9a917a3febd2de44.zip |
Add function for find first right separator
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/stringutils.cpp | 31 | ||||
-rw-r--r-- | src/utils/stringutils.h | 2 |
2 files changed, 33 insertions, 0 deletions
diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp index 45be9ef9c..3af63f96e 100644 --- a/src/utils/stringutils.cpp +++ b/src/utils/stringutils.cpp @@ -1157,6 +1157,37 @@ std::string urlJoin(std::string str1, } } +size_t rfindSepatator(const std::string &str1) +{ + const size_t idx1 = str1.rfind('/'); + const size_t idx2 = str1.rfind('\\'); + if (idx1 != std::string::npos) + { // idx1 + if (idx2 != std::string::npos) + { // idx1, idx2 + if (idx1 >= idx2) + return idx1; + else + return idx2; + } + else + { // idx1, not idx2 + return idx1; + } + } + else + { // not idx1 + if (idx2 != std::string::npos) + { // not idx1, idx2 + return idx2; + } + else + { // not idx1, not idx2 + return std::string::npos; + } + } +} + #ifndef DYECMD void replaceItemLinks(std::string &msg) { diff --git a/src/utils/stringutils.h b/src/utils/stringutils.h index bb5b370a8..8cd714dd3 100644 --- a/src/utils/stringutils.h +++ b/src/utils/stringutils.h @@ -293,4 +293,6 @@ std::string pathJoin(std::string str1, std::string urlJoin(std::string str1, const std::string &str2); +size_t rfindSepatator(const std::string &str1); + #endif // UTILS_STRINGUTILS_H |