BunyMuny/Rule.cs
Lynnesbian 2f6818aa5d
All checks were successful
continuous-integration/drone/push Build is passing
print out a nice summary at the end =u=
2020-09-27 13:59:58 +10:00

40 lines
1 KiB
C#

using System;
using System.Text.RegularExpressions;
namespace BunyMuny {
public class Rule {
public RuleMatch Match { get; set; }
public string Value { get; set; }
public string Category { get; set; }
public string Description { get; set; }
public bool CaseSensitive { get; set; } // TODO: make this have an effect
/// <summary>
/// Checks whether or not a given value matches the rule.
/// </summary>
/// <param name="input">The string to check against the rule's Value.</param>
/// <returns></returns>
public bool Check(string input) {
var value = Value;
if (!CaseSensitive) {
input = input.ToLower();
value = value.ToLower();
}
switch (Match) {
case RuleMatch.Exact:
return input == value;
case RuleMatch.Start:
return input.StartsWith(value);
case RuleMatch.End:
return input.EndsWith(value);
case RuleMatch.Regex:
var re = new Regex(value);
return re.IsMatch(input);
case RuleMatch.Contains:
return input.Contains(value);
default:
return false;
}
}
}
}