summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--src/Makefile.am1
-rw-r--r--src/game-server/mapreader.cpp6
-rw-r--r--src/utils/trim.hpp53
4 files changed, 63 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 7836aae8..1633026a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2007-11-13 Guillaume Melquiond <guillaume.melquiond@gmail.com>
+
+ * src/utils/trim.hpp, src/Makefile.am: Added trim function.
+ * src/game-server/mapreader.cpp: Trimed script filenames from spaces.
+
2007-10-27 Guillaume Melquiond <guillaume.melquiond@gmail.com>
* src/dal/recordset.cpp, src/utils/zlib.cpp, src/scripting/script.cpp,
diff --git a/src/Makefile.am b/src/Makefile.am
index 71bfd97a..e8638da3 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -150,6 +150,7 @@ tmwserv_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/game-server/mapreader.cpp b/src/game-server/mapreader.cpp
index 24ed3796..48f142c4 100644
--- a/src/game-server/mapreader.cpp
+++ b/src/game-server/mapreader.cpp
@@ -35,6 +35,7 @@
#include "scripting/script.hpp"
#include "utils/base64.h"
#include "utils/logger.h"
+#include "utils/trim.hpp"
#include "utils/xml.hpp"
#include "utils/zlib.hpp"
@@ -337,7 +338,7 @@ static Map *readMap(xmlNodePtr node, std::string const &path, MapComposite *comp
composite->setScript(s);
}
- char const *scriptFilename = NULL;
+ std::string scriptFilename;
char const *scriptText = NULL;
for_each_xml_child_node(propertiesNode, objectNode)
@@ -355,6 +356,7 @@ static Map *readMap(xmlNodePtr node, std::string const &path, MapComposite *comp
if (value == "FILENAME")
{
scriptFilename = (const char *)propertyNode->xmlChildrenNode->content;
+ trim(scriptFilename);
}
else if (value == "TEXT")
{
@@ -364,7 +366,7 @@ static Map *readMap(xmlNodePtr node, std::string const &path, MapComposite *comp
}
}
- if (scriptFilename != NULL)
+ if (!scriptFilename.empty())
{
s->loadFile(scriptFilename);
}
diff --git a/src/utils/trim.hpp b/src/utils/trim.hpp
new file mode 100644
index 00000000..4312cfa7
--- /dev/null
+++ b/src/utils/trim.hpp
@@ -0,0 +1,53 @@
+/*
+ * The Mana World
+ * Copyright 2007 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * The Mana World 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 World 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 World; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id$
+ */
+
+#ifndef _TMWSERV_UTILS_TRIM_
+#define _TMWSERV_UTILS_TRIM_
+
+#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