summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2016-02-08 23:02:06 +0300
committerAndrei Karas <akaras@inbox.ru>2016-02-08 23:02:06 +0300
commit7e66a4606bb15d98197f71245fe191d03152ee5f (patch)
tree825022571cfb55d70f1ca3c142f79db3758fb72b /src
parenta61ac4664d55cddb18d2d861e76629bd07676129 (diff)
downloadmv-7e66a4606bb15d98197f71245fe191d03152ee5f.tar.gz
mv-7e66a4606bb15d98197f71245fe191d03152ee5f.tar.bz2
mv-7e66a4606bb15d98197f71245fe191d03152ee5f.tar.xz
mv-7e66a4606bb15d98197f71245fe191d03152ee5f.zip
Improve some empty string checks.
Diffstat (limited to 'src')
-rw-r--r--src/actormanager.cpp10
-rw-r--r--src/being/being.cpp4
-rw-r--r--src/chatlogger.cpp4
-rw-r--r--src/configuration.cpp2
-rw-r--r--src/gui/theme.cpp2
-rw-r--r--src/gui/widgets/popup.cpp2
-rw-r--r--src/gui/widgets/radiobutton.cpp2
-rw-r--r--src/gui/widgets/scrollarea.cpp2
-rw-r--r--src/gui/widgets/window.cpp2
-rw-r--r--src/gui/windowmenu.cpp2
-rw-r--r--src/gui/windows/chatwindow.cpp4
-rw-r--r--src/gui/windows/logindialog.cpp5
-rw-r--r--src/gui/windows/ministatuswindow.cpp2
-rw-r--r--src/gui/windows/npcdialog.cpp4
-rw-r--r--src/gui/windows/updaterwindow.cpp2
-rw-r--r--src/net/download.cpp2
-rw-r--r--src/net/eathena/chathandler.cpp4
-rw-r--r--src/net/tmwa/chathandler.cpp4
-rw-r--r--src/resources/db/itemdb.cpp18
-rw-r--r--src/spellmanager.cpp7
20 files changed, 46 insertions, 38 deletions
diff --git a/src/actormanager.cpp b/src/actormanager.cpp
index c41f97c71..6b27e3205 100644
--- a/src/actormanager.cpp
+++ b/src/actormanager.cpp
@@ -1587,7 +1587,7 @@ void ActorManager::getPlayerNames(StringVect &names,
if ((being->getType() == ActorType::Player ||
(being->getType() == ActorType::Npc &&
npcNames == NpcNames_true)) &&
- being->getName() != "")
+ !being->getName().empty())
{
names.push_back(being->getName());
}
@@ -1610,7 +1610,7 @@ void ActorManager::getMobNames(StringVect &names) const
}
const Being *const being = static_cast<const Being*>(*it);
- if (being->getType() == ActorType::Monster && being->getName() != "")
+ if (being->getType() == ActorType::Monster && !being->getName().empty())
names.push_back(being->getName());
}
}
@@ -1630,7 +1630,7 @@ void ActorManager::updatePlayerNames() const
Being *const being = static_cast<Being*>(*it);
being->setGoodStatus(-1);
- if (being->getType() == ActorType::Player && being->getName() != "")
+ if (being->getType() == ActorType::Player && !being->getName().empty())
being->updateName();
}
}
@@ -1649,7 +1649,7 @@ void ActorManager::updatePlayerColors() const
}
Being *const being = static_cast<Being*>(*it);
- if (being->getType() == ActorType::Player && being->getName() != "")
+ if (being->getType() == ActorType::Player && !being->getName().empty())
being->updateColors();
}
}
@@ -1668,7 +1668,7 @@ void ActorManager::updatePlayerGuild() const
}
Being *const being = static_cast<Being*>(*it);
- if (being->getType() == ActorType::Player && being->getName() != "")
+ if (being->getType() == ActorType::Player && !being->getName().empty())
being->updateGuild();
}
}
diff --git a/src/being/being.cpp b/src/being/being.cpp
index 6aedf790e..3edd7c70f 100644
--- a/src/being/being.cpp
+++ b/src/being/being.cpp
@@ -792,7 +792,9 @@ void Being::takeDamage(Being *restrict const attacker,
updatePercentHP();
updateName();
}
- else if (mType == ActorType::Player && socialWindow && getName() != "")
+ else if (mType == ActorType::Player &&
+ socialWindow &&
+ !getName().empty())
{
socialWindow->updateAvatar(getName());
}
diff --git a/src/chatlogger.cpp b/src/chatlogger.cpp
index 9e3329f9a..4f8b1ed54 100644
--- a/src/chatlogger.cpp
+++ b/src/chatlogger.cpp
@@ -174,14 +174,14 @@ void ChatLogger::writeTo(std::ofstream &file,
void ChatLogger::setServerName(const std::string &serverName)
{
mServerName = serverName;
- if (mServerName == "")
+ if (mServerName.empty())
mServerName = config.getStringValue("MostUsedServerName0");
if (mLogFile.is_open())
mLogFile.close();
secureName(mServerName);
- if (mLogDir != "")
+ if (!mLogDir.empty())
{
const char *const name = (std::string(mLogDir).append(dirSeparator)
.append(mServerName)).c_str();
diff --git a/src/configuration.cpp b/src/configuration.cpp
index f70af1c3e..29d26f495 100644
--- a/src/configuration.cpp
+++ b/src/configuration.cpp
@@ -925,7 +925,7 @@ void Configuration::removeOldKeys()
mOptions.find(unusedKeys[2]) != mOptions.end())
{
int f = 0;
- while (unusedKeys[f] != "")
+ while (!unusedKeys[f].empty())
{
deleteKey(unusedKeys[f]);
logger->log("remove unused key: " + unusedKeys[f]);
diff --git a/src/gui/theme.cpp b/src/gui/theme.cpp
index 20ec774dc..f36a45579 100644
--- a/src/gui/theme.cpp
+++ b/src/gui/theme.cpp
@@ -983,7 +983,7 @@ static int readProgressType(const std::string &type)
void Theme::loadColors(std::string file)
{
- if (file == "")
+ if (file.empty())
file = "colors.xml";
else
file.append("/colors.xml");
diff --git a/src/gui/widgets/popup.cpp b/src/gui/widgets/popup.cpp
index 2c707b295..bd94236b9 100644
--- a/src/gui/widgets/popup.cpp
+++ b/src/gui/widgets/popup.cpp
@@ -55,7 +55,7 @@ Popup::Popup(const std::string &name,
addWidgetListener(this);
- if (skin == "")
+ if (skin.empty())
skin = "popup.xml";
if (theme)
diff --git a/src/gui/widgets/radiobutton.cpp b/src/gui/widgets/radiobutton.cpp
index 0f67bc54b..89b9b2341 100644
--- a/src/gui/widgets/radiobutton.cpp
+++ b/src/gui/widgets/radiobutton.cpp
@@ -315,7 +315,7 @@ void RadioButton::mouseDragged(MouseEvent& event)
void RadioButton::setGroup(const std::string &group)
{
- if (mGroup != "")
+ if (!mGroup.empty())
{
for (GroupIterator iter = mGroupMap.lower_bound(mGroup),
iterEnd = mGroupMap.upper_bound(mGroup);
diff --git a/src/gui/widgets/scrollarea.cpp b/src/gui/widgets/scrollarea.cpp
index 5bf67bfda..d515f3c66 100644
--- a/src/gui/widgets/scrollarea.cpp
+++ b/src/gui/widgets/scrollarea.cpp
@@ -195,7 +195,7 @@ void ScrollArea::init(std::string skinName)
}
// +++ here probably need move background from static
- if (skinName == "")
+ if (skinName.empty())
skinName = "scroll_background.xml";
if (theme)
{
diff --git a/src/gui/widgets/window.cpp b/src/gui/widgets/window.cpp
index 450c2e025..886372035 100644
--- a/src/gui/widgets/window.cpp
+++ b/src/gui/widgets/window.cpp
@@ -174,7 +174,7 @@ Window::Window(const std::string &caption,
setPadding(3);
setTitleBarHeight(20);
- if (skin == "")
+ if (skin.empty())
skin = "window.xml";
int childPalette = 1;
diff --git a/src/gui/windowmenu.cpp b/src/gui/windowmenu.cpp
index 6633fcb90..ec51062eb 100644
--- a/src/gui/windowmenu.cpp
+++ b/src/gui/windowmenu.cpp
@@ -378,7 +378,7 @@ void WindowMenu::loadButtons()
{
if (!mSmallWindow)
{
- if (config.getValue("windowmenu0", "") == "")
+ if (config.getValue("windowmenu0", "").empty())
{
for (std::map <std::string, ButtonInfo*>::iterator
it = mButtonNames.begin(),
diff --git a/src/gui/windows/chatwindow.cpp b/src/gui/windows/chatwindow.cpp
index 1551c10ae..5be54a6f9 100644
--- a/src/gui/windows/chatwindow.cpp
+++ b/src/gui/windows/chatwindow.cpp
@@ -801,7 +801,7 @@ void ChatWindow::keyPressed(KeyEvent &event)
mChatInput->getText().length()));
}
else if (actionId == InputAction::GUI_INSERT &&
- mChatInput->getText() != "")
+ !mChatInput->getText().empty())
{
// Add the current message to the history and clear the text
if (mHistory.empty() || mChatInput->getText() != mHistory.back())
@@ -1505,7 +1505,7 @@ std::string ChatWindow::autoCompleteHistory(const std::string &partName) const
f++;
line = line.substr(0, f);
- if (line != "")
+ if (!line.empty())
nameList.push_back(line);
++i;
diff --git a/src/gui/windows/logindialog.cpp b/src/gui/windows/logindialog.cpp
index c39486dda..34f84fee4 100644
--- a/src/gui/windows/logindialog.cpp
+++ b/src/gui/windows/logindialog.cpp
@@ -125,8 +125,11 @@ LoginDialog::LoginDialog(LoginData &data,
}
mUpdateHostText->adjustSize();
- if (mPassField->getText().empty() && LoginDialog::savedPassword != "")
+ if (mPassField->getText().empty() &&
+ !LoginDialog::savedPassword.empty())
+ {
mPassField->setText(LoginDialog::savedPassword);
+ }
mUpdateTypeDropDown->setActionEventId("updatetype");
mUpdateTypeDropDown->setSelected((mLoginData->updateType
diff --git a/src/gui/windows/ministatuswindow.cpp b/src/gui/windows/ministatuswindow.cpp
index fc2e9a82c..e0fe46bb3 100644
--- a/src/gui/windows/ministatuswindow.cpp
+++ b/src/gui/windows/ministatuswindow.cpp
@@ -507,7 +507,7 @@ void MiniStatusWindow::loadBars()
{
const std::string str = config.getValue(
"ministatus" + toString(f), "");
- if (str == "")
+ if (str.empty())
continue;
ProgressBar *const bar = mBarNames[str];
if (!bar)
diff --git a/src/gui/windows/npcdialog.cpp b/src/gui/windows/npcdialog.cpp
index 27386af5b..452567b94 100644
--- a/src/gui/windows/npcdialog.cpp
+++ b/src/gui/windows/npcdialog.cpp
@@ -489,7 +489,7 @@ void NpcDialog::action(const ActionEvent &event)
const int sz = mComplexInventory->getSize();
if (sz == 0)
{
- str = "";
+ str.clear();
}
else
{
@@ -1385,7 +1385,7 @@ std::string NpcDialog::complexItemToStr(const ComplexItem *const item)
}
else
{
- str = "";
+ str.clear();
}
return str;
}
diff --git a/src/gui/windows/updaterwindow.cpp b/src/gui/windows/updaterwindow.cpp
index e6e97553a..09f529259 100644
--- a/src/gui/windows/updaterwindow.cpp
+++ b/src/gui/windows/updaterwindow.cpp
@@ -145,7 +145,7 @@ static std::vector<UpdateFile> loadTxtFile(const std::string &fileName)
thisFile.name = name;
thisFile.hash = hash;
thisFile.type = "data";
- thisFile.group = "";
+ thisFile.group.clear();
thisFile.required = true;
thisFile.desc.clear();
diff --git a/src/net/download.cpp b/src/net/download.cpp
index 209b6085e..9e22745d4 100644
--- a/src/net/download.cpp
+++ b/src/net/download.cpp
@@ -272,7 +272,7 @@ int Download::downloadThread(void *ptr)
if (!d->mOptions.memoryWrite)
outFilename = d->mFileName + ".part";
else
- outFilename = "";
+ outFilename.clear();
}
while (!d->mUrlQueue.empty())
diff --git a/src/net/eathena/chathandler.cpp b/src/net/eathena/chathandler.cpp
index 353a82b0e..6efbb7864 100644
--- a/src/net/eathena/chathandler.cpp
+++ b/src/net/eathena/chathandler.cpp
@@ -99,7 +99,7 @@ void ChatHandler::sendRaw(const std::string &args) const
std::string str;
MessageOut *outMsg = nullptr;
- if (line == "")
+ if (line.empty())
return;
size_t pos = line.find(" ");
@@ -129,7 +129,7 @@ void ChatHandler::sendRaw(const std::string &args) const
line = line.substr(pos + 1);
pos = line.find(" ");
}
- if (line != "")
+ if (!line.empty())
processRaw(*outMsg, line);
delete outMsg;
}
diff --git a/src/net/tmwa/chathandler.cpp b/src/net/tmwa/chathandler.cpp
index 61a8054ba..7d22102fc 100644
--- a/src/net/tmwa/chathandler.cpp
+++ b/src/net/tmwa/chathandler.cpp
@@ -100,7 +100,7 @@ void ChatHandler::sendRaw(const std::string &args) const
std::string str;
MessageOut *outMsg = nullptr;
- if (line == "")
+ if (line.empty())
return;
size_t pos = line.find(" ");
@@ -129,7 +129,7 @@ void ChatHandler::sendRaw(const std::string &args) const
line = line.substr(pos + 1);
pos = line.find(" ");
}
- if (line != "")
+ if (!line.empty())
processRaw(*outMsg, line);
delete outMsg;
}
diff --git a/src/resources/db/itemdb.cpp b/src/resources/db/itemdb.cpp
index ba5631293..d07301e88 100644
--- a/src/resources/db/itemdb.cpp
+++ b/src/resources/db/itemdb.cpp
@@ -357,7 +357,7 @@ void ItemDB::loadXmlFile(const std::string &fileName, int &tagNum)
SpriteDisplay display;
display.image = image;
- if (floor != "")
+ if (!floor.empty())
display.floor = floor;
else
display.floor = image;
@@ -447,7 +447,7 @@ void ItemDB::loadXmlFile(const std::string &fileName, int &tagNum)
}
for (int f = 0; f < 3; f++)
{
- if (tags[f] != "")
+ if (!tags[f].empty())
{
if (mTags.find(tags[f]) == mTags.end())
{
@@ -624,16 +624,18 @@ void ItemDB::loadXmlFile(const std::string &fileName, int &tagNum)
}
}
-#define CHECK_PARAM(param, error_value) \
- if (param == error_value) \
+#define CHECK_PARAM(param) \
+ if (param.empty()) \
+ { \
logger->log("ItemDB: Missing " #param " attribute for item %i!", \
- id)
+ id); \
+ }
if (id >= 0 && typeStr != "other")
{
- CHECK_PARAM(name, "");
- CHECK_PARAM(description, "");
- CHECK_PARAM(image, "");
+ CHECK_PARAM(name)
+ CHECK_PARAM(description)
+ CHECK_PARAM(image)
}
#undef CHECK_PARAM
}
diff --git a/src/spellmanager.cpp b/src/spellmanager.cpp
index 07ee344f7..e894ff6df 100644
--- a/src/spellmanager.cpp
+++ b/src/spellmanager.cpp
@@ -261,7 +261,7 @@ void SpellManager::load(const bool oldConfig)
mSpells.clear();
mSpellsVector.clear();
- if (cfg->getValue("commandShortcutFlags0", "") == "")
+ if (cfg->getValue("commandShortcutFlags0", "").empty())
{
fillSpells();
save();
@@ -315,7 +315,7 @@ void SpellManager::load(const bool oldConfig)
#define setOrDel(str, method) \
const std::string var##method = spell->method(); \
- if (var##method != "") \
+ if (!var##method.empty()) \
serverConfig.setValue(str + toString(i), var##method); \
else \
serverConfig.deleteKey(str + toString(i));
@@ -331,7 +331,8 @@ void SpellManager::save() const
setOrDel("commandShortcutComment", getComment);
setOrDel("commandShortcutSymbol", getSymbol);
setOrDel("commandShortcutIcon", getIcon);
- if (spell->getCommand() != "" && spell->getSymbol() != "")
+ if (!spell->getCommand().empty() &&
+ !spell->getSymbol().empty())
{
#ifdef TMWA_SUPPORT
serverConfig.setValue("commandShortcutFlags" + toString(i),