Skip to content

Commit

Permalink
tc_file add joinPaths
Browse files Browse the repository at this point in the history
  • Loading branch information
ruanshudong committed Jan 23, 2024
1 parent b8354c6 commit 563aa54
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
7 changes: 7 additions & 0 deletions unit-test/util/test_tc_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,10 @@ TEST_F(UtilFileTest, config)

ASSERT_TRUE(volumes.size() == 2);
}

TEST_F(UtilFileTest, join)
{
string v = TC_File::joinPaths("abc", string("def"), string("ddd"));

cout << v << endl;
}
25 changes: 24 additions & 1 deletion util/include/util/tc_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,31 @@ class TC_File
*/
static bool startWindowsPanfu(const string & sPath);

/**
* 连接参数, 变成路径
* @tparam T
* @tparam Args
* @param t
* @param args
* @return
*/
template<typename T, typename... Args>
static std::string joinPaths(T t, Args... args) {
return string(t) + FILE_SEP + joinPaths(args...);
}
private:
static bool isPanfu(const string & sPath);
// Base case: single argument
template<typename T>
static std::string joinPaths(T t) {
return t;
}

/**
* 是否是windows的盘符
* @param sPath
* @return
*/
static bool isPanfu(const string & sPath);
};
}
#endif // TC_FILE_H

0 comments on commit 563aa54

Please sign in to comment.