aseprite/src/app/match_words.h
David Capello b6cf0f218c Add search field on Font Popup
Added support to set child visibility property to ListBox items.
2017-03-15 14:24:42 -03:00

45 lines
919 B
C++

// Aseprite
// Copyright (C) 2017 David Capello
//
// This program is distributed under the terms of
// the End-User License Agreement for Aseprite.
#ifndef APP_MATCH_WORDS_H_INCLUDED
#define APP_MATCH_WORDS_H_INCLUDED
#pragma once
#include "base/split_string.h"
#include "base/string.h"
#include <string>
#include <vector>
namespace app {
class MatchWords {
public:
MatchWords(const std::string& search) {
base::split_string(base::string_to_lower(search),
m_parts, " ");
}
bool operator()(const std::string& item) {
std::string lowerItem = base::string_to_lower(item);
std::size_t matches = 0;
for (const auto& part : m_parts) {
if (lowerItem.find(part) != std::string::npos)
++matches;
}
return (matches == m_parts.size());
}
private:
std::vector<std::string> m_parts;
};
} // namespace app
#endif