diff --git a/src/core/Path.cc b/src/core/Path.cc index 83fa762..1010ad1 100644 --- a/src/core/Path.cc +++ b/src/core/Path.cc @@ -17,7 +17,7 @@ std::string Path::dirname(const std::string & s) return std::string(s, 0, pos); } -std::string Path::join(const std::string & first, const std::string & second) +std::string Path::_join(const std::string & first, const std::string & second) { if (first == "") { diff --git a/src/core/Path.h b/src/core/Path.h index 782eaf7..5b43cee 100644 --- a/src/core/Path.h +++ b/src/core/Path.h @@ -7,9 +7,24 @@ class Path { public: static std::string dirname(const std::string & s); - static std::string join(const std::string & first, const std::string & second); + + template + static std::string join(Parts... parts) + { + return _join(parts...); + } + static bool is_file(const std::string & s); static bool is_dir(const std::string & s); + +protected: + static std::string _join(const std::string & first, const std::string & second); + + template + static std::string _join(const std::string & first, const std::string & second, Parts... more) + { + return _join(_join(first, second), more...); + } }; #endif diff --git a/test/src/test_Path.cc b/test/src/test_Path.cc index ffc90a3..c205f92 100644 --- a/test/src/test_Path.cc +++ b/test/src/test_Path.cc @@ -62,6 +62,11 @@ TEST(Path_join, does_not_add_extra_slash_when_first_path_already_ends_with_one) EXPECT_EQ("/var/run", Path::join("/var/", "run")); } +TEST(Path_join, allows_arbitrary_number_of_arguments) +{ + EXPECT_EQ("/usr/local/share/jes/runtime", Path::join("/usr/local/", "share", "jes/", "runtime")); +} + TEST(Path_is_file, returns_true_for_file) {