summaryrefslogtreecommitdiff
path: root/src/utils/stringutils.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2017-02-27 23:42:54 +0300
committerAndrei Karas <akaras@inbox.ru>2017-02-27 23:42:54 +0300
commiteb5128aa6ce4a33aa9021b51231d0934294c7caa (patch)
tree26db4336d595812e0fdcedf18e97ccc3c091b4ab /src/utils/stringutils.cpp
parent555be6547d24f09e5c2a901673237276fa4ae0bd (diff)
downloadmanaverse-eb5128aa6ce4a33aa9021b51231d0934294c7caa.tar.gz
manaverse-eb5128aa6ce4a33aa9021b51231d0934294c7caa.tar.bz2
manaverse-eb5128aa6ce4a33aa9021b51231d0934294c7caa.tar.xz
manaverse-eb5128aa6ce4a33aa9021b51231d0934294c7caa.zip
Add string function for sanitization strings.
Diffstat (limited to 'src/utils/stringutils.cpp')
-rw-r--r--src/utils/stringutils.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp
index bb7f7efb5..28b2c8e1e 100644
--- a/src/utils/stringutils.cpp
+++ b/src/utils/stringutils.cpp
@@ -385,6 +385,20 @@ std::string& replaceAll(std::string& context,
return context;
}
+void replaceRecursiveAll(std::string& context,
+ const std::string &restrict from,
+ const char to)
+{
+ size_t lookHere = 0;
+ size_t foundHere;
+ const size_t fromSize = from.size();
+ while ((foundHere = context.find(from, lookHere)) != std::string::npos)
+ {
+ context.replace(foundHere, fromSize, 1, to);
+ lookHere = foundHere;
+ }
+}
+
bool getBoolFromString(const std::string &text)
{
std::string txt = text;
@@ -1015,6 +1029,21 @@ std::string escapeString(std::string str)
return "\"" + str + "\"";
}
+void sanitizePath(std::string &path)
+{
+#ifdef WIN32
+ const char sepStr = '\\';
+ const std::string sep2Str = "\\\\";
+ const std::string sepWrongStr = "/";
+#else
+ const char sepStr = '/';
+ const std::string sep2Str = "//";
+ const std::string sepWrongStr = "\\";
+#endif
+ replaceRecursiveAll(path, sepWrongStr, sepStr);
+ replaceRecursiveAll(path, sep2Str, sepStr);
+}
+
#ifndef DYECMD
void replaceItemLinks(std::string &msg)
{