Added new MatchesRegex and DoesNotMatchRegex comparers for keys and IF/WHILE statements.

This commit is contained in:
ruri
2019-05-03 18:24:04 +02:00
parent 2a6d7a497d
commit d74e1077ff
+14 -1
View File
@@ -1,6 +1,7 @@
using System;
using System.Globalization;
using System.Linq;
using System.Text.RegularExpressions;
namespace RuriLib
{
@@ -31,7 +32,13 @@ namespace RuriLib
Exists,
/// <summary>Whether no variable can be replaced inside the string.</summary>
DoesNotExist
DoesNotExist,
/// <summary>A matches regex pattern B.</summary>
MatchesRegex,
/// <summary>A does not match regex pattern B.</summary>
DoesNotMatchRegex
}
/// <summary>
@@ -80,6 +87,12 @@ namespace RuriLib
case Condition.DoesNotExist:
return L.All(l => l == left); // Returns true if no replacement took place
case Condition.MatchesRegex:
return L.Any(l => Regex.Match(l, r).Success);
case Condition.DoesNotMatchRegex:
return L.Any(l => !Regex.Match(l, r).Success);
default:
return false;
}