aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Mike Kelly <pioto@pioto.org> 2007-07-16 17:40:03 +0000
committerAvatar Mike Kelly <pioto@pioto.org> 2007-07-16 17:40:03 +0000
commit4efa00282a8282be189bcda866a8fad9c448a407 (patch)
tree40fd34463096e01f8f3fd66c2ac55dcbad555e0a
parentdd25e9881d58ec884c6a1d762e55d17fefe1bc90 (diff)
downloadpaludis-4efa00282a8282be189bcda866a8fad9c448a407.tar.gz
paludis-4efa00282a8282be189bcda866a8fad9c448a407.tar.xz
Add a new member to URIDepSpec, filename().
-rw-r--r--paludis/dep_spec.cc15
-rw-r--r--paludis/dep_spec.hh1
-rw-r--r--paludis/dep_spec_TEST.cc5
3 files changed, 21 insertions, 0 deletions
diff --git a/paludis/dep_spec.cc b/paludis/dep_spec.cc
index 5e6f8e2..bc2c30a 100644
--- a/paludis/dep_spec.cc
+++ b/paludis/dep_spec.cc
@@ -1007,6 +1007,21 @@ URIDepSpec::renamed_url_suffix() const
return text().substr(p + 4);
}
+std::string
+URIDepSpec::filename() const
+{
+ std::string rus = renamed_url_suffix();
+ if (! rus.empty())
+ return rus;
+
+ std::string orig = original_url();
+ std::string::size_type p(orig.rfind('/'));
+
+ if (std::string::npos == p)
+ return orig;
+ return orig.substr(p+1);
+}
+
tr1::shared_ptr<DepSpec>
URIDepSpec::clone() const
{
diff --git a/paludis/dep_spec.hh b/paludis/dep_spec.hh
index 5544c82..cb91f7f 100644
--- a/paludis/dep_spec.hh
+++ b/paludis/dep_spec.hh
@@ -404,6 +404,7 @@ namespace paludis
std::string original_url() const;
std::string renamed_url_suffix() const;
+ std::string filename() const;
virtual tr1::shared_ptr<DepSpec> clone() const PALUDIS_ATTRIBUTE((warn_unused_result));
};
diff --git a/paludis/dep_spec_TEST.cc b/paludis/dep_spec_TEST.cc
index 6a04bb1..73f6907 100644
--- a/paludis/dep_spec_TEST.cc
+++ b/paludis/dep_spec_TEST.cc
@@ -201,10 +201,15 @@ namespace test_cases
URIDepSpec a("foo");
TEST_CHECK_EQUAL(a.original_url(), "foo");
TEST_CHECK_EQUAL(a.renamed_url_suffix(), "");
+ TEST_CHECK_EQUAL(a.filename(), "foo");
URIDepSpec b("fnord -> bar");
TEST_CHECK_EQUAL(b.original_url(), "fnord");
TEST_CHECK_EQUAL(b.renamed_url_suffix(), "bar");
+ TEST_CHECK_EQUAL(b.filename(), "bar");
+
+ URIDepSpec c("http://example.com/download/baz");
+ TEST_CHECK_EQUAL(c.filename(), "baz");
}
} test_uri_dep_spec;