[Filter] Add unused flag for regex compatibile level

This commit is contained in:
Matt Nadareski
2017-02-08 20:38:29 -08:00
parent 40e0e14751
commit 5eb517780c

View File

@@ -470,7 +470,7 @@ namespace SabreTools.Helper.Dats
/// <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> /// <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)
@@ -478,7 +478,7 @@ namespace SabreTools.Helper.Dats
if (!String.IsNullOrEmpty(straw)) if (!String.IsNullOrEmpty(straw))
{ {
// Pre-process the straw to make it regex-compatibile // Pre-process the straw to make it regex-compatibile
string regexStraw = "^" + (straw.StartsWith("*") ? ".*" : "") + Regex.Escape(straw.Trim('*')) + (straw.EndsWith("*") ? ".*" : "") + "$"; 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, straw, RegexOptions.IgnoreCase); found |= Regex.IsMatch(needle, straw, RegexOptions.IgnoreCase);