Deduplicated the snippet regex

This commit is contained in:
Veloman Yunkan 2022-06-05 00:33:36 +04:00 committed by Matthieu Gautier
parent 7d4867194a
commit f279769435
1 changed files with 4 additions and 2 deletions

View File

@ -548,15 +548,17 @@ const std::vector<SearchResult> LARGE_SEARCH_RESULTS = {
typedef std::vector<std::string> Snippets;
const char SNIPPET_REGEX_FOR_HTML[] = "<cite>(.+)</cite>";
std::string maskSnippetsInHtmlSearchResults(std::string s)
{
return replace(s, "<cite>.+</cite>", "<cite>SNIPPET TEXT WAS MASKED</cite>");
return replace(s, SNIPPET_REGEX_FOR_HTML, "<cite>SNIPPET TEXT WAS MASKED</cite>");
}
Snippets extractSearchResultSnippetsFromHtml(const std::string& html)
{
Snippets snippets;
const std::regex snippetRegex("<cite>(.*)</cite>");
const std::regex snippetRegex(SNIPPET_REGEX_FOR_HTML);
std::sregex_iterator snippetIt(html.begin(), html.end(), snippetRegex);
const std::sregex_iterator end;
for ( ; snippetIt != end; ++snippetIt)