summaryrefslogtreecommitdiff
path: root/src/utils/stringutils.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-07-01 12:17:24 +0300
committerAndrei Karas <akaras@inbox.ru>2013-07-01 12:17:24 +0300
commitf8871c5bd2131b9fb9ee54575767b8262394ac06 (patch)
treedc71525fcf18113758427851d42f68b01d66ce7e /src/utils/stringutils.cpp
parent4d580a22e13f003e8835adba54c78bab1a2a3f5a (diff)
downloadplus-f8871c5bd2131b9fb9ee54575767b8262394ac06.tar.gz
plus-f8871c5bd2131b9fb9ee54575767b8262394ac06.tar.bz2
plus-f8871c5bd2131b9fb9ee54575767b8262394ac06.tar.xz
plus-f8871c5bd2131b9fb9ee54575767b8262394ac06.zip
improve size() usage in stringutils.
Diffstat (limited to 'src/utils/stringutils.cpp')
-rw-r--r--src/utils/stringutils.cpp16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp
index 69474bd93..da3f8dd06 100644
--- a/src/utils/stringutils.cpp
+++ b/src/utils/stringutils.cpp
@@ -338,10 +338,12 @@ std::string& replaceAll(std::string& context, const std::string& from,
return context;
size_t lookHere = 0;
size_t foundHere;
+ const size_t fromSize = from.size();
+ const size_t toSize = to.size();
while ((foundHere = context.find(from, lookHere)) != std::string::npos)
{
- context.replace(foundHere, from.size(), to);
- lookHere = foundHere + to.size();
+ context.replace(foundHere, fromSize, to);
+ lookHere = foundHere + toSize;
}
return context;
}
@@ -545,8 +547,9 @@ std::string packList(const std::list<std::string> &list)
str.append(*i).append("|");
++ i;
}
- if (str.size() > 1)
- str = str.substr(0, str.size() - 1);
+ const size_t sz = str.size();
+ if (sz > 1)
+ str = str.substr(0, sz - 1);
return str;
}
@@ -641,9 +644,10 @@ std::string &removeProtocol(std::string &url)
bool strStartWith(const std::string &str1, const std::string &str2)
{
- if (str1.size() < str2.size())
+ const size_t sz2 = str2.size();
+ if (str1.size() < sz2)
return false;
- return str1.substr(0, str2.size()) == str2;
+ return str1.substr(0, sz2) == str2;
}
std::string getDateString()