diff options
author | Shauren <shauren.trinity@gmail.com> | 2016-06-04 16:40:57 +0200 |
---|---|---|
committer | jackpoz <giacomopoz@gmail.com> | 2016-08-06 14:29:11 +0200 |
commit | caee7dcad51474de16f43bea5e0ade203e50e8c5 (patch) | |
tree | 65989e4a04ab37e87aefff345dbc89bb3bdb5e17 | |
parent | b51409a5d3201e86bd189d1ea7dfd1dc1ca8a35f (diff) |
Core/Utils: Added additional argument to Tokenizer class to make it behave like strtok - not returning empty tokens in case of multiple consecutive separators in input string
(cherry picked from commit dd1533b315bda37e1d43ebe0fb8bde87381c6e66)
-rw-r--r-- | src/common/Utilities/Util.cpp | 7 | ||||
-rw-r--r-- | src/common/Utilities/Util.h | 2 |
2 files changed, 5 insertions, 4 deletions
diff --git a/src/common/Utilities/Util.cpp b/src/common/Utilities/Util.cpp index 3d8cda66d48..b8877fe491e 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 cc68f3b2237..1699ca8096e 100644 --- a/src/common/Utilities/Util.h +++ b/src/common/Utilities/Util.h @@ -52,7 +52,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(); } |