diff options
author | Shauren <shauren.trinity@gmail.com> | 2016-06-04 16:40:57 +0200 |
---|---|---|
committer | Shauren <shauren.trinity@gmail.com> | 2016-06-04 16:40:57 +0200 |
commit | dd1533b315bda37e1d43ebe0fb8bde87381c6e66 (patch) | |
tree | 04f14c77c6335ee0ad277643e98ea45931e35074 /src/common/Utilities/Util.cpp | |
parent | 3f02f9edcd68548bc6ae0625d706452f626a0b03 (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
Diffstat (limited to 'src/common/Utilities/Util.cpp')
-rw-r--r-- | src/common/Utilities/Util.cpp | 7 |
1 files changed, 4 insertions, 3 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') |