Skip to content

Commit

Permalink
LibGUI: Add possibility to search for exact match in model
Browse files Browse the repository at this point in the history
  • Loading branch information
speles authored and awesomekling committed Mar 1, 2021
1 parent dff31d5 commit aa9c5d4
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Userland/Libraries/LibGUI/Model.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class Model : public RefCounted<Model> {
FirstMatchOnly = 1 << 0,
CaseInsensitive = 1 << 1,
MatchAtStart = 1 << 2,
MatchFull = 1 << 3,
};

virtual ~Model();
Expand Down Expand Up @@ -112,6 +113,8 @@ class Model : public RefCounted<Model> {
static bool string_matches(const StringView& str, const StringView& needle, unsigned flags)
{
auto case_sensitivity = (flags & CaseInsensitive) ? CaseSensitivity::CaseInsensitive : CaseSensitivity::CaseSensitive;
if (flags & MatchFull)
return str.length() == needle.length() && str.starts_with(needle, case_sensitivity);
if (flags & MatchAtStart)
return str.starts_with(needle, case_sensitivity);
return str.contains(needle, case_sensitivity);
Expand Down

0 comments on commit aa9c5d4

Please sign in to comment.