mirror of
https://github.com/LibreOffice/online.git
synced 2025-08-20 23:24:34 +00:00
removed tokenize method with regex
Added new tokenize method with const char* delimiter Change-Id: Id1c4e89e5418d66aaf348ff4d8c3855f80fb4656 Reviewed-on: https://gerrit.libreoffice.org/c/online/+/83574 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Michael Meeks <michael.meeks@collabora.com>
This commit is contained in:

committed by
Michael Meeks

parent
85f09360d8
commit
8aa9b37b86
@ -53,9 +53,11 @@ void Authorization::authorizeRequest(Poco::Net::HTTPRequest& request) const
|
||||
// Authorization: Basic ....
|
||||
// X-Something-Custom: Huh
|
||||
// Regular expression evaluates and finds "\n\r" and tokenizes accordingly
|
||||
std::vector<std::string> tokens(LOOLProtocol::tokenize(_data, std::regex(R"(\n\r)"), /*skipEmpty =*/ true));
|
||||
for (const auto& token : tokens)
|
||||
StringVector tokens(LOOLProtocol::tokenize(_data, "\n\r"));
|
||||
for (auto it = tokens.begin(); it != tokens.end(); ++it)
|
||||
{
|
||||
std::string token = tokens.getParam(*it);
|
||||
|
||||
size_t separator = token.find_first_of(':');
|
||||
if (separator != std::string::npos)
|
||||
{
|
||||
|
@ -138,16 +138,29 @@ namespace LOOLProtocol
|
||||
return tokenize(s.data(), s.size(), delimiter);
|
||||
}
|
||||
|
||||
/// Tokenize according to the regex, potentially skip empty tokens.
|
||||
inline
|
||||
std::vector<std::string> tokenize(const std::string& s, const std::regex& pattern, bool skipEmpty = false)
|
||||
StringVector tokenize(const std::string& s, const char* delimiter)
|
||||
{
|
||||
std::vector<std::string> tokens;
|
||||
if (skipEmpty)
|
||||
std::copy_if(std::sregex_token_iterator(s.begin(), s.end(), pattern, -1), std::sregex_token_iterator(), std::back_inserter(tokens), [](std::string in) { return !in.empty(); });
|
||||
else
|
||||
std::copy(std::sregex_token_iterator(s.begin(), s.end(), pattern, -1), std::sregex_token_iterator(), std::back_inserter(tokens));
|
||||
return tokens;
|
||||
std::vector<StringToken> tokens;
|
||||
if (s.size() == 0)
|
||||
{
|
||||
return StringVector(std::string(), {});
|
||||
}
|
||||
|
||||
size_t start = 0;
|
||||
size_t end = s.find(delimiter, start);
|
||||
|
||||
tokens.emplace_back(start, end - start);
|
||||
start = end + std::strlen(delimiter);
|
||||
|
||||
while(end != std::string::npos)
|
||||
{
|
||||
end = s.find(delimiter, start);
|
||||
tokens.emplace_back(start, end - start);
|
||||
start = end + std::strlen(delimiter);
|
||||
}
|
||||
|
||||
return StringVector(s, tokens);
|
||||
}
|
||||
|
||||
inline
|
||||
|
Reference in New Issue
Block a user