mirror of https://github.com/kiwix/libkiwix.git
Moved a function
This commit is contained in:
parent
0340a49780
commit
7d4867194a
|
@ -546,11 +546,27 @@ const std::vector<SearchResult> LARGE_SEARCH_RESULTS = {
|
|||
// - Non-overlapping snippets can be joined with a " ... " in between.
|
||||
//
|
||||
|
||||
typedef std::vector<std::string> Snippets;
|
||||
|
||||
std::string maskSnippetsInHtmlSearchResults(std::string s)
|
||||
{
|
||||
return replace(s, "<cite>.+</cite>", "<cite>SNIPPET TEXT WAS MASKED</cite>");
|
||||
}
|
||||
|
||||
Snippets extractSearchResultSnippetsFromHtml(const std::string& html)
|
||||
{
|
||||
Snippets snippets;
|
||||
const std::regex snippetRegex("<cite>(.*)</cite>");
|
||||
std::sregex_iterator snippetIt(html.begin(), html.end(), snippetRegex);
|
||||
const std::sregex_iterator end;
|
||||
for ( ; snippetIt != end; ++snippetIt)
|
||||
{
|
||||
const std::smatch snippetMatch = *snippetIt;
|
||||
snippets.push_back(snippetMatch[1].str());
|
||||
}
|
||||
return snippets;
|
||||
}
|
||||
|
||||
bool isValidSnippet(const std::string& s)
|
||||
{
|
||||
return s.size() >= 250
|
||||
|
@ -731,22 +747,6 @@ struct TestData
|
|||
checkSnippets(extractSearchResultSnippetsFromHtml(html));
|
||||
}
|
||||
|
||||
typedef std::vector<std::string> Snippets;
|
||||
|
||||
static Snippets extractSearchResultSnippetsFromHtml(const std::string& html)
|
||||
{
|
||||
Snippets snippets;
|
||||
const std::regex snippetRegex("<cite>(.*)</cite>");
|
||||
std::sregex_iterator snippetIt(html.begin(), html.end(), snippetRegex);
|
||||
const std::sregex_iterator end;
|
||||
for ( ; snippetIt != end; ++snippetIt)
|
||||
{
|
||||
const std::smatch snippetMatch = *snippetIt;
|
||||
snippets.push_back(snippetMatch[1].str());
|
||||
}
|
||||
return snippets;
|
||||
}
|
||||
|
||||
void checkSnippets(const Snippets& snippets) const
|
||||
{
|
||||
ASSERT_EQ(snippets.size(), results.size());
|
||||
|
|
Loading…
Reference in New Issue