commit 2bf942c232079225f8babd96c2e4dfe9dafe85b4
parent 298db41c777f4a3cc6ce1af4680bb66c0f34799a
Author: cfillion <cfillion@users.noreply.github.com>
Date: Wed, 18 Jan 2017 02:12:18 -0500
path: remove unused prepend/removeFirst methods
Diffstat:
3 files changed, 9 insertions(+), 80 deletions(-)
diff --git a/src/path.cpp b/src/path.cpp
@@ -69,25 +69,6 @@ Path::Path(const string &path)
append(path);
}
-void Path::prepend(const string &str)
-{
- if(str.empty())
- return;
-
- bool skip = false;
-
- const vector<string> &parts = Split(str);
-
- for(const string &part : parts | boost::adaptors::reversed) {
- if(part == DOTDOT)
- skip = true;
- else if(!skip)
- m_parts.push_front(part);
- else
- skip = false;
- }
-}
-
void Path::append(const string &parts, const bool traversal)
{
if(parts.empty())
@@ -103,11 +84,6 @@ void Path::append(const string &parts, const bool traversal)
}
}
-void Path::prepend(const Path &o)
-{
- m_parts.insert(m_parts.begin(), o.m_parts.begin(), o.m_parts.end());
-}
-
void Path::append(const Path &o)
{
m_parts.insert(m_parts.end(), o.m_parts.begin(), o.m_parts.end());
@@ -118,12 +94,6 @@ void Path::clear()
m_parts.clear();
}
-void Path::removeFirst()
-{
- if(!empty())
- m_parts.pop_front();
-}
-
void Path::removeLast()
{
if(!empty())
@@ -206,7 +176,7 @@ Path Path::operator+(const string &part) const
Path Path::operator+(const Path &o) const
{
Path path(*this);
- path += o;
+ path.append(o);
return path;
}
diff --git a/src/path.hpp b/src/path.hpp
@@ -35,11 +35,8 @@ public:
Path(const std::string &path = std::string());
- void prepend(const std::string &part);
void append(const std::string &part, bool traversal = true);
- void prepend(const Path &other);
void append(const Path &other);
- void removeFirst();
void removeLast();
void clear();
diff --git a/test/path.cpp b/test/path.cpp
@@ -19,7 +19,7 @@ TEST_CASE("compare paths", M) {
REQUIRE_FALSE(a != a);
}
-TEST_CASE("prepend and append path components", M) {
+TEST_CASE("append path components", M) {
Path path;
REQUIRE(path.empty());
REQUIRE(path.size() == 0);
@@ -27,14 +27,14 @@ TEST_CASE("prepend and append path components", M) {
REQUIRE(path.dirname().empty());
REQUIRE(path.basename().empty());
- path.prepend("world");
+ path.append("hello");
REQUIRE_FALSE(path.empty());
REQUIRE(path.size() == 1);
- REQUIRE(path.join() == "world");
+ REQUIRE(path.join() == "hello");
REQUIRE(path.dirname().empty());
- REQUIRE(path.basename() == "world");
+ REQUIRE(path.basename() == "hello");
- path.prepend("hello");
+ path.append("world");
REQUIRE(path.size() == 2);
#ifndef _WIN32
REQUIRE(path.join() == "hello/world");
@@ -70,7 +70,6 @@ TEST_CASE("concatenate paths", M) {
TEST_CASE("empty components", M) {
Path a;
a.append(string());
- a.prepend(string());
REQUIRE(a.size() == 0);
}
@@ -117,15 +116,6 @@ TEST_CASE("split input", M) {
REQUIRE(a[1] == "world");
}
- SECTION("prepend") {
- Path a;
- a.prepend("hello/world");
-
- REQUIRE(a.size() == 2);
- REQUIRE(a[0] == "hello");
- REQUIRE(a[1] == "world");
- }
-
SECTION("append") {
Path a;
a.append("hello/world");
@@ -154,24 +144,6 @@ TEST_CASE("absolute path (unix)", M) {
}
#endif
-TEST_CASE("remove first component of path", M) {
- Path a;
- a.append("a");
- a.append("b");
-
- CHECK(a.size() == 2);
-
- a.removeFirst();
-
- REQUIRE(a.size() == 1);
- REQUIRE(a[0] == "b");
-
- a.removeFirst();
- REQUIRE(a.empty());
-
- a.removeFirst(); // no crash
-}
-
TEST_CASE("remove last component of path", M) {
Path a;
a.append("a");
@@ -228,16 +200,6 @@ TEST_CASE("directory traversal", M) {
REQUIRE(a == Path("a/b"));
}
- SECTION("prepend") {
- Path a;
- a.prepend("a/../b/c/../d");
- REQUIRE(a == Path("b/d"));
-
- Path b;
- b.prepend("../a");
- REQUIRE(b == Path("a"));
- }
-
SECTION("concatenate") {
// concatenating a std::string to a path, directory traversal is applied
const Path a = Path("a/b/c") + "../../../d/e/f";
@@ -249,11 +211,11 @@ TEST_CASE("directory traversal", M) {
}
}
-TEST_CASE("append and prepend full paths") {
+TEST_CASE("append full paths") {
Path a;
- a += Path("c/d");
+ a += Path("a/b");
+ a.append(Path("c/d"));
a.append(Path("e/f"));
- a.prepend(Path("a/b"));
REQUIRE(a == Path("a/b/c/d/e/f"));
}