From bcc3737d88f571f1f472ed3a1754f226e5402b1a Mon Sep 17 00:00:00 2001 From: Albert S Date: Sun, 27 Mar 2022 19:51:53 +0200 Subject: [PATCH] UrlProvider: Introduce combine(), rootUrl(), atomFeed() --- urlprovider.cpp | 26 ++++++++++++++++++++++++++ urlprovider.h | 6 ++++++ 2 files changed, 32 insertions(+) diff --git a/urlprovider.cpp b/urlprovider.cpp index dbcc4bd..a515bff 100644 --- a/urlprovider.cpp +++ b/urlprovider.cpp @@ -18,6 +18,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +#include #include "urlprovider.h" std::string replaceSingleVar(std::string where, std::string varname, std::string replacement) @@ -119,3 +120,28 @@ std::string UrlProvider::login(std::string page) { return replaceOnlyPage(config->loginurl, page); } + +std::string UrlProvider::rootUrl() +{ + return config->rooturl; +} + +std::string UrlProvider::atomFeed(std::string filter) +{ + return combine({config->rooturl, replaceSingleVar(config->atomurl, "filter", filter)}); +} + +std::string UrlProvider::combine(std::initializer_list urls) +{ + std::string result; + for(const std::string &url : urls) + { + std::string_view urlview{url}; + if(result.back() == '/' && urlview.front() == '/') + { + urlview.remove_prefix(1); + } + result += urlview; + } + return result; +} diff --git a/urlprovider.h b/urlprovider.h index faf50a7..3c28c0e 100644 --- a/urlprovider.h +++ b/urlprovider.h @@ -48,6 +48,12 @@ class UrlProvider std::string category(std::string catname); std::string login(std::string page); + + std::string rootUrl(); + + std::string atomFeed(std::string filter); + + std::string combine(std::initializer_list urls); }; #endif // LINKCREATOR_H