Log filter: match case-insensitively
The Log window's filter used a case-sensitive substring match, so "error" missed "ERROR" -- inconsistent with the rest of the app. Match case-insensitively. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
#include "log_panel.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
|
||||
#include "imgui.h"
|
||||
|
||||
@@ -11,6 +14,24 @@
|
||||
namespace coop
|
||||
{
|
||||
|
||||
namespace
|
||||
{
|
||||
// Case-insensitive substring test, so the log filter matches regardless of case (consistent with the
|
||||
// rest of the app, where "error" should find "ERROR").
|
||||
bool icontains(const std::string& hay, const char* needle)
|
||||
{
|
||||
if (needle == nullptr || needle[0] == '\0')
|
||||
{
|
||||
return true;
|
||||
}
|
||||
auto lower = [](std::string s) {
|
||||
std::transform(s.begin(), s.end(), s.begin(), [](unsigned char c) { return static_cast<char>(std::tolower(c)); });
|
||||
return s;
|
||||
};
|
||||
return lower(hay).find(lower(needle)) != std::string::npos;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
void LogPanel::add_line(const LogRecord& rec)
|
||||
{
|
||||
if (first_millis_ == 0)
|
||||
@@ -55,7 +76,7 @@ void LogPanel::draw()
|
||||
const bool has_filter = filter_[0] != '\0';
|
||||
for (const Line& line : lines_)
|
||||
{
|
||||
if (has_filter && line.text.find(filter_) == std::string::npos)
|
||||
if (has_filter && !icontains(line.text, filter_))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user