Skip to content

Commit 8775138

Browse files
committed
Path: added join() with 3 paths
1 parent 6bbfee2 commit 8775138

3 files changed

Lines changed: 14 additions & 0 deletions

File tree

lib/path.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,3 +458,8 @@ std::string Path::join(std::string path1, std::string path2)
458458
return path2;
459459
return ((path1.back() == '/') ? path1 : (path1 + "/")) + path2;
460460
}
461+
462+
std::string Path::join(std::string path1, std::string path2, std::string path3)
463+
{
464+
return Path::join(Path::join(std::move(path1), std::move(path2)), std::move(path3));
465+
}

lib/path.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,13 @@ class CPPCHECKLIB Path {
206206
* @return the joined path with normalized slashes
207207
*/
208208
static std::string join(std::string path1, std::string path2);
209+
210+
/**
211+
* @brief join 3 paths with '/' separators
212+
* if path2 is an absolute path path1 will be dismissed.
213+
* @return the joined path with normalized slashes
214+
*/
215+
static std::string join(std::string path1, std::string path2, std::string path3);
209216
};
210217

211218
/// @}

test/testpath.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,8 @@ class TestPath : public TestFixture {
202202
//ASSERT_EQUALS("", Path::join("S:/a", "S:/b"));
203203
//ASSERT_EQUALS("", Path::join("S:/a", "S:\\b"));
204204
//ASSERT_EQUALS("", Path::join("S:/a", "/b"));
205+
206+
ASSERT_EQUALS("a/b/c", Path::join("a", "b", "c"));
205207
}
206208

207209
void isDirectory() const {

0 commit comments

Comments
 (0)