From cd24ed1c6c5aab358b4f18d262bd4c00c0ebfe96 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sun, 16 Sep 2012 19:28:16 +0300 Subject: Add const to variables with type size_t. --- src/gui/chatwindow.cpp | 15 +++++++-------- src/gui/helpwindow.cpp | 2 +- src/gui/shopwindow.cpp | 2 +- src/gui/whoisonline.cpp | 11 ++++------- src/gui/widgets/browserbox.cpp | 6 +++--- src/gui/widgets/chattab.cpp | 4 ++-- src/gui/widgets/textbox.cpp | 3 +-- src/gui/widgets/whispertab.cpp | 8 ++++---- 8 files changed, 23 insertions(+), 28 deletions(-) (limited to 'src/gui') diff --git a/src/gui/chatwindow.cpp b/src/gui/chatwindow.cpp index 9ea0bb383..fdc6169ed 100644 --- a/src/gui/chatwindow.cpp +++ b/src/gui/chatwindow.cpp @@ -1055,7 +1055,7 @@ void ChatWindow::addWhisper(const std::string &nick, { std::string msg = mes; std::string nick2; - size_t idx = mes.find(":"); + const size_t idx = mes.find(":"); if (idx != std::string::npos && idx > 0) { nick2 = msg.substr(0, idx); @@ -1298,7 +1298,7 @@ std::string ChatWindow::autoComplete(StringVect &names, std::string name = *i; toLower(name); - size_t pos = name.find(partName, 0); + const size_t pos = name.find(partName, 0); if (pos == 0) { if (newName != "") @@ -1330,8 +1330,7 @@ std::string ChatWindow::autoComplete(std::string partName, while (i != i_end) { std::string line = *i; - size_t pos = line.find(partName, 0); - if (pos == 0) + if (line.find(partName, 0) == 0) nameList.push_back(line); ++i; } @@ -1388,7 +1387,7 @@ void ChatWindow::resortChatLog(std::string line, Own own, return; } - size_t idx = line.find(": \302\202"); + const size_t idx = line.find(": \302\202"); if (idx != std::string::npos) { line = line.erase(idx + 2, 2); @@ -1396,13 +1395,13 @@ void ChatWindow::resortChatLog(std::string line, Own own, return; } - size_t idx1 = line.find("@@"); + const size_t idx1 = line.find("@@"); if (idx1 != std::string::npos) { - size_t idx2 = line.find("|", idx1); + const size_t idx2 = line.find("|", idx1); if (idx2 != std::string::npos) { - size_t idx3 = line.find("@@", idx2); + const size_t idx3 = line.find("@@", idx2); if (idx3 != std::string::npos) { if (line.find("http", idx1) != idx1 + 2) diff --git a/src/gui/helpwindow.cpp b/src/gui/helpwindow.cpp index 61bd54c8c..6dbb6ec09 100644 --- a/src/gui/helpwindow.cpp +++ b/src/gui/helpwindow.cpp @@ -136,7 +136,7 @@ void HelpWindow::loadTags() it != it_end; ++ it) { const std::string &str = *it; - size_t idx = str.find('|'); + const size_t idx = str.find('|'); if (idx != std::string::npos) mTagFileMap[str.substr(idx + 1)].insert(str.substr(0, idx)); } diff --git a/src/gui/shopwindow.cpp b/src/gui/shopwindow.cpp index 386652a93..016ad2d26 100644 --- a/src/gui/shopwindow.cpp +++ b/src/gui/shopwindow.cpp @@ -693,7 +693,7 @@ void ShopWindow::processRequest(std::string nick, std::string data, if (!inv) return; - size_t idx = data.find(" "); + const size_t idx = data.find(" "); if (idx == std::string::npos) return; diff --git a/src/gui/whoisonline.cpp b/src/gui/whoisonline.cpp index 0747b4276..747691ad3 100644 --- a/src/gui/whoisonline.cpp +++ b/src/gui/whoisonline.cpp @@ -241,7 +241,7 @@ void WhoIsOnline::updateWindow(std::vector &friends, void WhoIsOnline::loadList(std::vector &list) { mBrowserBox->clearRows(); - size_t numOnline = list.size(); + const size_t numOnline = list.size(); std::vector friends; std::vector neutral; std::vector disregard; @@ -353,13 +353,10 @@ void WhoIsOnline::loadWebList() trim(lineStr); if (listStarted == true) { - size_t found; - found = lineStr.find(" users are online."); - if (found == std::string::npos) + if (lineStr.find(" users are online.") == std::string::npos) { int level = 0; - size_t pos = 0; if (lineStr.length() > 24) { nick = lineStr.substr(0, 24); @@ -373,7 +370,7 @@ void WhoIsOnline::loadWebList() trim(nick); bool isGM(false); - pos = lineStr.find(gmText, 0); + size_t pos = lineStr.find(gmText, 0); if (pos != std::string::npos) { lineStr = lineStr.substr(pos + gmText.length()); @@ -477,7 +474,7 @@ size_t WhoIsOnline::memoryWrite(void *ptr, size_t size, return 0; WhoIsOnline *wio = reinterpret_cast(stream); - size_t totalMem = size * nmemb; + const size_t totalMem = size * nmemb; wio->mMemoryBuffer = static_cast(realloc(wio->mMemoryBuffer, wio->mDownloadedBytes + totalMem)); if (wio->mMemoryBuffer) diff --git a/src/gui/widgets/browserbox.cpp b/src/gui/widgets/browserbox.cpp index c657d1e0e..18a9df3e2 100644 --- a/src/gui/widgets/browserbox.cpp +++ b/src/gui/widgets/browserbox.cpp @@ -121,8 +121,8 @@ void BrowserBox::addRow(const std::string &row, const bool atTop) const int sz = static_cast(mTextRows.size()); while (idx1 != std::string::npos) { - size_t idx2 = tmp.find("|", idx1); - size_t idx3 = tmp.find("@@", idx2); + const size_t idx2 = tmp.find("|", idx1); + const size_t idx3 = tmp.find("@@", idx2); if (idx2 == std::string::npos || idx3 == std::string::npos) break; @@ -560,7 +560,7 @@ int BrowserBox::calcHeight() } } - size_t len = (end == std::string::npos) ? end : end - start; + const size_t len = (end == std::string::npos) ? end : end - start; if (start >= row.length()) break; diff --git a/src/gui/widgets/chattab.cpp b/src/gui/widgets/chattab.cpp index a78d1f636..d71f7f640 100644 --- a/src/gui/widgets/chattab.cpp +++ b/src/gui/widgets/chattab.cpp @@ -114,7 +114,7 @@ void ChatTab::chatLog(std::string line, Own own, tmp.nick = ""; tmp.text = line; - size_t pos = line.find(" : "); + const size_t pos = line.find(" : "); if (pos != std::string::npos) { if (line.length() <= pos + 3) @@ -345,7 +345,7 @@ void ChatTab::chatInput(const std::string &message) while (start + 1 < msg.size() && start != std::string::npos && msg[start + 1] != '@') { - size_t end = msg.find(']', start); + const size_t end = msg.find(']', start); if (start + 1 != end && end != std::string::npos) { // Catch multiple embeds and ignore them diff --git a/src/gui/widgets/textbox.cpp b/src/gui/widgets/textbox.cpp index 541308e5e..3254f9f28 100644 --- a/src/gui/widgets/textbox.cpp +++ b/src/gui/widgets/textbox.cpp @@ -52,13 +52,12 @@ void TextBox::setTextWrapped(const std::string &text, const int minDimension) mMinWidth = minDimension; std::stringstream wrappedStream; - size_t spacePos; size_t newlinePos; size_t lastNewlinePos = 0; int minWidth = 0; int xpos; - spacePos = text.rfind(" ", text.size()); + size_t spacePos = text.rfind(" ", text.size()); if (spacePos != std::string::npos) { diff --git a/src/gui/widgets/whispertab.cpp b/src/gui/widgets/whispertab.cpp index cc4db6a87..2126f3c7b 100644 --- a/src/gui/widgets/whispertab.cpp +++ b/src/gui/widgets/whispertab.cpp @@ -80,10 +80,10 @@ void WhisperTab::handleCommand(const std::string &msg) return; } - size_t pos = msg.find(' '); - std::string type(msg, 0, pos); - std::string args(msg, pos == std::string::npos - ? msg.size() : pos + 1); + const size_t pos = msg.find(' '); + const std::string type(msg, 0, pos); + const std::string args(msg, pos == std::string::npos + ? msg.size() : pos + 1); if (type == "me") { -- cgit v1.2.3-70-g09d2