mirror of
https://github.com/kiwix/libkiwix.git
synced 2025-06-28 05:49:35 +00:00
[API Break] Fix pathTools (and a bit stringTools).
Api changes : - removeLastPathElement do not takes extra arguments `removePreSeparator` and `removePostSeparator`. This is not needed as path do not need special tailing separator. - Only one function `split`. Arguments can be implicitly convert to string. No need for overloading functions to explicitly cast them. - `split` function takes another argument `trimEmpty`. If true, empty element are removed. Path manipulation now almost pass trough a vector<string> to store each path's part. Most of the complex works is now made in the normalizeParts function.
This commit is contained in:
@ -23,6 +23,7 @@
|
||||
|
||||
namespace kiwix {
|
||||
std::string join(const std::vector<std::string>& list, const std::string& sep);
|
||||
std::vector<std::string> split(const std::string& base, const std::string& sep, bool trimEmpty);
|
||||
};
|
||||
|
||||
using namespace kiwix;
|
||||
@ -36,6 +37,22 @@ TEST(stringTools, join)
|
||||
ASSERT_EQ(join(list, ";"), "a;b;c");
|
||||
}
|
||||
|
||||
TEST(stringTools, split)
|
||||
{
|
||||
std::vector<std::string> list1 = { "a", "b", "c" };
|
||||
ASSERT_EQ(split("a;b;c", ";", false), list1);
|
||||
ASSERT_EQ(split("a;b;c", ";", true), list1);
|
||||
std::vector<std::string> list2 = { "", "a", "b", "c" };
|
||||
ASSERT_EQ(split(";a;b;c", ";", false), list2);
|
||||
ASSERT_EQ(split(";a;b;c", ";", true), list1);
|
||||
std::vector<std::string> list3 = { "", "a", "b", "c", ""};
|
||||
ASSERT_EQ(split(";a;b;c;", ";", false), list3);
|
||||
ASSERT_EQ(split(";a;b;c;", ";", true), list1);
|
||||
std::vector<std::string> list4 = { "", "a", "b", "", "c", ""};
|
||||
ASSERT_EQ(split(";a;b;;c;", ";", false), list4);
|
||||
ASSERT_EQ(split(";a;b;;c;", ";", true), list1);
|
||||
}
|
||||
|
||||
};
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
|
Reference in New Issue
Block a user