Fix positioning of matches in search::search().

This commit is contained in:
tastytea 2021-06-06 22:34:52 +02:00
parent 5e89a71e00
commit 1e29608c7e
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
1 changed files with 3 additions and 2 deletions

View File

@ -96,6 +96,7 @@ std::vector<match> search(const fs::path &filepath,
string::const_iterator begin{file.text.begin()};
string::const_iterator end{file.text.end()};
auto begin_text{begin};
boost::match_results<string::const_iterator> match_result;
while (boost::regex_search(begin, end, match_result, re,
@ -107,12 +108,12 @@ std::vector<match> search(const fs::path &filepath,
match.text = match_result[0];
match.context = context(match_result, opts.context);
const auto pos = static_cast<size_t>(
std::distance(begin, match_result[0].begin()));
std::distance(begin_text, match_result[0].begin()));
match.headline = headline(file, pos);
match.page = page(file, pos);
matches.emplace_back(match);
begin = match_result[0].second;
begin = match_result[0].end();
}
}