| 1 | // Aseprite |
| 2 | // Copyright (C) 2017 David Capello |
| 3 | // |
| 4 | // This program is distributed under the terms of |
| 5 | // the End-User License Agreement for Aseprite. |
| 6 | |
| 7 | #ifndef APP_MATCH_WORDS_H_INCLUDED |
| 8 | #define APP_MATCH_WORDS_H_INCLUDED |
| 9 | #pragma once |
| 10 | |
| 11 | #include "base/split_string.h" |
| 12 | #include "base/string.h" |
| 13 | |
| 14 | #include <string> |
| 15 | #include <vector> |
| 16 | |
| 17 | namespace app { |
| 18 | |
| 19 | class MatchWords { |
| 20 | public: |
| 21 | MatchWords(const std::string& search) { |
| 22 | base::split_string(base::string_to_lower(search), |
| 23 | m_parts, " " ); |
| 24 | } |
| 25 | |
| 26 | bool operator()(const std::string& item) { |
| 27 | std::string lowerItem = base::string_to_lower(item); |
| 28 | std::size_t matches = 0; |
| 29 | |
| 30 | for (const auto& part : m_parts) { |
| 31 | if (lowerItem.find(part) != std::string::npos) |
| 32 | ++matches; |
| 33 | } |
| 34 | |
| 35 | return (matches == m_parts.size()); |
| 36 | } |
| 37 | |
| 38 | private: |
| 39 | std::vector<std::string> m_parts; |
| 40 | }; |
| 41 | |
| 42 | } // namespace app |
| 43 | |
| 44 | #endif |
| 45 | |