allow Path::join() to take an arbitrary number of arguments
This commit is contained in:
parent
2012591b27
commit
725a0f22a1
@ -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 == "")
|
||||
{
|
||||
|
@ -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 <typename... Parts>
|
||||
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 <typename... Parts>
|
||||
static std::string _join(const std::string & first, const std::string & second, Parts... more)
|
||||
{
|
||||
return _join(_join(first, second), more...);
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -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)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user