summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorYohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>2010-09-08 22:43:00 +0200
committerYohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>2010-09-08 22:43:00 +0200
commitd6d215e2ab53322c769792b4aa53396ecce96422 (patch)
treeca1f73f1156f7a3eeccf2430a00d7bcdbd39d149 /src
parentde803e103f5317856d4eadf15661ef7516cfc72a (diff)
downloadmanaserv-d6d215e2ab53322c769792b4aa53396ecce96422.tar.gz
manaserv-d6d215e2ab53322c769792b4aa53396ecce96422.tar.bz2
manaserv-d6d215e2ab53322c769792b4aa53396ecce96422.tar.xz
manaserv-d6d215e2ab53322c769792b4aa53396ecce96422.zip
Centralized stringToBool conversion.
Also moved the trim() function into the utils namespace where it belongs more, and made some random code cleanups. Reviewed-by: Thorbjorn.
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/Makefile.am1
-rw-r--r--src/account-server/accounthandler.cpp46
-rw-r--r--src/common/configuration.cpp15
-rw-r--r--src/common/configuration.hpp9
-rw-r--r--src/game-server/attributemanager.cpp39
-rw-r--r--src/game-server/mapreader.cpp27
-rw-r--r--src/game-server/mapreader.hpp4
-rw-r--r--src/game-server/skillmanager.cpp8
-rw-r--r--src/utils/string.cpp36
-rw-r--r--src/utils/string.hpp37
-rw-r--r--src/utils/trim.hpp50
-rw-r--r--src/utils/xml.cpp8
13 files changed, 161 insertions, 120 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 20840c04..d9e3920f 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -263,7 +263,6 @@ SET(SRCS_MANASERVGAME
utils/mathutils.cpp
utils/speedconv.hpp
utils/speedconv.cpp
- utils/trim.hpp
utils/zlib.hpp
utils/zlib.cpp
)
diff --git a/src/Makefile.am b/src/Makefile.am
index 19390cba..d6669808 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -192,7 +192,6 @@ manaserv_game_SOURCES = \
utils/stringfilter.cpp \
utils/timer.h \
utils/timer.cpp \
- utils/trim.hpp \
utils/tokencollector.hpp \
utils/tokencollector.cpp \
utils/tokendispenser.hpp \
diff --git a/src/account-server/accounthandler.cpp b/src/account-server/accounthandler.cpp
index 1342b36a..ce3635b6 100644
--- a/src/account-server/accounthandler.cpp
+++ b/src/account-server/accounthandler.cpp
@@ -50,7 +50,6 @@ static void addUpdateHost(MessageOut *msg)
msg->writeString(updateHost);
}
-
// List of attributes that the client can send at account creation.
static std::vector< int > initAttr;
@@ -163,7 +162,7 @@ AccountHandler::AccountHandler(const std::string &attrFile):
continue;
}
- if (utils::toupper(XML::getProperty(attributenode, "modifiable", "false")) == "TRUE")
+ if (XML::getBoolProperty(attributenode, "modifiable", false))
initAttr.push_back(id);
// Store as string initially to check
@@ -358,7 +357,7 @@ void AccountHandler::handleLoginMessage(AccountClient &client, MessageIn &msg)
return;
}
- // The client succesfully logged in
+ // The client successfully logged in
// set lastLogin date of the account
time_t login;
@@ -408,7 +407,8 @@ void AccountHandler::handleLogoutMessage(AccountClient &client)
client.send(reply);
}
-void AccountHandler::handleReconnectMessage(AccountClient &client, MessageIn &msg)
+void AccountHandler::handleReconnectMessage(AccountClient &client,
+ MessageIn &msg)
{
if (client.status != CLIENT_LOGIN)
{
@@ -428,14 +428,14 @@ bool checkCaptcha(AccountClient &client, std::string captcha)
return true;
}
-void AccountHandler::handleRegisterMessage(AccountClient &client, MessageIn &msg)
+void AccountHandler::handleRegisterMessage(AccountClient &client,
+ MessageIn &msg)
{
int clientVersion = msg.readLong();
std::string username = msg.readString();
std::string password = msg.readString();
std::string email = msg.readString();
std::string captcha = msg.readString();
- std::string allowed = Configuration::getValue("account_allowRegister", "1");
int minClientVersion = Configuration::getValue("clientVersion", 0);
unsigned minNameLength = Configuration::getValue("account_minNameLength", 4);
unsigned maxNameLength = Configuration::getValue("account_maxNameLength", 15);
@@ -446,7 +446,7 @@ void AccountHandler::handleRegisterMessage(AccountClient &client, MessageIn &msg
{
reply.writeByte(ERRMSG_FAILURE);
}
- else if (allowed == "0" or allowed == "false")
+ else if (!Configuration::getBoolValue("account_allowRegister", true))
{
reply.writeByte(ERRMSG_FAILURE);
}
@@ -523,7 +523,8 @@ void AccountHandler::handleRegisterMessage(AccountClient &client, MessageIn &msg
client.send(reply);
}
-void AccountHandler::handleUnregisterMessage(AccountClient &client, MessageIn &msg)
+void AccountHandler::handleUnregisterMessage(AccountClient &client,
+ MessageIn &msg)
{
LOG_DEBUG("AccountHandler::handleUnregisterMessage");
std::string username = msg.readString();
@@ -545,7 +546,7 @@ void AccountHandler::handleUnregisterMessage(AccountClient &client, MessageIn &m
return;
}
- // See if the account exists
+ // See whether the account exists
Account *acc = storage->getAccount(username);
if (!acc || acc->getPassword() != password)
@@ -565,17 +566,19 @@ void AccountHandler::handleUnregisterMessage(AccountClient &client, MessageIn &m
client.send(reply);
}
-void AccountHandler::handleRequestRegisterInfoMessage(AccountClient &client, MessageIn &msg)
+void AccountHandler::handleRequestRegisterInfoMessage(AccountClient &client,
+ MessageIn &msg)
{
LOG_INFO("AccountHandler::handleRequestRegisterInfoMessage");
MessageOut reply(APMSG_REGISTER_INFO_RESPONSE);
- std::string allowed = Configuration::getValue("account_allowRegister", "1");
- if (allowed == "0" or allowed == "false")
+ if (!Configuration::getBoolValue("account_allowRegister", true))
{
reply.writeByte(false);
reply.writeString(Configuration::getValue(
- "account_denyRegisterReason", ""));
- } else {
+ "account_denyRegisterReason", ""));
+ }
+ else
+ {
reply.writeByte(true);
reply.writeByte(Configuration::getValue("account_minNameLength", 4));
reply.writeByte(Configuration::getValue("account_maxNameLength", 16));
@@ -585,7 +588,8 @@ void AccountHandler::handleRequestRegisterInfoMessage(AccountClient &client, Mes
client.send(reply);
}
-void AccountHandler::handleEmailChangeMessage(AccountClient &client, MessageIn &msg)
+void AccountHandler::handleEmailChangeMessage(AccountClient &client,
+ MessageIn &msg)
{
MessageOut reply(APMSG_EMAIL_CHANGE_RESPONSE);
@@ -622,7 +626,8 @@ void AccountHandler::handleEmailChangeMessage(AccountClient &client, MessageIn &
client.send(reply);
}
-void AccountHandler::handlePasswordChangeMessage(AccountClient &client, MessageIn &msg)
+void AccountHandler::handlePasswordChangeMessage(AccountClient &client,
+ MessageIn &msg)
{
std::string oldPassword = sha256(msg.readString());
std::string newPassword = sha256(msg.readString());
@@ -653,7 +658,8 @@ void AccountHandler::handlePasswordChangeMessage(AccountClient &client, MessageI
client.send(reply);
}
-void AccountHandler::handleCharacterCreateMessage(AccountClient &client, MessageIn &msg)
+void AccountHandler::handleCharacterCreateMessage(AccountClient &client,
+ MessageIn &msg)
{
std::string name = msg.readString();
int hairStyle = msg.readByte();
@@ -795,7 +801,8 @@ void AccountHandler::handleCharacterCreateMessage(AccountClient &client, Message
client.send(reply);
}
-void AccountHandler::handleCharacterSelectMessage(AccountClient &client, MessageIn &msg)
+void AccountHandler::handleCharacterSelectMessage(AccountClient &client,
+ MessageIn &msg)
{
MessageOut reply(APMSG_CHAR_SELECT_RESPONSE);
@@ -860,7 +867,8 @@ void AccountHandler::handleCharacterSelectMessage(AccountClient &client, Message
storage->addTransaction(trans);
}
-void AccountHandler::handleCharacterDeleteMessage(AccountClient &client, MessageIn &msg)
+void AccountHandler::handleCharacterDeleteMessage(AccountClient &client,
+ MessageIn &msg)
{
MessageOut reply(APMSG_CHAR_DELETE_RESPONSE);
diff --git a/src/common/configuration.cpp b/src/common/configuration.cpp
index 0f0a5844..a0e2ab2e 100644
--- a/src/common/configuration.cpp
+++ b/src/common/configuration.cpp
@@ -27,6 +27,7 @@
#include "utils/logger.h"
#include "utils/xml.hpp"
+#include "utils/string.hpp"
/**< Persistent configuration. */
static std::map< std::string, std::string > options;
@@ -78,13 +79,23 @@ std::string Configuration::getValue(const std::string &key,
const std::string &deflt)
{
std::map<std::string, std::string>::iterator iter = options.find(key);
- if (iter == options.end()) return deflt;
+ if (iter == options.end())
+ return deflt;
return iter->second;
}
int Configuration::getValue(const std::string &key, int deflt)
{
std::map<std::string, std::string>::iterator iter = options.find(key);
- if (iter == options.end()) return deflt;
+ if (iter == options.end())
+ return deflt;
return atoi(iter->second.c_str());
}
+
+bool Configuration::getBoolValue(const std::string &key, bool deflt)
+{
+ std::map<std::string, std::string>::iterator iter = options.find(key);
+ if (iter == options.end())
+ return deflt;
+ return utils::stringToBool(iter->second.c_str(), deflt);
+}
diff --git a/src/common/configuration.hpp b/src/common/configuration.hpp
index 0627c290..dbb0a7d4 100644
--- a/src/common/configuration.hpp
+++ b/src/common/configuration.hpp
@@ -43,11 +43,18 @@ namespace Configuration
std::string getValue(const std::string &key, const std::string &deflt);
/**
- * Gets an option as a string.
+ * Gets an option as an integer.
* @param key option identifier.
* @param deflt default value.
*/
int getValue(const std::string &key, int deflt);
+
+ /**
+ * Gets an option as a boolean.
+ * @param key option identifier.
+ * @param deflt default value.
+ */
+ bool getBoolValue(const std::string &key, bool deflt);
}
#ifndef DEFAULT_SERVER_PORT
diff --git a/src/game-server/attributemanager.cpp b/src/game-server/attributemanager.cpp
index ba94b815..d24c2645 100644
--- a/src/game-server/attributemanager.cpp
+++ b/src/game-server/attributemanager.cpp
@@ -38,25 +38,21 @@ void AttributeManager::reload()
for (unsigned int i = 0; i < ATTR_MAX; ++i)
mAttributeScopes[i].clear();
- std::string absPathFile;
- xmlNodePtr node;
-
- absPathFile = ResourceManager::resolve(mAttributeReferenceFile);
- if (absPathFile.empty()) {
- LOG_FATAL("Attribute Manager: Could not find " << mAttributeReferenceFile << "!");
+ std::string absPathFile = ResourceManager::resolve(mAttributeReferenceFile);
+ if (absPathFile.empty())
+ {
+ LOG_FATAL("Attribute Manager: Could not find "
+ << mAttributeReferenceFile << "!");
exit(3);
- return;
}
XML::Document doc(absPathFile, int());
- node = doc.rootNode();
-
+ xmlNodePtr node = doc.rootNode();
if (!node || !xmlStrEqual(node->name, BAD_CAST "attributes"))
{
LOG_FATAL("Attribute Manager: " << mAttributeReferenceFile
<< " is not a valid database file!");
exit(3);
- return;
}
LOG_INFO("Loading attribute reference...");
@@ -67,15 +63,21 @@ void AttributeManager::reload()
{
unsigned int id = XML::getProperty(attributenode, "id", 0);
- mAttributeMap[id] = std::pair< bool , std::vector<struct AttributeInfoType> >(false , std::vector<struct AttributeInfoType>());
+ mAttributeMap[id] = std::pair< bool ,
+ std::vector<struct AttributeInfoType> >
+ (false , std::vector<struct AttributeInfoType>());
+
unsigned int layerCount = 0;
for_each_xml_child_node(subnode, attributenode)
{
if (xmlStrEqual(subnode->name, BAD_CAST "modifier"))
{
- std::string sType = utils::toupper(XML::getProperty(subnode, "stacktype", ""));
- std::string eType = utils::toupper(XML::getProperty(subnode, "modtype", ""));
- std::string tag = utils::toupper(XML::getProperty(subnode, "tag", ""));
+ std::string sType = utils::toUpper(XML::getProperty(subnode,
+ "stacktype", ""));
+ std::string eType = utils::toUpper(XML::getProperty(subnode,
+ "modtype", ""));
+ std::string tag = utils::toUpper(XML::getProperty(subnode,
+ "tag", ""));
AT_TY pSType;
AME_TY pEType;
if (!sType.empty())
@@ -132,7 +134,8 @@ void AttributeManager::reload()
}
}
}
- std::string scope = utils::toupper(XML::getProperty(attributenode, "scope", std::string()));
+ std::string scope = utils::toUpper(XML::getProperty(attributenode,
+ "scope", std::string()));
if (scope.empty())
{
// Give a warning unless scope has been explicitly set to "NONE"
@@ -166,11 +169,13 @@ void AttributeManager::reload()
}
LOG_DEBUG("attribute map:");
- LOG_DEBUG("TY_ST is " << TY_ST << ", TY_ NST is " << TY_NST << ", TY_NSTB is " << TY_NSTB << ".");
+ LOG_DEBUG("TY_ST is " << TY_ST << ", TY_ NST is " << TY_NST
+ << ", TY_NSTB is " << TY_NSTB << ".");
LOG_DEBUG("AME_ADD is " << AME_ADD << ", AME_MULT is " << AME_MULT << ".");
const std::string *tag;
unsigned int count = 0;
- for (AttributeMap::const_iterator i = mAttributeMap.begin(); i != mAttributeMap.end(); ++i)
+ for (AttributeMap::const_iterator i = mAttributeMap.begin();
+ i != mAttributeMap.end(); ++i)
{
unsigned int lCount = 0;
LOG_DEBUG(" "<<i->first<<" : ");
diff --git a/src/game-server/mapreader.cpp b/src/game-server/mapreader.cpp
index ca827dd4..94da287c 100644
--- a/src/game-server/mapreader.cpp
+++ b/src/game-server/mapreader.cpp
@@ -30,7 +30,6 @@
#include "scripting/script.hpp"
#include "utils/base64.h"
#include "utils/logger.h"
-#include "utils/trim.hpp"
#include "utils/xml.hpp"
#include "utils/zlib.hpp"
#include "utils/string.hpp"
@@ -136,7 +135,8 @@ Map* MapReader::readMap(xmlNodePtr node, const std::string &path,
}
else
{
- ::tilesetFirstGids.push_back(XML::getProperty(node, "firstgid", 0));
+ ::tilesetFirstGids.push_back(XML::getProperty(node, "firstgid",
+ 0));
}
}
else if (xmlStrEqual(node->name, BAD_CAST "properties"))
@@ -172,7 +172,7 @@ Map* MapReader::readMap(xmlNodePtr node, const std::string &path,
std::string objName = XML::getProperty(objectNode, "name", "");
std::string objType = XML::getProperty(objectNode, "type", "");
- objType = utils::toupper(objType);
+ objType = utils::toUpper(objType);
int objX = XML::getProperty(objectNode, "x", 0);
int objY = XML::getProperty(objectNode, "y", 0);
int objW = XML::getProperty(objectNode, "width", 0);
@@ -195,13 +195,16 @@ Map* MapReader::readMap(xmlNodePtr node, const std::string &path,
for_each_xml_child_node(propertyNode, propertiesNode)
{
- if (xmlStrEqual(propertyNode->name, BAD_CAST "property"))
+ if (xmlStrEqual(propertyNode->name,
+ BAD_CAST "property"))
{
- std::string value = XML::getProperty(propertyNode, "name", std::string());
- value = utils::toupper(value);
+ std::string value = XML::getProperty(
+ propertyNode, "name", std::string());
+ value = utils::toUpper(value);
if (value == "DEST_MAP")
{
- destMapName = getObjectProperty(propertyNode, std::string());
+ destMapName = getObjectProperty(propertyNode,
+ std::string());
}
else if (value == "DEST_X")
{
@@ -249,7 +252,7 @@ Map* MapReader::readMap(xmlNodePtr node, const std::string &path,
if (xmlStrEqual(propertyNode->name, BAD_CAST "property"))
{
std::string value = XML::getProperty(propertyNode, "name", std::string());
- value = utils::toupper(value);
+ value = utils::toUpper(value);
if (value == "MONSTER_ID")
{
monsterId = getObjectProperty(propertyNode, monsterId);
@@ -302,7 +305,7 @@ Map* MapReader::readMap(xmlNodePtr node, const std::string &path,
if (xmlStrEqual(propertyNode->name, BAD_CAST "property"))
{
std::string value = XML::getProperty(propertyNode, "name", std::string());
- value = utils::toupper(value);
+ value = utils::toUpper(value);
if (value == "NPC_ID")
{
npcId = getObjectProperty(propertyNode, npcId);
@@ -349,11 +352,11 @@ Map* MapReader::readMap(xmlNodePtr node, const std::string &path,
if (xmlStrEqual(propertyNode->name, BAD_CAST "property"))
{
std::string value = XML::getProperty(propertyNode, "name", std::string());
- value = utils::toupper(value);
+ value = utils::toUpper(value);
if (value == "FILENAME")
{
scriptFilename = getObjectProperty(propertyNode, "");
- trim(scriptFilename);
+ utils::trim(scriptFilename);
}
else if (value == "TEXT")
{
@@ -546,6 +549,6 @@ void MapReader::setTileWithGid(Map *map, int x, int y, int gid)
set = *i;
}
- if (gid!=set)
+ if (gid != set)
map->blockTile(x, y, Map::BLOCKTYPE_WALL);
}
diff --git a/src/game-server/mapreader.hpp b/src/game-server/mapreader.hpp
index 53831d3f..f4a0e5f8 100644
--- a/src/game-server/mapreader.hpp
+++ b/src/game-server/mapreader.hpp
@@ -18,8 +18,8 @@
* along with The Mana Server. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef _INCLUDED_MAPREADER_H
-#define _INCLUDED_MAPREADER_H
+#ifndef _MAPREADER_H
+#define _MAPREADER_H
#include <string>
#include <vector>
diff --git a/src/game-server/skillmanager.cpp b/src/game-server/skillmanager.cpp
index dd9ee512..99c03f0e 100644
--- a/src/game-server/skillmanager.cpp
+++ b/src/game-server/skillmanager.cpp
@@ -21,7 +21,7 @@
#include "game-server/skillmanager.hpp"
#include "common/resourcemanager.hpp"
-#include "utils/string.hpp" // for the toupper function
+#include "utils/string.hpp" // for the toUpper function
#include "utils/logger.h"
#include "utils/xml.hpp"
@@ -88,7 +88,7 @@ void SkillManager::reload()
{
std::string name = XML::getProperty(skillnode, "name",
std::string());
- name = utils::toupper(name);
+ name = utils::toUpper(name);
int id = XML::getProperty(skillnode, "id", 0);
if (id && !name.empty())
{
@@ -199,11 +199,11 @@ int SkillManager::getIdFromString(const std::string &name)
}
// Convert to upper case for easier finding
- SkillMap::iterator i = skillMap.find(utils::toupper(name));
+ SkillMap::iterator i = skillMap.find(utils::toUpper(name));
if (i == skillMap.end())
{
LOG_WARN("SkillManager: No weapon-type name corresponding to "
- << utils::toupper(name) << " into " << skillReferenceFile);
+ << utils::toUpper(name) << " into " << skillReferenceFile);
return 0;
}
else
diff --git a/src/utils/string.cpp b/src/utils/string.cpp
index 3a2bb25e..785a0921 100644
--- a/src/utils/string.cpp
+++ b/src/utils/string.cpp
@@ -26,12 +26,18 @@
namespace utils {
-std::string toupper(std::string s)
+std::string toUpper(std::string s)
{
std::transform(s.begin(), s.end(), s.begin(), (int(*)(int)) std::toupper);
return s;
}
+std::string toLower(std::string s)
+{
+ std::transform(s.begin(), s.end(), s.begin(), (int(*)(int)) std::tolower);
+ return s;
+}
+
bool isNumeric(const std::string &s)
{
for (unsigned int i = 0; i < s.size(); ++i)
@@ -73,4 +79,32 @@ int compareStrI(const std::string &a, const std::string &b)
return 0;
}
+bool stringToBool(const std::string &s, bool defaultValue)
+{
+ std::string a = toLower(s);
+ if (a == "true" || a == "1" || a == "on" || a == "yes" || a == "y")
+ return true;
+ if (a == "false" || a == "0" || a == "off" || a == "no" || a == "n")
+ return false;
+
+ return defaultValue;
+}
+
+void trim(std::string &str)
+{
+ std::string::size_type pos = str.find_last_not_of(" \n\t");
+ if (pos != std::string::npos)
+ {
+ str.erase(pos + 1);
+ pos = str.find_first_not_of(" \n\t");
+ if (pos != std::string::npos)
+ str.erase(0, pos);
+ }
+ else
+ {
+ // There is nothing else but whitespace in the string
+ str.clear();
+ }
+}
+
} // namespace utils
diff --git a/src/utils/string.hpp b/src/utils/string.hpp
index e09e9abc..9f2b4ac6 100644
--- a/src/utils/string.hpp
+++ b/src/utils/string.hpp
@@ -18,15 +18,32 @@
* along with The Mana Server. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef UTILS_STRING_HPP
-#define UTILS_STRING_HPP
+#ifndef UTILS_STRING_H
+#define UTILS_STRING_H
#include <string>
namespace utils
{
- std::string toupper(std::string);
+ /**
+ * Returns an upper-cased copy of the string.
+ */
+ std::string toUpper(std::string);
+
+ /**
+ * Returns an lower-cased copy of the string.
+ */
+ std::string toLower(std::string);
+
+ /**
+ * Tells whether the string is a numerical representation.
+ */
bool isNumeric(const std::string &);
+
+ /**
+ * Turns a string representing a numerical representation
+ * into an integer value.
+ */
int stringToInt(const std::string &);
/**
@@ -38,6 +55,18 @@ namespace utils
* negative if the second is greater
*/
int compareStrI(const std::string &a, const std::string &b);
+
+ /**
+ * Returns the boolean value represented in a string, or default.
+ */
+ bool stringToBool(const std::string &s, bool defaultValue);
+
+ /**
+ * Trims spaces off the end and the beginning of the given string.
+ *
+ * @param str the string to trim spaces off
+ */
+ void trim(std::string &str);
}
-#endif // UTILS_STRING_HPP
+#endif // UTILS_STRING_H
diff --git a/src/utils/trim.hpp b/src/utils/trim.hpp
deleted file mode 100644
index ff93f939..00000000
--- a/src/utils/trim.hpp
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * The Mana Server
- * Copyright (C) 2007-2010 The Mana World Development Team
- *
- * This file is part of The Mana Server.
- *
- * The Mana Server is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * The Mana Server is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with The Mana Server. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef UTILS_TRIM_HPP
-#define UTILS_TRIM_HPP
-
-#include <string>
-
-/**
- * Trims spaces off the end and the beginning of the given string.
- *
- * @param str the string to trim spaces off
- */
-inline void trim(std::string &str)
-{
- std::string::size_type pos = str.find_last_not_of(" \n\t");
- if (pos != std::string::npos)
- {
- str.erase(pos + 1);
- pos = str.find_first_not_of(" \n\t");
- if (pos != std::string::npos)
- {
- str.erase(0, pos);
- }
- }
- else
- {
- // There is nothing else but whitespace in the string
- str.clear();
- }
-}
-
-#endif
diff --git a/src/utils/xml.cpp b/src/utils/xml.cpp
index 8bc9ebef..29202274 100644
--- a/src/utils/xml.cpp
+++ b/src/utils/xml.cpp
@@ -23,6 +23,7 @@
#include "common/resourcemanager.hpp"
#include "utils/logger.h"
+#include "utils/string.hpp"
#include <iostream>
#include <fstream>
@@ -114,12 +115,7 @@ namespace XML
xmlChar *prop = xmlGetProp(node, BAD_CAST name);
if (prop)
{
- if (xmlStrEqual(prop, BAD_CAST "true")
- ||xmlStrEqual(prop, BAD_CAST "yes"))
- ret = true;
- if (xmlStrEqual(prop, BAD_CAST "false")
- ||xmlStrEqual(prop, BAD_CAST "no"))
- ret = false;
+ ret = utils::stringToBool((char*) prop, def);
xmlFree(prop);
}
return ret;