mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 21:27:34 +00:00
LibGUI: Add possibility to search for exact match in model
This commit is contained in:
parent
dff31d5885
commit
aa9c5d4418
1 changed files with 3 additions and 0 deletions
|
@ -66,6 +66,7 @@ public:
|
||||||
FirstMatchOnly = 1 << 0,
|
FirstMatchOnly = 1 << 0,
|
||||||
CaseInsensitive = 1 << 1,
|
CaseInsensitive = 1 << 1,
|
||||||
MatchAtStart = 1 << 2,
|
MatchAtStart = 1 << 2,
|
||||||
|
MatchFull = 1 << 3,
|
||||||
};
|
};
|
||||||
|
|
||||||
virtual ~Model();
|
virtual ~Model();
|
||||||
|
@ -112,6 +113,8 @@ protected:
|
||||||
static bool string_matches(const StringView& str, const StringView& needle, unsigned flags)
|
static bool string_matches(const StringView& str, const StringView& needle, unsigned flags)
|
||||||
{
|
{
|
||||||
auto case_sensitivity = (flags & CaseInsensitive) ? CaseSensitivity::CaseInsensitive : CaseSensitivity::CaseSensitive;
|
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)
|
if (flags & MatchAtStart)
|
||||||
return str.starts_with(needle, case_sensitivity);
|
return str.starts_with(needle, case_sensitivity);
|
||||||
return str.contains(needle, case_sensitivity);
|
return str.contains(needle, case_sensitivity);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue