Skip to content

Commit 4e31171

Browse files
committed
Allow tokenization w/o empty elements exclusion
1 parent b164eeb commit 4e31171

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

Common/Utils/include/CommonUtils/StringUtils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ struct Str {
107107
}
108108

109109
// return vector of tokens from the string with provided delimiter. If requested, trim the spaces from tokens
110-
static std::vector<std::string> tokenize(const std::string& src, char delim, bool trimToken = true);
110+
static std::vector<std::string> tokenize(const std::string& src, char delim, bool trimToken = true, bool skipEmpty = true);
111111

112112
// concatenate arbitrary number of strings
113113
template <typename... Ts>

Common/Utils/src/StringUtils.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
using namespace o2::utils;
1717

18-
std::vector<std::string> Str::tokenize(const std::string& src, char delim, bool trimToken)
18+
std::vector<std::string> Str::tokenize(const std::string& src, char delim, bool trimToken, bool skipEmpty)
1919
{
2020
std::stringstream ss(src);
2121
std::string token;
@@ -25,7 +25,7 @@ std::vector<std::string> Str::tokenize(const std::string& src, char delim, bool
2525
if (trimToken) {
2626
trim(token);
2727
}
28-
if (!token.empty()) {
28+
if (!token.empty() || !skipEmpty) {
2929
tokens.push_back(std::move(token));
3030
}
3131
}

0 commit comments

Comments
 (0)