summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-02-12 01:23:09 +0300
committerAndrei Karas <akaras@inbox.ru>2012-02-12 01:23:09 +0300
commit541bd299d521666d7d02b4f36b75f31dd8a2d64f (patch)
tree0d25d0af90cbe5b8698ad2f3c4a4610c9d4b0d75 /src
parentbb156df11431e3eb286ddd3311adf1ac710945e0 (diff)
downloadplus-541bd299d521666d7d02b4f36b75f31dd8a2d64f.tar.gz
plus-541bd299d521666d7d02b4f36b75f31dd8a2d64f.tar.bz2
plus-541bd299d521666d7d02b4f36b75f31dd8a2d64f.tar.xz
plus-541bd299d521666d7d02b4f36b75f31dd8a2d64f.zip
Fix some possible errors in string untils.
Diffstat (limited to 'src')
-rw-r--r--src/utils/stringutils.cpp34
-rw-r--r--src/utils/stringutils.h2
2 files changed, 24 insertions, 12 deletions
diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp
index 798690602..9184ba79d 100644
--- a/src/utils/stringutils.cpp
+++ b/src/utils/stringutils.cpp
@@ -105,6 +105,7 @@ std::string strprintf(char const *format, ...)
return res;
}
+/*
std::string &removeBadChars(std::string &str)
{
std::string::size_type pos;
@@ -118,6 +119,7 @@ std::string &removeBadChars(std::string &str)
return str;
}
+*/
std::string removeColors(std::string msg)
{
@@ -316,27 +318,37 @@ void getSafeUtf8String(std::string text, char *buf)
std::string getFileName(std::string path)
{
- size_t pos = path.rfind("/");
- if (pos == std::string::npos)
- pos = path.rfind("\\");
- if (pos == std::string::npos)
+ size_t pos1 = path.rfind("/");
+ size_t pos2 = path.rfind("\\");
+ if (pos1 == std::string::npos)
+ pos1 = pos2;
+ else if (pos2 != std::string::npos && pos2 > pos1)
+ pos1 = pos2;
+
+ if (pos1 == std::string::npos)
return path;
- return path.substr(pos + 1);
+ return path.substr(pos1 + 1);
}
std::string getFileDir(std::string path)
{
- size_t pos = path.rfind("/");
- if (pos == std::string::npos)
- pos = path.rfind("\\");
- if (pos == std::string::npos)
- return "";
- return path.substr(0, pos);
+ size_t pos1 = path.rfind("/");
+ size_t pos2 = path.rfind("\\");
+ if (pos1 == std::string::npos)
+ pos1 = pos2;
+ else if (pos2 != std::string::npos && pos2 > pos1)
+ pos1 = pos2;
+
+ if (pos1 == std::string::npos)
+ return path;
+ return path.substr(0, pos1);
}
std::string& replaceAll(std::string& context, const std::string& from,
const std::string& to)
{
+ if (from.empty())
+ return context;
size_t lookHere = 0;
size_t foundHere;
while ((foundHere = context.find(from, lookHere)) != std::string::npos)
diff --git a/src/utils/stringutils.h b/src/utils/stringutils.h
index 398737179..47d495dd0 100644
--- a/src/utils/stringutils.h
+++ b/src/utils/stringutils.h
@@ -103,7 +103,7 @@ std::string strprintf(char const *, ...)
* @param str the string to remove the bad chars from
* @return a reference to the string without bad chars
*/
-std::string &removeBadChars(std::string &str);
+//std::string &removeBadChars(std::string &str);
/**
* Removes colors from a string