utils: add schemepath function for url

This commit is contained in:
BlackMATov
2019-12-29 00:34:04 +07:00
parent 53519a9bc5
commit 3cb4890737
3 changed files with 15 additions and 0 deletions

View File

@@ -38,6 +38,8 @@ namespace e2d
const str& scheme() const noexcept;
const str& path() const noexcept;
str schemepath() const;
url& operator+=(str_view path);
url& operator/=(str_view path);

View File

@@ -135,6 +135,15 @@ namespace e2d
return path_;
}
str url::schemepath() const {
str result;
result.reserve(scheme_.size() + scheme_separator.size() + path_.size());
result.append(scheme_);
result.append(scheme_separator);
result.append(path_);
return result;
}
url& url::operator+=(str_view path) {
return concat(path);
}

View File

@@ -19,24 +19,28 @@ TEST_CASE("url") {
REQUIRE(u.empty());
REQUIRE(u.scheme().empty());
REQUIRE(u.path().empty());
REQUIRE(u.schemepath() == "://");
}
{
url u("://file");
REQUIRE(!u.empty());
REQUIRE(u.scheme().empty());
REQUIRE(u.path() == "file");
REQUIRE(u.schemepath() == "://file");
}
{
url u("file://");
REQUIRE(u.empty());
REQUIRE(u.scheme() == "file");
REQUIRE(u.path().empty());
REQUIRE(u.schemepath() == "file://");
}
{
url u("file://test_file");
REQUIRE(!u.empty());
REQUIRE(u.scheme() == "file");
REQUIRE(u.path() == "test_file");
REQUIRE(u.schemepath() == "file://test_file");
}
{
url u("dir/file");