Unverified Commit e0826ede by Mircea Trofin Committed by GitHub

Fix StrSplit empty string case (#1142)

This also fixes #1135. Because StrSplit was returning a vector with an empty string, it was treated by PerfCounters::Create as a legitimate ask for setting up a counter with that name. The empty vector is understood by PerfCounters as "just return NoCounters()".
parent e50b572e
......@@ -164,6 +164,7 @@ std::string StrFormat(const char* format, ...) {
}
std::vector<std::string> StrSplit(const std::string& str, char delim) {
if (str.empty()) return {};
std::vector<std::string> ret;
size_t first = 0;
size_t next = str.find(delim);
......
......@@ -151,7 +151,7 @@ TEST(StringUtilTest, stod) {
}
TEST(StringUtilTest, StrSplit) {
EXPECT_EQ(benchmark::StrSplit("", ','), std::vector<std::string>{""});
EXPECT_EQ(benchmark::StrSplit("", ','), std::vector<std::string>{});
EXPECT_EQ(benchmark::StrSplit("hello", ','),
std::vector<std::string>({"hello"}));
EXPECT_EQ(benchmark::StrSplit("hello,there", ','),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment