From 4dc688f9ebf75b3d34a0e74af6ceb865c9da65f7 Mon Sep 17 00:00:00 2001 From: Albert S Date: Sat, 17 Apr 2021 12:41:22 +0200 Subject: [PATCH] utils: split: Rename all splitBy*() variants to split() --- database/pagedaosqlite.cpp | 2 +- parser.cpp | 2 +- request.cpp | 5 +++-- utils.cpp | 9 +++++---- utils.h | 6 +++--- 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/database/pagedaosqlite.cpp b/database/pagedaosqlite.cpp index a05d0eb..9b95ab3 100644 --- a/database/pagedaosqlite.cpp +++ b/database/pagedaosqlite.cpp @@ -159,7 +159,7 @@ std::vector PageDaoSqlite::fetchCategories(std::string pagename, Qu std::string PageDaoSqlite::ftsEscape(std::string input) { std::string result = ""; - for(auto &str : utils::splitByChar(input, ' ')) + for(auto &str : utils::split(input, ' ')) { std::string tmp = utils::strreplace(str, "\"", "\"\""); tmp = "\"" + tmp + "\"" + " "; diff --git a/parser.cpp b/parser.cpp index f069d9e..8ee460c 100644 --- a/parser.cpp +++ b/parser.cpp @@ -86,7 +86,7 @@ std::string Parser::processLink(const PageDao &pageDao, UrlProvider &urlProvider std::string linktag = match.str(1); std::string inside = match.str(2); - std::vector splitted = utils::splitByChar(inside, '|'); + std::vector splitted = utils::split(inside, '|'); HtmlLink htmllink; if(splitted.size() == 2) { diff --git a/request.cpp b/request.cpp index 800b822..0566343 100644 --- a/request.cpp +++ b/request.cpp @@ -47,7 +47,7 @@ std::pair Request::createPairFromVar(std::string var) void Request::initMultiMap(std::multimap &map, const std::string &url) { - auto splitted = utils::splitByChar(url, '&'); + auto splitted = utils::split(url, '&'); for(const std::string &part : splitted) { auto pair = createPairFromVar(part); @@ -75,7 +75,8 @@ void Request::initPostMap(const std::string &url) void Request::initCookies(const std::string &cookiestr) { // TODO: find out what it really should be, ";" or "; "? - auto cookiesplitted = utils::splitByRegex(cookiestr, ";+\\s?"); + std::regex regex { ";+\\s?" }; + auto cookiesplitted = utils::split(cookiestr, regex); for(const std::string &part : cookiesplitted) { auto pair = createPairFromVar(part); diff --git a/utils.cpp b/utils.cpp index 163d149..3df6306 100644 --- a/utils.cpp +++ b/utils.cpp @@ -78,7 +78,7 @@ std::string utils::urldecode(std::string_view str) return result; } -std::vector utils::splitByChar(const std::string &str, char delim) +std::vector utils::split(const std::string &str, char delim) { std::vector result; std::stringstream stream(str); @@ -91,12 +91,13 @@ std::vector utils::splitByChar(const std::string &str, char delim) } // TODO: can easily break if we pass a regex here -std::vector utils::splitByString(const std::string &str, const std::string &delim) +std::vector utils::split(const std::string &str, const std::string &delim) { - return splitByRegex(str, delim + "+"); + std::regex regex { delim + "+" }; + return split(str, regex); } -std::vector utils::splitByRegex(const std::string &str, const std::string ®ex) +std::vector utils::split(const std::string &str, std::regex ®ex) { std::vector result; std::regex reg(regex); diff --git a/utils.h b/utils.h index fee00be..d19be1b 100644 --- a/utils.h +++ b/utils.h @@ -11,9 +11,9 @@ namespace utils { -std::vector splitByChar(const std::string &str, char delim); -std::vector splitByString(const std::string &str, const std::string &delim); -std::vector splitByRegex(const std::string &str, const std::string ®ex); +std::vector split(const std::string &str, char delim); +std::vector split(const std::string &str, const std::string &delim); +std::vector split(const std::string &str, std::regex ®ex); std::string urldecode(std::string_view str); std::string strreplace(const std::string &str, const std::string &search, const std::string &replace);