mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[Filter] Fully enable regex matching
This commit is contained in:
@@ -469,19 +469,15 @@ namespace SabreTools.Helper.Dats
|
|||||||
/// <param name="haystack">List to search for the value in</param>
|
/// <param name="haystack">List to search for the value in</param>
|
||||||
/// <param name="needle">Value to search the list for</param>
|
/// <param name="needle">Value to search the list for</param>
|
||||||
/// <returns>True if the value could be found, false otherwise</returns>
|
/// <returns>True if the value could be found, false otherwise</returns>
|
||||||
/// <remarks>TODO: Add proper regex matching to all strings</remarks>
|
private bool FindValueInList(List<string> haystack, string needle)
|
||||||
private bool FindValueInList(List<string> haystack, string needle, bool regex = false)
|
|
||||||
{
|
{
|
||||||
bool found = false;
|
bool found = false;
|
||||||
foreach (string straw in haystack)
|
foreach (string straw in haystack)
|
||||||
{
|
{
|
||||||
if (!String.IsNullOrEmpty(straw))
|
if (!String.IsNullOrEmpty(straw))
|
||||||
{
|
{
|
||||||
// Pre-process the straw to make it regex-compatibile
|
|
||||||
string regexStraw = (!regex ? "^" + (straw.StartsWith("*") ? ".*" : "") + Regex.Escape(straw.Trim('*')) + (straw.EndsWith("*") ? ".*" : "") + "$" : straw);
|
|
||||||
|
|
||||||
// Check if a match is found with the regex
|
// Check if a match is found with the regex
|
||||||
found |= Regex.IsMatch(needle, regexStraw, RegexOptions.IgnoreCase);
|
found |= Regex.IsMatch(needle, straw, RegexOptions.IgnoreCase);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -955,13 +955,9 @@ Options:
|
|||||||
-nmd5=, --not-md5= Exclude by MD5 hash
|
-nmd5=, --not-md5= Exclude by MD5 hash
|
||||||
-sha1=, --sha1= Filter by SHA-1 hash
|
-sha1=, --sha1= Filter by SHA-1 hash
|
||||||
-nsha1=, --not-sha1= Exclude by SHA-1 hash
|
-nsha1=, --not-sha1= Exclude by SHA-1 hash
|
||||||
For each of the flags above, the user can specify either an exact match or can use a
|
For each of the flags above, the user can specify either an exact match or can use
|
||||||
wildcard as defined below (case-insensitive):
|
full C#-style regex for pattern matching. Multiples of each of the above inputs are
|
||||||
*00 means ends with '00'
|
allowed.
|
||||||
00* means starts with '00'
|
|
||||||
*00* means contains '00'
|
|
||||||
00 means exactly equals '00'
|
|
||||||
Multiples of each of the above inputs are allowed.
|
|
||||||
|
|
||||||
-ofg, --of-as-game Allow cloneof and romof tags to match game name filters
|
-ofg, --of-as-game Allow cloneof and romof tags to match game name filters
|
||||||
If filter or exclude by game name is used, this flag will allow those filters to
|
If filter or exclude by game name is used, this flag will allow those filters to
|
||||||
|
|||||||
@@ -647,11 +647,7 @@ namespace SabreTools
|
|||||||
|
|
||||||
"",
|
"",
|
||||||
"Filter parameters game name, rom name, CRC, MD5, SHA-1 can",
|
"Filter parameters game name, rom name, CRC, MD5, SHA-1 can",
|
||||||
"do partial matches using asterisks as follows (case insensitive):",
|
"be matched using full C#-style regex.",
|
||||||
" *00 means ends with '00'",
|
|
||||||
" 00* means starts with '00'",
|
|
||||||
" *00* means contains '00'",
|
|
||||||
" 00 means exactly equals '00'",
|
|
||||||
|
|
||||||
"",
|
"",
|
||||||
"Filter parameters for size can use postfixes for inputs:",
|
"Filter parameters for size can use postfixes for inputs:",
|
||||||
|
|||||||
Reference in New Issue
Block a user