UrlProvider: Introduce combine(), rootUrl(), atomFeed()
This commit is contained in:
父節點
9520aabe5c
當前提交
bcc3737d88
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
載入中…
新增問題並參考
Block a user