summaryrefslogtreecommitdiff
path: root/src/utils/stringutils.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils/stringutils.cpp')
-rw-r--r--src/utils/stringutils.cpp99
1 files changed, 99 insertions, 0 deletions
diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp
index 28b2c8e1e..3663cc007 100644
--- a/src/utils/stringutils.cpp
+++ b/src/utils/stringutils.cpp
@@ -1044,6 +1044,105 @@ void sanitizePath(std::string &path)
replaceRecursiveAll(path, sep2Str, sepStr);
}
+std::string pathJoin(std::string str1,
+ const std::string &str2)
+{
+#ifdef WIN32
+ const char sep = '\\';
+ std::string sepStr = "\\";
+#else
+ const char sep = '/';
+ std::string sepStr = "/";
+#endif
+
+ if (str1.empty())
+ {
+ if (str2[0] == sep)
+ return str2;
+ else
+ return sepStr.append(str2);
+ }
+ const size_t sz1 = str1.size();
+ if (str2.empty())
+ {
+ if (str1[sz1 - 1] == sep)
+ return str1;
+ else
+ return str1.append(sepStr);
+ }
+ if (str1[sz1 - 1] == sep)
+ {
+ if (str2[0] == sep)
+ return str1.append(str2.substr(1));
+ else
+ return str1.append(str2);
+ }
+ else
+ {
+ if (str2[0] == sep)
+ return str1.append(str2);
+ else
+ return str1.append(sepStr).append(str2);
+ }
+}
+
+std::string pathJoin(std::string str1,
+ const std::string &str2,
+ const std::string &str3)
+{
+#ifdef WIN32
+ const char sep = '\\';
+ std::string sepStr = "\\";
+#else
+ const char sep = '/';
+ std::string sepStr = "/";
+#endif
+
+ if (str1.empty())
+ {
+ return pathJoin(str2, str3);
+ }
+ size_t sz1 = str1.size();
+ if (str2.empty())
+ {
+ return pathJoin(str1, str3);
+ }
+ if (str3.empty())
+ {
+ return pathJoin(str1, str2);
+ }
+ if (str1[sz1 - 1] == sep)
+ {
+ if (str2[0] == sep)
+ str1.append(str2.substr(1));
+ else
+ str1.append(str2);
+ }
+ else
+ {
+ if (str2[0] == sep)
+ str1.append(str2);
+ else
+ str1.append(sepStr).append(str2);
+ }
+
+ sz1 = str1.size();
+ if (str1[sz1 - 1] == sep)
+ {
+ if (str3[0] == sep)
+ return str1.append(str3.substr(1));
+ else
+ return str1.append(str3);
+ }
+ else
+ {
+ if (str3[0] == sep)
+ return str1.append(str3);
+ else
+ return str1.append(sepStr).append(str3);
+ }
+}
+
#ifndef DYECMD
void replaceItemLinks(std::string &msg)
{