mirror of
https://github.com/SabreTools/BinaryObjectScanner.git
synced 2026-09-23 07:14:49 +00:00
Add invariance
This commit is contained in:
@@ -100,7 +100,7 @@ namespace BurnOutSharp.Matching
|
||||
/// Determine whether all content matches pass
|
||||
/// </summary>
|
||||
/// <param name="fileContent">Byte array representing the file contents</param>
|
||||
/// <returns>Tuole of passing status and matching positions</returns>
|
||||
/// <returns>Tuple of passing status and matching positions</returns>
|
||||
public (bool, List<int>) MatchesAll(byte[] fileContent)
|
||||
{
|
||||
// If no content matches are defined, we fail out
|
||||
@@ -127,7 +127,7 @@ namespace BurnOutSharp.Matching
|
||||
/// Determine whether all content matches pass
|
||||
/// </summary>
|
||||
/// <param name="stack">List of strings to try to match</param>
|
||||
/// <returns>Tuole of passing status and matching values</returns>
|
||||
/// <returns>Tuple of passing status and matching values</returns>
|
||||
public (bool, List<string>) MatchesAll(List<string> stack)
|
||||
{
|
||||
// If no path matches are defined, we fail out
|
||||
@@ -154,7 +154,7 @@ namespace BurnOutSharp.Matching
|
||||
/// Determine whether any content matches pass
|
||||
/// </summary>
|
||||
/// <param name="stack">List of strings to try to match</param>
|
||||
/// <returns>Tuole of passing status and matching values</returns>
|
||||
/// <returns>Tuple of passing status and matching values</returns>
|
||||
public (bool, string) MatchesAny(List<string> stack)
|
||||
{
|
||||
// If no path matches are defined, we fail out
|
||||
|
||||
@@ -12,14 +12,20 @@ namespace BurnOutSharp.Matching
|
||||
/// </summary>
|
||||
public string Needle { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Match exact casing instead of invariant
|
||||
/// </summary>
|
||||
public bool MatchExact { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Match that values end with the needle and not just contains
|
||||
/// </summary>
|
||||
public bool UseEndsWith { get; set; }
|
||||
|
||||
public PathMatch(string needle, bool useEndsWith = false)
|
||||
public PathMatch(string needle, bool matchExact = false, bool useEndsWith = false)
|
||||
{
|
||||
Needle = needle;
|
||||
MatchExact = matchExact;
|
||||
UseEndsWith = useEndsWith;
|
||||
}
|
||||
|
||||
@@ -35,11 +41,17 @@ namespace BurnOutSharp.Matching
|
||||
if (stack == null || stack.Count == 0 || Needle == null || Needle.Length == 0)
|
||||
return (false, null);
|
||||
|
||||
// Preprocess the needle, if necessary
|
||||
string procNeedle = MatchExact ? Needle : Needle.ToLowerInvariant();
|
||||
|
||||
foreach (string stackItem in stack)
|
||||
{
|
||||
if (UseEndsWith && stackItem.EndsWith(Needle))
|
||||
// Preprocess the stack item, ir necessary
|
||||
string procStackItem = MatchExact ? stackItem : stackItem.ToLowerInvariant();
|
||||
|
||||
if (UseEndsWith && procStackItem.EndsWith(procNeedle))
|
||||
return (true, stackItem);
|
||||
else if (!UseEndsWith && stackItem.Contains(Needle))
|
||||
else if (!UseEndsWith && procStackItem.Contains(procNeedle))
|
||||
return (true, stackItem);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user