Don't replace stuff in search::cleanup_text() if nothing matched.

This commit is contained in:
tastytea 2021-05-24 19:58:59 +02:00
parent 09090a1c13
commit e1d29c5893
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
1 changed files with 8 additions and 4 deletions

View File

@ -104,7 +104,8 @@ std::vector<match> search(const fs::path &filepath, std::string_view regex,
void cleanup_text(std::string &text)
{
for (size_t pos{}; pos != std::string::npos; pos = text.find('<', pos))
size_t pos{};
while ((pos = text.find('<', pos)) != std::string::npos)
{
// Mark headlines. We need them later on.
std::string replacement;
@ -133,17 +134,20 @@ void cleanup_text(std::string &text)
pos += replacement.length();
}
for (size_t pos{}; pos != std::string::npos; pos = text.find('\r', pos))
pos = 0;
while ((pos = text.find('\r', pos)) != std::string::npos)
{
text.erase(pos, 1);
}
for (size_t pos{}; pos != std::string::npos; pos = text.find('\n', pos))
pos = 0;
while ((pos = text.find('\n', pos)) != std::string::npos)
{
text.replace(pos, 1, " ");
}
for (size_t pos{}; pos != std::string::npos; pos = text.find(" ", pos))
pos = 0;
while ((pos = text.find(" ", pos)) != std::string::npos)
{
text.replace(pos, 2, " ");
}