1#ifndef YAZE_APP_GUI_CORE_SEARCH_H
2#define YAZE_APP_GUI_CORE_SEARCH_H
23inline bool FuzzyMatch(
const std::string& pattern,
const std::string& str) {
24 if (pattern.empty())
return true;
25 if (str.empty())
return false;
27 size_t pattern_idx = 0;
29 if (std::tolower(
static_cast<unsigned char>(c)) ==
30 std::tolower(
static_cast<unsigned char>(pattern[pattern_idx]))) {
32 if (pattern_idx >= pattern.length())
return true;
50inline int FuzzyScore(
const std::string& pattern,
const std::string& str) {
51 if (pattern.empty())
return 100;
54 std::string lower_pattern, lower_str;
55 lower_pattern.reserve(pattern.size());
56 lower_str.reserve(str.size());
58 for (
char c : pattern)
59 lower_pattern +=
static_cast<char>(
60 std::tolower(
static_cast<unsigned char>(c)));
62 lower_str +=
static_cast<char>(
63 std::tolower(
static_cast<unsigned char>(c)));
65 if (lower_str.find(lower_pattern) == 0)
return 100;
66 if (lower_str.find(lower_pattern) != std::string::npos)
return 80;
76inline bool PassesFilter(
const std::string& filter,
const std::string& str) {
77 if (filter.empty())
return true;
88 const std::vector<std::string>& strings) {
89 if (filter.empty())
return true;
90 for (
const auto& str : strings) {
bool PassesFilter(const std::string &filter, const std::string &str)
Check if a string matches a search filter.
bool FuzzyMatch(const std::string &pattern, const std::string &str)
Simple fuzzy match - returns true if all chars in pattern appear in str in order.
bool AnyPassesFilter(const std::string &filter, const std::vector< std::string > &strings)
Check if any of multiple strings match a search filter.
int FuzzyScore(const std::string &pattern, const std::string &str)
Score a fuzzy match (higher = better, 0 = no match)