mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[Filter] Internally use regex in preparation for external usage
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
using SabreTools.Helper.Data;
|
using SabreTools.Helper.Data;
|
||||||
|
|
||||||
@@ -468,6 +469,7 @@ 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 found = false;
|
bool found = false;
|
||||||
@@ -475,34 +477,11 @@ namespace SabreTools.Helper.Dats
|
|||||||
{
|
{
|
||||||
if (!String.IsNullOrEmpty(straw))
|
if (!String.IsNullOrEmpty(straw))
|
||||||
{
|
{
|
||||||
if (straw.StartsWith("*") && straw.EndsWith("*"))
|
// Pre-process the straw to make it regex-compatibile
|
||||||
{
|
string regexStraw = "^" + (straw.StartsWith("*") ? ".*" : "") + Regex.Escape(straw.Trim('*')) + (straw.EndsWith("*") ? ".*" : "") + "$";
|
||||||
if (needle.ToLowerInvariant().Contains(straw.ToLowerInvariant().Replace("*", "")))
|
|
||||||
{
|
// Check if a match is found with the regex
|
||||||
found = true;
|
found |= Regex.IsMatch(needle, straw, RegexOptions.IgnoreCase);
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (straw.StartsWith("*"))
|
|
||||||
{
|
|
||||||
if (needle.EndsWith(straw.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase))
|
|
||||||
{
|
|
||||||
found = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (straw.EndsWith("*"))
|
|
||||||
{
|
|
||||||
if (needle.StartsWith(straw.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase))
|
|
||||||
{
|
|
||||||
found = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (String.Equals(needle, straw, StringComparison.InvariantCultureIgnoreCase))
|
|
||||||
{
|
|
||||||
found = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user