utils: split: Rename all splitBy*() variants to split()
This commit is contained in:
parent
b995362d1f
commit
4dc688f9eb
@ -159,7 +159,7 @@ std::vector<std::string> PageDaoSqlite::fetchCategories(std::string pagename, Qu
|
|||||||
std::string PageDaoSqlite::ftsEscape(std::string input)
|
std::string PageDaoSqlite::ftsEscape(std::string input)
|
||||||
{
|
{
|
||||||
std::string result = "";
|
std::string result = "";
|
||||||
for(auto &str : utils::splitByChar(input, ' '))
|
for(auto &str : utils::split(input, ' '))
|
||||||
{
|
{
|
||||||
std::string tmp = utils::strreplace(str, "\"", "\"\"");
|
std::string tmp = utils::strreplace(str, "\"", "\"\"");
|
||||||
tmp = "\"" + tmp + "\"" + " ";
|
tmp = "\"" + tmp + "\"" + " ";
|
||||||
|
@ -86,7 +86,7 @@ std::string Parser::processLink(const PageDao &pageDao, UrlProvider &urlProvider
|
|||||||
std::string linktag = match.str(1);
|
std::string linktag = match.str(1);
|
||||||
std::string inside = match.str(2);
|
std::string inside = match.str(2);
|
||||||
|
|
||||||
std::vector<std::string> splitted = utils::splitByChar(inside, '|');
|
std::vector<std::string> splitted = utils::split(inside, '|');
|
||||||
HtmlLink htmllink;
|
HtmlLink htmllink;
|
||||||
if(splitted.size() == 2)
|
if(splitted.size() == 2)
|
||||||
{
|
{
|
||||||
|
@ -47,7 +47,7 @@ std::pair<std::string, std::string> Request::createPairFromVar(std::string var)
|
|||||||
|
|
||||||
void Request::initMultiMap(std::multimap<std::string, std::string> &map, const std::string &url)
|
void Request::initMultiMap(std::multimap<std::string, std::string> &map, const std::string &url)
|
||||||
{
|
{
|
||||||
auto splitted = utils::splitByChar(url, '&');
|
auto splitted = utils::split(url, '&');
|
||||||
for(const std::string &part : splitted)
|
for(const std::string &part : splitted)
|
||||||
{
|
{
|
||||||
auto pair = createPairFromVar(part);
|
auto pair = createPairFromVar(part);
|
||||||
@ -75,7 +75,8 @@ void Request::initPostMap(const std::string &url)
|
|||||||
void Request::initCookies(const std::string &cookiestr)
|
void Request::initCookies(const std::string &cookiestr)
|
||||||
{
|
{
|
||||||
// TODO: find out what it really should be, ";" or "; "?
|
// 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)
|
for(const std::string &part : cookiesplitted)
|
||||||
{
|
{
|
||||||
auto pair = createPairFromVar(part);
|
auto pair = createPairFromVar(part);
|
||||||
|
@ -78,7 +78,7 @@ std::string utils::urldecode(std::string_view str)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> utils::splitByChar(const std::string &str, char delim)
|
std::vector<std::string> utils::split(const std::string &str, char delim)
|
||||||
{
|
{
|
||||||
std::vector<std::string> result;
|
std::vector<std::string> result;
|
||||||
std::stringstream stream(str);
|
std::stringstream stream(str);
|
||||||
@ -91,12 +91,13 @@ std::vector<std::string> utils::splitByChar(const std::string &str, char delim)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: can easily break if we pass a regex here
|
// TODO: can easily break if we pass a regex here
|
||||||
std::vector<std::string> utils::splitByString(const std::string &str, const std::string &delim)
|
std::vector<std::string> utils::split(const std::string &str, const std::string &delim)
|
||||||
{
|
{
|
||||||
return splitByRegex(str, delim + "+");
|
std::regex regex { delim + "+" };
|
||||||
|
return split(str, regex);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> utils::splitByRegex(const std::string &str, const std::string ®ex)
|
std::vector<std::string> utils::split(const std::string &str, std::regex ®ex)
|
||||||
{
|
{
|
||||||
std::vector<std::string> result;
|
std::vector<std::string> result;
|
||||||
std::regex reg(regex);
|
std::regex reg(regex);
|
||||||
|
6
utils.h
6
utils.h
@ -11,9 +11,9 @@
|
|||||||
namespace utils
|
namespace utils
|
||||||
{
|
{
|
||||||
|
|
||||||
std::vector<std::string> splitByChar(const std::string &str, char delim);
|
std::vector<std::string> split(const std::string &str, char delim);
|
||||||
std::vector<std::string> splitByString(const std::string &str, const std::string &delim);
|
std::vector<std::string> split(const std::string &str, const std::string &delim);
|
||||||
std::vector<std::string> splitByRegex(const std::string &str, const std::string ®ex);
|
std::vector<std::string> split(const std::string &str, std::regex ®ex);
|
||||||
std::string urldecode(std::string_view str);
|
std::string urldecode(std::string_view str);
|
||||||
std::string strreplace(const std::string &str, const std::string &search, const std::string &replace);
|
std::string strreplace(const std::string &str, const std::string &search, const std::string &replace);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user