diff --git a/BasicNodes/Functions/Matches.cs b/BasicNodes/Functions/Matches.cs index 91ec4bd4..7fea4afd 100644 --- a/BasicNodes/Functions/Matches.cs +++ b/BasicNodes/Functions/Matches.cs @@ -56,15 +56,6 @@ public class Matches : Node args.Logger?.ILog("Testing match value: " + strValue); - if (GeneralHelper.IsRegex(match.Value)) - { - if (Regex.IsMatch(strValue, match.Value, RegexOptions.IgnoreCase | RegexOptions.CultureInvariant)) - { - args.Logger?.ILog($"Match found '{match.Value}' = {strValue}"); - return output; - } - } - if (Regex.IsMatch(match.Value ??string.Empty, "^(true|1)$", RegexOptions.IgnoreCase) && Regex.IsMatch(strValue, "^(true|1)$", RegexOptions.IgnoreCase)) { @@ -78,8 +69,6 @@ public class Matches : Node return output; } - if (args.StringHelper.Matches(strValue, match.Value)) - return output; if (args.MathHelper.IsMathOperation(match.Value)) { @@ -89,6 +78,9 @@ public class Matches : Node return output; } } + + if (args.StringHelper.Matches(match.Value, strValue)) + return output; } catch (Exception) { diff --git a/BasicNodes/Helpers/GeneralHelper.cs b/BasicNodes/Helpers/GeneralHelper.cs deleted file mode 100644 index 3576c144..00000000 --- a/BasicNodes/Helpers/GeneralHelper.cs +++ /dev/null @@ -1,17 +0,0 @@ -namespace FileFlows.BasicNodes.Helpers; - -/// -/// General helper -/// -public class GeneralHelper -{ - /// - /// Checks if the input string represents a regular expression. - /// - /// The input string to check. - /// True if the input is a regular expression, otherwise false. - public static bool IsRegex(string input) - { - return new[] { "?", "|", "^", "$", "*" }.Any(ch => input.Contains(ch)); - } -} \ No newline at end of file diff --git a/BasicNodes/Helpers/MathHelper.cs b/BasicNodes/Helpers/MathHelper.cs deleted file mode 100644 index f20ea268..00000000 --- a/BasicNodes/Helpers/MathHelper.cs +++ /dev/null @@ -1,166 +0,0 @@ -// using System.Globalization; -// -// namespace FileFlows.BasicNodes.Helpers; -// -// /// -// /// Helper for math operations -// /// -// public class MathHelper -// { -// /// -// /// Checks if the comparison string represents a mathematical operation. -// /// -// /// The comparison string to check. -// /// True if the comparison is a mathematical operation, otherwise false. -// public static bool IsMathOperation(string comparison) -// { -// // Check if the comparison string starts with <=, <, >, >=, ==, or = -// return new[] { "<=", "<", ">", ">=", "==", "=" }.Any(comparison.StartsWith); -// } -// -// -// /// -// /// Tests if a math operation is true -// /// -// /// The value to apply the operation to. -// /// The operation string representing the mathematical operation. -// /// True if the mathematical operation is successful, otherwise false. -// public static bool IsTrue(string value, string operation) -// { -// // This is a basic example; you may need to handle different operators -// switch (operation[..2]) -// { -// case "<=": -// return Convert.ToDouble(value) <= Convert.ToDouble(AdjustComparisonValue(operation[2..].Trim())); -// case ">=": -// return Convert.ToDouble(value) >= Convert.ToDouble(AdjustComparisonValue(operation[2..].Trim())); -// case "==": -// return Math.Abs(Convert.ToDouble(value) - Convert.ToDouble(AdjustComparisonValue(operation[2..].Trim()))) < 0.05f; -// case "!=": -// case "<>": -// return Math.Abs(Convert.ToDouble(value) - Convert.ToDouble(AdjustComparisonValue(operation[2..].Trim()))) > 0.05f; -// } -// -// switch (operation[..1]) -// { -// case "<": -// return Convert.ToDouble(value) < Convert.ToDouble(AdjustComparisonValue(operation[1..].Trim())); -// case ">": -// return Convert.ToDouble(value) > Convert.ToDouble(AdjustComparisonValue(operation[1..].Trim())); -// case "=": -// return Math.Abs(Convert.ToDouble(value) - Convert.ToDouble(AdjustComparisonValue(operation[1..].Trim()))) < 0.05f; -// } -// -// return false; -// } -// -// /// -// /// Adjusts the comparison string by handling common mistakes in units and converting them into full numbers. -// /// -// /// The original comparison string to be adjusted. -// /// The adjusted comparison string with corrected units or the original comparison if no adjustments are made. -// private static string AdjustComparisonValue(string comparisonValue) -// { -// if (string.IsNullOrWhiteSpace(comparisonValue)) -// return string.Empty; -// -// string adjustedComparison = comparisonValue.ToLower().Trim(); -// -// // Handle common mistakes in units -// if (adjustedComparison.EndsWith("mbps")) -// { -// // Make an educated guess for Mbps to kbps conversion -// return adjustedComparison[..^4] switch -// { -// { } value when double.TryParse(value, out var numericValue) => (numericValue * 1_000_000) -// .ToString(CultureInfo.InvariantCulture), -// _ => comparisonValue -// }; -// } -// if (adjustedComparison.EndsWith("kbps")) -// { -// // Make an educated guess for kbps to bps conversion -// return adjustedComparison[..^4] switch -// { -// { } value when double.TryParse(value, out var numericValue) => (numericValue * 1_000) -// .ToString(CultureInfo.InvariantCulture), -// _ => comparisonValue -// }; -// } -// if (adjustedComparison.EndsWith("kb")) -// { -// return adjustedComparison[..^2] switch -// { -// { } value when double.TryParse(value, out var numericValue) => (numericValue * 1_000 ) -// .ToString(CultureInfo.InvariantCulture), -// _ => comparisonValue -// }; -// } -// if (adjustedComparison.EndsWith("mb")) -// { -// return adjustedComparison[..^2] switch -// { -// { } value when double.TryParse(value, out var numericValue) => (numericValue * 1_000_000 ) -// .ToString(CultureInfo.InvariantCulture), -// _ => comparisonValue -// }; -// } -// if (adjustedComparison.EndsWith("gb")) -// { -// return adjustedComparison[..^2] switch -// { -// { } value when double.TryParse(value, out var numericValue) => (numericValue * 1_000_000_000 ) -// .ToString(CultureInfo.InvariantCulture), -// _ => comparisonValue -// }; -// } -// if (adjustedComparison.EndsWith("tb")) -// { -// return adjustedComparison[..^2] switch -// { -// { } value when double.TryParse(value, out var numericValue) => (numericValue * 1_000_000_000_000) -// .ToString(CultureInfo.InvariantCulture), -// _ => comparisonValue -// }; -// } -// -// if (adjustedComparison.EndsWith("kib")) -// { -// return adjustedComparison[..^3] switch -// { -// { } value when double.TryParse(value, out var numericValue) => (numericValue * 1_024 ) -// .ToString(CultureInfo.InvariantCulture), -// _ => comparisonValue -// }; -// } -// if (adjustedComparison.EndsWith("mib")) -// { -// return adjustedComparison[..^3] switch -// { -// { } value when double.TryParse(value, out var numericValue) => (numericValue * 1_048_576 ) -// .ToString(CultureInfo.InvariantCulture), -// _ => comparisonValue -// }; -// } -// if (adjustedComparison.EndsWith("gib")) -// { -// return adjustedComparison[..^3] switch -// { -// { } value when double.TryParse(value, out var numericValue) => (numericValue * 1_099_511_627_776 ) -// .ToString(CultureInfo.InvariantCulture), -// _ => comparisonValue -// }; -// } -// if (adjustedComparison.EndsWith("tib")) -// { -// return adjustedComparison[..^3] switch -// { -// { } value when double.TryParse(value, out var numericValue) => (numericValue * 1_000_000_000_000) -// .ToString(CultureInfo.InvariantCulture), -// _ => comparisonValue -// }; -// } -// return comparisonValue; -// } -// -// } \ No newline at end of file diff --git a/BasicNodes/Tests/MatchesTests.cs b/BasicNodes/Tests/MatchesTests.cs index 81ab057b..727defc3 100644 --- a/BasicNodes/Tests/MatchesTests.cs +++ b/BasicNodes/Tests/MatchesTests.cs @@ -112,9 +112,9 @@ public class MatchesTests : TestBase Matches ele = new (); ele.MatchConditions = new() { - new("{file.Name}", "triggerthis"), - new("{file.Name}", ".*batman.*"), - new("{file.Name}", "TriggerThis"), + new("{file.Name}", "/triggerthis/"), + new("{file.Name}", "/.*batman.*/"), + new("{file.Name}", "/TriggerThis/"), }; var args = new FileFlows.Plugin.NodeParameters(null, Logger, false, string.Empty, new LocalFileService());