Moved a function

This commit is contained in:
Veloman Yunkan 2022-06-05 00:32:04 +04:00 committed by Matthieu Gautier
parent 0340a49780
commit 7d4867194a
1 changed files with 16 additions and 16 deletions

View File

@ -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());