diff options
author | Max Kellermann <max@duempel.org> | 2014-01-26 11:37:52 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2014-10-10 22:43:40 +0200 |
commit | 464767c5fd0671b93f97f79905bdfb987826f6ef (patch) | |
tree | 371199fc0413bece2b143042e4fc23b2cd9f1e36 /src/util/UriUtil.cxx | |
parent | a9c3ca86065a5db6a9aeed32a25250cb785702a1 (diff) | |
download | mpd-464767c5fd0671b93f97f79905bdfb987826f6ef.tar.gz mpd-464767c5fd0671b93f97f79905bdfb987826f6ef.tar.xz mpd-464767c5fd0671b93f97f79905bdfb987826f6ef.zip |
db/upnp/Util: move caturl() to util/UriUtil.cxx
Diffstat (limited to '')
-rw-r--r-- | src/util/UriUtil.cxx | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/util/UriUtil.cxx b/src/util/UriUtil.cxx index a549f7938..fdca47c00 100644 --- a/src/util/UriUtil.cxx +++ b/src/util/UriUtil.cxx @@ -137,3 +137,31 @@ uri_is_child_or_same(const char *parent, const char *child) { return strcmp(parent, child) == 0 || uri_is_child(parent, child); } + +std::string +uri_apply_base(const std::string &uri, const std::string &base) +{ + if (uri.front() == '/') { + /* absolute path: replace the whole URI path in base */ + + auto i = base.find("://"); + if (i == base.npos) + /* no scheme: override base completely */ + return uri; + + /* find the first slash after the host part */ + i = base.find('/', i + 3); + if (i == base.npos) + /* there's no URI path - simply append uri */ + i = base.length(); + + return base.substr(0, i) + uri; + } + + std::string out(base); + if (out.back() != '/') + out.push_back('/'); + + out += uri; + return out; +} |