Find and remove specified line from g_output. Return true if found, otherwise, false.
| 69 | // Find and remove specified line from g_output. |
| 70 | // Return true if found, otherwise, false. |
| 71 | bool LogGuard::findAndRemove(const std::string & line) const |
| 72 | { |
| 73 | // Escape the line to prevent error in regex if the line contains regex character. |
| 74 | std::string escaped_line = std::regex_replace(line, std::regex("[\\[\\](){}*+?.^$|\\\\]"), "\\$&"); |
| 75 | std::regex pattern(escaped_line + R"([\r\n]+)"); |
| 76 | std::smatch match; |
| 77 | if (std::regex_search(g_output, match, pattern)) |
| 78 | { |
| 79 | // If the line is found, remove it. |
| 80 | auto pos = std::next(g_output.begin(), match.position()); |
| 81 | auto end = std::next(pos, match.length()); |
| 82 | g_output.erase(pos, end); |
| 83 | return true; |
| 84 | } |
| 85 | return false; |
| 86 | } |
| 87 | |
| 88 | bool LogGuard::findAllAndRemove(const std::string & sPattern) const |
| 89 | { |
no test coverage detected