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()".
This commit is contained in:
Mircea Trofin 2021-05-06 11:12:36 -07:00 committed by GitHub
parent e50b572e89
commit e0826edea7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 1 deletions

View File

@ -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);

View File

@ -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", ','),