From a9d1aaa774b9e986b8ee3c6cb1e7baa1d9ba3ea5 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Fri, 9 Aug 2013 23:41:59 +0300 Subject: improve size() methods usage. --- src/gui/widgets/textbox.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/gui/widgets/textbox.cpp') diff --git a/src/gui/widgets/textbox.cpp b/src/gui/widgets/textbox.cpp index 4eccbe76c..660655033 100644 --- a/src/gui/widgets/textbox.cpp +++ b/src/gui/widgets/textbox.cpp @@ -89,13 +89,14 @@ void TextBox::setTextWrapped(const std::string &text, const int minDimension) xpos = 0; gcn::Font *const font = getFont(); const int spaceWidth = font->getWidth(" "); + size_t sz = line.size(); do { spacePos = line.find(" ", lastSpacePos); if (spacePos == std::string::npos) - spacePos = line.size(); + spacePos = sz; const std::string word = line.substr(lastSpacePos, spacePos - lastSpacePos); @@ -130,14 +131,13 @@ void TextBox::setTextWrapped(const std::string &text, const int minDimension) mMinWidth = minWidth; wrappedStream.clear(); wrappedStream.str(""); -// spacePos = 0; lastNewlinePos = 0; newlinePos = text.find("\n", lastNewlinePos); if (newlinePos == std::string::npos) newlinePos = textSize; line = text.substr(lastNewlinePos, newlinePos - lastNewlinePos); -// width = 0; + sz = line.size(); break; } else @@ -148,14 +148,14 @@ void TextBox::setTextWrapped(const std::string &text, const int minDimension) } lastSpacePos = spacePos + 1; } - while (spacePos != line.size()); + while (spacePos != sz); if (text.find("\n", lastNewlinePos) != std::string::npos) wrappedStream << "\n"; lastNewlinePos = newlinePos + 1; } - while (newlinePos != text.size()); + while (newlinePos != textSize); if (xpos > minWidth) minWidth = xpos; -- cgit v1.2.3-60-g2f50