Apply all separators, not only the first one found, ref #518

This commit is contained in:
emeric
2024-09-07 09:34:45 +02:00
parent 39ca55e8fa
commit fc27a4f852
6 changed files with 90 additions and 28 deletions
+32
View File
@@ -79,6 +79,9 @@ namespace lms::core::stringUtils::tests
TestCase tests[]{
{ "", "", { "" } },
{ "//", "//", { "", "" } },
{ "//abc//", "//", { "", "abc", "" } },
{ "//abc////abc//", "//", { "", "abc", "", "abc", "" } },
{ "abc", "", { "abc" } },
{ "abc", "-", { "abc" } },
{ "abc", "b", { "a", "c" } },
@@ -99,6 +102,35 @@ namespace lms::core::stringUtils::tests
}
}
TEST(StringUtils, splitString_multiStringDelim)
{
struct TestCase
{
std::string_view input;
std::vector<std::string_view> delimiters;
std::vector<std::string_view> expectedOutput;
};
TestCase tests[]{
{ "", { "" }, { "" } },
{ "abc", { "" }, { "abc" } },
{ "abc", { "b" }, { "a", "c" } },
{ "ab/cd", { "/" }, { "ab", "cd" } },
{ "ab/cd", { "/", ";" }, { "ab", "cd" } },
{ "ab;/cd", { "/", ";" }, { "ab", "", "cd" } },
{ "ab;/;cd", { "/", ";" }, { "ab", "", "", "cd" } },
{ "ab/;cd", { "/", ";" }, { "ab", "", "cd" } },
{ "ab/;/cd", { "/", ";" }, { "ab", "", "", "cd" } },
{ "ab/cd/ef", { "/", "cd" }, { "ab", "", "", "ef" } },
};
for (const TestCase& test : tests)
{
const std::vector<std::string_view> res{ splitString(test.input, test.delimiters) };
EXPECT_EQ(res, test.expectedOutput) << "Input = '" << test.input << "'";
}
}
TEST(StringUtils, joinStrings)
{
struct TestCase