UrlProvider: Introduce combine(), rootUrl(), atomFeed()

Šī revīzija ir iekļauta:
Albert S. 2022-03-27 19:51:53 +02:00
vecāks 9520aabe5c
revīzija bcc3737d88
2 mainīti faili ar 32 papildinājumiem un 0 dzēšanām

Parādīt failu

@ -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 <string_view>
#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<std::string> 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;
}

Parādīt failu

@ -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<std::string> urls);
};
#endif // LINKCREATOR_H