diff options
author | Andrei Karas <akaras@inbox.ru> | 2013-08-09 23:41:59 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2013-08-09 23:41:59 +0300 |
commit | a9d1aaa774b9e986b8ee3c6cb1e7baa1d9ba3ea5 (patch) | |
tree | 20a5024ce03d3b0abedd76378c534f4150af0ee9 /src/utils | |
parent | d0ccffd7db79f5dbff6f2cb4f8b77a8bb3435e57 (diff) | |
download | manaverse-a9d1aaa774b9e986b8ee3c6cb1e7baa1d9ba3ea5.tar.gz manaverse-a9d1aaa774b9e986b8ee3c6cb1e7baa1d9ba3ea5.tar.bz2 manaverse-a9d1aaa774b9e986b8ee3c6cb1e7baa1d9ba3ea5.tar.xz manaverse-a9d1aaa774b9e986b8ee3c6cb1e7baa1d9ba3ea5.zip |
improve size() methods usage.
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/stringutils.cpp | 27 | ||||
-rw-r--r-- | src/utils/translation/poparser.cpp | 14 |
2 files changed, 27 insertions, 14 deletions
diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp index a54d9d5ab..09cd41fc2 100644 --- a/src/utils/stringutils.cpp +++ b/src/utils/stringutils.cpp @@ -286,20 +286,30 @@ std::string removeSpriteIndex(std::string str) const char* getSafeUtf8String(std::string text) { - const int size = static_cast<int>(text.size()) + UTF8_MAX_SIZE; + const size_t sz = text.size(); + const size_t size = sz + UTF8_MAX_SIZE; char *const buf = new char[size]; - memcpy(buf, text.c_str(), text.size()); - memset(buf + text.size(), 0, UTF8_MAX_SIZE); + memcpy(buf, text.c_str(), sz); + memset(buf + sz, 0, UTF8_MAX_SIZE); return buf; } void getSafeUtf8String(std::string text, char *const buf) { - const int size = static_cast<int>(text.size()) + UTF8_MAX_SIZE; + const size_t sz = text.size(); + const size_t size = sz + UTF8_MAX_SIZE; if (size > 65500) + { text = text.substr(0, 65500); - memcpy(buf, text.c_str(), text.size()); - memset(buf + text.size(), 0, UTF8_MAX_SIZE); + const size_t sz1 = text.size(); + memcpy(buf, text.c_str(), sz1); + memset(buf + sz1, 0, UTF8_MAX_SIZE); + } + else + { + memcpy(buf, text.c_str(), sz); + memset(buf + sz, 0, UTF8_MAX_SIZE); + } return; } @@ -366,11 +376,12 @@ void replaceSpecialChars(std::string &text) while (pos1 != std::string::npos) { const size_t idx = pos1 + 1; - if (idx >= text.size()) + const size_t sz = text.size(); + if (idx >= sz) break; size_t f; - for (f = idx; f < text.size(); f ++) + for (f = idx; f < sz; f ++) { if (text[f] < '0' || text[f] > '9') break; diff --git a/src/utils/translation/poparser.cpp b/src/utils/translation/poparser.cpp index e6c41580c..55d4e01e2 100644 --- a/src/utils/translation/poparser.cpp +++ b/src/utils/translation/poparser.cpp @@ -161,9 +161,10 @@ bool PoParser::readMsgId() if (strStartWith(mLine, msgId1)) { mReadingId = true; + const size_t msgId1Size = msgId1.size(); // reading text from: msgid "text" - mMsgId.append(mLine.substr(msgId1.size(), - mLine.size() - 1 - msgId1.size())); + mMsgId.append(mLine.substr(msgId1Size, + mLine.size() - 1 - msgId1Size)); mLine.clear(); return true; } @@ -201,9 +202,10 @@ bool PoParser::readMsgStr() if (strStartWith(mLine, msgStr1)) { mReadingStr = true; + const size_t msgStr1Size = msgStr1.size(); // reading text from: msgid "text" - mMsgStr.append(mLine.substr(msgStr1.size(), - mLine.size() - 1 - msgStr1.size())); + mMsgStr.append(mLine.substr(msgStr1Size, + mLine.size() - 1 - msgStr1Size)); mLine.clear(); return true; } @@ -215,9 +217,9 @@ bool PoParser::readMsgStr() bool PoParser::checkLine() { + const size_t sz = mLine.size(); // check is line in format: "text" - return mLine.size() > 2 && mLine[0] == '\"' - && mLine[mLine.size() - 1] == '\"'; + return sz > 2 && mLine[0] == '\"' && mLine[sz - 1] == '\"'; } PoDict *PoParser::getEmptyDict() |