mirror of
https://github.com/badaix/snapcast.git
synced 2025-07-23 11:27:38 +02:00
Split returns empty last element
This commit is contained in:
parent
ad6ab1ad3b
commit
15a3cf9680
2 changed files with 21 additions and 2 deletions
|
@ -162,6 +162,10 @@ std::vector<std::string>& split(const std::string& s, char delim, std::vector<st
|
||||||
{
|
{
|
||||||
elems.push_back(item);
|
elems.push_back(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!s.empty() && (s.back() == delim))
|
||||||
|
elems.emplace_back("");
|
||||||
|
|
||||||
return elems;
|
return elems;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,21 @@ TEST_CASE("String utils")
|
||||||
using namespace utils::string;
|
using namespace utils::string;
|
||||||
REQUIRE(ltrim_copy(" test") == "test");
|
REQUIRE(ltrim_copy(" test") == "test");
|
||||||
|
|
||||||
auto strings = split("1*2", '*');
|
auto strings = split("", '*');
|
||||||
|
REQUIRE(strings.empty());
|
||||||
|
|
||||||
|
strings = split("*", '*');
|
||||||
|
REQUIRE(strings.size() == 2);
|
||||||
|
REQUIRE(strings[0] == "");
|
||||||
|
REQUIRE(strings[1] == "");
|
||||||
|
|
||||||
|
strings = split("**", '*');
|
||||||
|
REQUIRE(strings.size() == 3);
|
||||||
|
REQUIRE(strings[0] == "");
|
||||||
|
REQUIRE(strings[1] == "");
|
||||||
|
REQUIRE(strings[2] == "");
|
||||||
|
|
||||||
|
strings = split("1*2", '*');
|
||||||
REQUIRE(strings.size() == 2);
|
REQUIRE(strings.size() == 2);
|
||||||
REQUIRE(strings[0] == "1");
|
REQUIRE(strings[0] == "1");
|
||||||
REQUIRE(strings[1] == "2");
|
REQUIRE(strings[1] == "2");
|
||||||
|
@ -66,10 +80,11 @@ TEST_CASE("String utils")
|
||||||
REQUIRE(strings[2] == "2");
|
REQUIRE(strings[2] == "2");
|
||||||
|
|
||||||
strings = split("*1*2*", '*');
|
strings = split("*1*2*", '*');
|
||||||
REQUIRE(strings.size() == 3);
|
REQUIRE(strings.size() == 4);
|
||||||
REQUIRE(strings[0] == "");
|
REQUIRE(strings[0] == "");
|
||||||
REQUIRE(strings[1] == "1");
|
REQUIRE(strings[1] == "1");
|
||||||
REQUIRE(strings[2] == "2");
|
REQUIRE(strings[2] == "2");
|
||||||
|
REQUIRE(strings[3] == "");
|
||||||
|
|
||||||
std::vector<std::string> vec{"1", "2", "3"};
|
std::vector<std::string> vec{"1", "2", "3"};
|
||||||
REQUIRE(container_to_string(vec) == "1, 2, 3");
|
REQUIRE(container_to_string(vec) == "1, 2, 3");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue