Introduced String Regex Condition Operator

Require complete string to be a full match

Changed to DarthAffe suggestion

Changed to fit new Condition API and match code style
This commit is contained in:
Felix Lehmann committed 2020-10-21 21:28:34 +02:00
1 parent d8d54cff01
commit 648f01e160
2 files changed
+21

No files matched your search

@@ -0,0 +1,20 @@
using System.Text.RegularExpressions;
namespace Artemis.Core.DefaultTypes {
internal class StringMatchesRegexConditionOperator : ConditionOperator<string, string>
{
public override string Description => "Matches Regex";
public override string Icon => "Regex";
public override bool Evaluate(string text, string regex)
{
// Ensures full match
if (!regex.StartsWith("^"))
regex = "^" + regex;
if (!regex.EndsWith("$"))
regex += "$";
return Regex.IsMatch(text, regex);
}
}
}
@@ -61,6 +61,7 @@ namespace Artemis.Core.Services
RegisterConditionOperator(Constants.CorePluginInfo, new StringNotContainsConditionOperator()); RegisterConditionOperator(Constants.CorePluginInfo, new StringNotContainsConditionOperator());
RegisterConditionOperator(Constants.CorePluginInfo, new StringStartsWithConditionOperator()); RegisterConditionOperator(Constants.CorePluginInfo, new StringStartsWithConditionOperator());
RegisterConditionOperator(Constants.CorePluginInfo, new StringEndsWithConditionOperator()); RegisterConditionOperator(Constants.CorePluginInfo, new StringEndsWithConditionOperator());
RegisterConditionOperator(Constants.CorePluginInfo, new StringMatchesRegexConditionOperator());
// Null checks, at the bottom // Null checks, at the bottom
// TODO: Implement a priority mechanism // TODO: Implement a priority mechanism