From 6b7551264a65f4e9d330a79a9a917a3febd2de44 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Thu, 7 Mar 2019 02:11:23 +0300 Subject: Add function for find first right separator --- src/utils/stringutils.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'src/utils/stringutils.cpp') 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) { -- cgit v1.2.3-70-g09d2