From e1d29c5893165e55bd6e9edbef98d6b455c97c8c Mon Sep 17 00:00:00 2001 From: tastytea Date: Mon, 24 May 2021 19:58:59 +0200 Subject: [PATCH] Don't replace stuff in search::cleanup_text() if nothing matched. --- src/search.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/search.cpp b/src/search.cpp index 8434945..70ce197 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -104,7 +104,8 @@ std::vector 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, " "); }