diff options
author | Shauren <shauren.trinity@gmail.com> | 2016-06-04 16:36:23 +0200 |
---|---|---|
committer | Shauren <shauren.trinity@gmail.com> | 2016-06-04 16:36:23 +0200 |
commit | 40065aa658bf6eb0e4321983d36f16e8e61ad58e (patch) | |
tree | 0b060298741bc2a97120858b768eac10a1499e8f | |
parent | 3a63cfb1b240839c81b2a741fd33cae5df3d7180 (diff) |
Core/GameTables: Fixed loading gametables with trailing tabs
-rw-r--r-- | src/common/Utilities/Util.cpp | 7 | ||||
-rw-r--r-- | src/common/Utilities/Util.h | 2 | ||||
-rw-r--r-- | src/server/game/DataStores/GameTables.cpp | 9 |
3 files changed, 10 insertions, 8 deletions
diff --git a/src/common/Utilities/Util.cpp b/src/common/Utilities/Util.cpp index 28ffc891034..4f758c9cff1 100644 --- a/src/common/Utilities/Util.cpp +++ b/src/common/Utilities/Util.cpp @@ -30,7 +30,7 @@ #include <arpa/inet.h> #endif -Tokenizer::Tokenizer(const std::string &src, const char sep, uint32 vectorReserve) +Tokenizer::Tokenizer(const std::string &src, const char sep, uint32 vectorReserve /*= 0*/, bool keepEmptyStrings /*= true*/) { m_str = new char[src.length() + 1]; memcpy(m_str, src.c_str(), src.length() + 1); @@ -45,9 +45,10 @@ Tokenizer::Tokenizer(const std::string &src, const char sep, uint32 vectorReserv { if (*posnew == sep) { - m_storage.push_back(posold); - posold = posnew + 1; + if (keepEmptyStrings || posold != posnew) + m_storage.push_back(posold); + posold = posnew + 1; *posnew = '\0'; } else if (*posnew == '\0') diff --git a/src/common/Utilities/Util.h b/src/common/Utilities/Util.h index 7f0fc907964..ff737eb33bd 100644 --- a/src/common/Utilities/Util.h +++ b/src/common/Utilities/Util.h @@ -54,7 +54,7 @@ public: typedef StorageType::const_reference const_reference; public: - Tokenizer(const std::string &src, char const sep, uint32 vectorReserve = 0); + Tokenizer(const std::string &src, char const sep, uint32 vectorReserve = 0, bool keepEmptyStrings = true); ~Tokenizer() { delete[] m_str; } const_iterator begin() const { return m_storage.begin(); } diff --git a/src/server/game/DataStores/GameTables.cpp b/src/server/game/DataStores/GameTables.cpp index 4cde4bb7b2e..3197305b77f 100644 --- a/src/server/game/DataStores/GameTables.cpp +++ b/src/server/game/DataStores/GameTables.cpp @@ -51,7 +51,7 @@ inline uint32 LoadGameTable(std::vector<std::string>& errors, GameTable<T>& stor return 0; } - Tokenizer columnDefs(headers, '\t'); + Tokenizer columnDefs(headers, '\t', 0, false); ASSERT(columnDefs.size() - 1 == sizeof(T) / sizeof(float), "GameTable '%s' has different count of columns " SZFMTD " than expected by size of C++ structure (" SZFMTD ").", @@ -63,12 +63,13 @@ inline uint32 LoadGameTable(std::vector<std::string>& errors, GameTable<T>& stor std::string line; while (std::getline(stream, line)) { - if (line.empty()) + Tokenizer values(line, '\t', columnDefs.size(), false); + if (values.size() == 0) break; - Tokenizer values(line, '\t', columnDefs.size()); - ASSERT(values.size() == columnDefs.size()); + ASSERT(values.size() == columnDefs.size(), SZFMTD " == " SZFMTD, values.size(), columnDefs.size()); + // as of 21796 blizz doesnt seem to care about id column and just puts in whatever there ASSERT(strtol(values[0], nullptr, 10) == data.size(), "Unexpected row identifier %u at row " SZFMTD " (expected " SZFMTD ")", strtol(values[0], nullptr, 10), data.size(), data.size()); |