SearchQuery.h 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. #pragma once
  2. // Browser search queries (docs/WORKFLOW_FL.md P2: browser search). Case-insensitive (ASCII) matching of
  3. // file names against a small query language:
  4. // kick snare both words (AND; "AND" may also be written)
  5. // kick OR snare either side of OR (OR binds looser than AND)
  6. // NOT loop / -loop excludes names containing the word
  7. // "808 kick" the exact phrase
  8. // kick*.wav, h?t wildcards: * any run of characters, ? any one character (the whole name must match)
  9. // An empty query matches everything.
  10. #include <string>
  11. #include <vector>
  12. namespace lynx::search
  13. {
  14. struct Term
  15. {
  16. std::string text; // lower-case
  17. bool negated = false;
  18. bool wildcard = false; // contains * or ?: matched against the whole name
  19. };
  20. // Groups of AND-ed terms, OR-ed together.
  21. using Query = std::vector<std::vector<Term>>;
  22. Query parse (const std::string& query);
  23. bool matches (const Query& query, const std::string& name);
  24. bool matches (const std::string& query, const std::string& name);
  25. // Wildcard match of the whole text (* and ?), case-insensitive.
  26. bool wildcardMatch (const std::string& pattern, const std::string& text);
  27. } // namespace lynx::search