summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/game-server/mapreader.cpp5
-rw-r--r--src/utils/string.cpp27
-rw-r--r--src/utils/string.hpp10
3 files changed, 36 insertions, 6 deletions
diff --git a/src/game-server/mapreader.cpp b/src/game-server/mapreader.cpp
index 55c7a6d..263b26f 100644
--- a/src/game-server/mapreader.cpp
+++ b/src/game-server/mapreader.cpp
@@ -125,7 +125,6 @@ Map* MapReader::readMap(xmlNodePtr node, const std::string &path,
// We only support tile width of 32 at the moment
int tilew = XML::getProperty(node, "tilewidth", DEFAULT_TILE_WIDTH);
int tileh = XML::getProperty(node, "tileheight", DEFAULT_TILE_HEIGHT);
- int layerNr = 0;
Map* map = new Map(w, h, tilew, tileh);
for (node = node->xmlChildrenNode; node != NULL; node = node->next)
@@ -156,8 +155,8 @@ Map* MapReader::readMap(xmlNodePtr node, const std::string &path,
}
else if (xmlStrEqual(node->name, BAD_CAST "layer"))
{
- // Layer 3 is collision layer.
- if (layerNr++ == 3)
+ if (utils::compareStrI(XML::getProperty(node, "name", "unnamed"),
+ "collision") == 0)
{
readLayer(node, map);
}
diff --git a/src/utils/string.cpp b/src/utils/string.cpp
index d5e6d22..b1c1a05 100644
--- a/src/utils/string.cpp
+++ b/src/utils/string.cpp
@@ -24,13 +24,15 @@
#include <algorithm>
#include <sstream>
-std::string utils::toupper(std::string s)
+namespace utils {
+
+std::string toupper(std::string s)
{
std::transform(s.begin(), s.end(), s.begin(), (int(*)(int)) std::toupper);
return s;
}
-bool utils::isNumeric(const std::string &s)
+bool isNumeric(const std::string &s)
{
for (unsigned int i = 0; i < s.size(); ++i)
{
@@ -43,7 +45,7 @@ bool utils::isNumeric(const std::string &s)
return true;
}
-int utils::stringToInt(const std::string &s)
+int stringToInt(const std::string &s)
{
int value;
std::stringstream str(s);
@@ -53,3 +55,22 @@ int utils::stringToInt(const std::string &s)
return value;
}
+
+int compareStrI(const std::string &a, const std::string &b)
+{
+ std::string::const_iterator itA = a.begin();
+ std::string::const_iterator endA = a.end();
+ std::string::const_iterator itB = b.begin();
+ std::string::const_iterator endB = b.end();
+
+ for (; itA < endA, itB < endB; ++itA, ++itB)
+ {
+ int comp = tolower(*itA) - tolower(*itB);
+ if (comp)
+ return comp;
+ }
+
+ return 0;
+}
+
+} // namespace utils
diff --git a/src/utils/string.hpp b/src/utils/string.hpp
index 448376f..5d494b7 100644
--- a/src/utils/string.hpp
+++ b/src/utils/string.hpp
@@ -28,6 +28,16 @@ namespace utils
std::string toupper(std::string);
bool isNumeric(const std::string &);
int stringToInt(const std::string &);
+
+ /**
+ * Compares the two strings case-insensitively.
+ *
+ * @param a the first string in the comparison
+ * @param b the second string in the comparison
+ * @return 0 if the strings are equal, positive if the first is greater,
+ * negative if the second is greater
+ */
+ int compareStrI(const std::string &a, const std::string &b);
}
#endif // UTILS_STRING_HPP