mirror of
https://github.com/enduro2d/enduro2d.git
synced 2026-03-22 04:44:09 +07:00
utils: add schemepath function for url
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user