mirror of https://github.com/kiwix/libkiwix.git
Deduplicated the snippet regex
This commit is contained in:
parent
7d4867194a
commit
f279769435
|
@ -548,15 +548,17 @@ const std::vector<SearchResult> LARGE_SEARCH_RESULTS = {
|
||||||
|
|
||||||
typedef std::vector<std::string> Snippets;
|
typedef std::vector<std::string> Snippets;
|
||||||
|
|
||||||
|
const char SNIPPET_REGEX_FOR_HTML[] = "<cite>(.+)</cite>";
|
||||||
|
|
||||||
std::string maskSnippetsInHtmlSearchResults(std::string s)
|
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 extractSearchResultSnippetsFromHtml(const std::string& html)
|
||||||
{
|
{
|
||||||
Snippets snippets;
|
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);
|
std::sregex_iterator snippetIt(html.begin(), html.end(), snippetRegex);
|
||||||
const std::sregex_iterator end;
|
const std::sregex_iterator end;
|
||||||
for ( ; snippetIt != end; ++snippetIt)
|
for ( ; snippetIt != end; ++snippetIt)
|
||||||
|
|
Loading…
Reference in New Issue