qzdoom/wadsrc/static/zscript/ui/menu/search/query.zs
alexey.lysiuk 6d1a85af3c - fixed deprecation warnings in core scripts
Script warning, "gzdoom.pk3:zscript/ui/statscreen/statscreen.zs" line 24:
Call to deprecated function CharAt
Script warning, "gzdoom.pk3:zscript/ui/statscreen/statscreen.zs" line 24:
Accessing deprecated function CharAt - deprecated since 4.1.0
Script warning, "gzdoom.pk3:zscript/ui/menu/search/query.zs" line 64:
Call to deprecated function ToLower
Script warning, "gzdoom.pk3:zscript/ui/menu/search/query.zs" line 64:
Accessing deprecated function ToLower - deprecated since 4.1.0
Script warning, "gzdoom.pk3:zscript/ui/menu/search/query.zs" line 65:
Call to deprecated function ToLower
Script warning, "gzdoom.pk3:zscript/ui/menu/search/query.zs" line 65:
Accessing deprecated function ToLower - deprecated since 4.1.0
Script warning, "gzdoom.pk3:zscript/ui/menu/conversationmenu.zs" line 202:
Call to deprecated function CharAt
Script warning, "gzdoom.pk3:zscript/ui/menu/conversationmenu.zs" line 202:
Accessing deprecated function CharAt - deprecated since 4.1.0
Script warning, "gzdoom.pk3:zscript/ui/menu/conversationmenu.zs" line 235:
Call to deprecated function CharAt
Script warning, "gzdoom.pk3:zscript/ui/menu/conversationmenu.zs" line 235:
Accessing deprecated function CharAt - deprecated since 4.1.0
2019-04-28 11:26:01 +03:00

73 lines
1.6 KiB
Text

//=============================================================================
//
// Option Search Query class represents a search query.
// A search query consists constists of one or more terms (words).
//
// Query matching deponds on "os_is_any_of" variable.
// If this variable is "true", the text matches the query if any of the terms
// matches the query.
// If this variable is "false", the text matches the query only if all the
// terms match the query.
//
//=============================================================================
class os_Query
{
static os_Query fromString(string str)
{
let query = new("os_Query");
str.Split(query.mQueryParts, " ", TOK_SKIPEMPTY);
return query;
}
bool matches(string text, bool isSearchForAny)
{
return isSearchForAny
? matchesAny(text)
: matchesAll(text);
}
// private: //////////////////////////////////////////////////////////////////
private bool matchesAny(string text)
{
int nParts = mQueryParts.size();
for (int i = 0; i < nParts; ++i)
{
string queryPart = mQueryParts[i];
if (contains(text, queryPart)) { return true; }
}
return false;
}
private bool matchesAll(string text)
{
int nParts = mQueryParts.size();
for (int i = 0; i < nParts; ++i)
{
string queryPart = mQueryParts[i];
if (!contains(text, queryPart)) { return false; }
}
return true;
}
private static bool contains(string str, string substr)
{
let lowerstr = str .MakeLower();
let lowersubstr = substr.MakeLower();
bool contains = (lowerstr.IndexOf(lowersubstr) != -1);
return contains;
}
private Array<String> mQueryParts;
}