Don't process split of an empty string

This commit is contained in:
baldurk
2019-05-13 11:06:16 +01:00
parent 4f06af0eb3
commit 37d3320847
+17
View File
@@ -152,6 +152,9 @@ std::wstring get_dirname(const std::wstring &path)
void split(const std::string &in, std::vector<std::string> &out, const char sep)
{
if(in.empty())
return;
{
size_t numSeps = 0;
@@ -388,6 +391,20 @@ TEST_CASE("String manipulation", "[string]")
merge(vec, str, ' ');
CHECK(str == "Hello World");
};
SECTION("degenerate cases")
{
std::vector<std::string> vec;
std::string str;
split(std::string(), vec, ',');
REQUIRE(vec.empty());
merge(vec, str, ',');
REQUIRE(str == "");
};
};
#endif // ENABLED(ENABLE_UNIT_TESTS)