using System; using System.Text.RegularExpressions; using Questionable.Functions; namespace Questionable.Model; internal sealed class StringOrRegex { private readonly Regex? _regex; private readonly string? _stringValue; public StringOrRegex(Regex? regex) { ArgumentNullException.ThrowIfNull(regex, "regex"); _regex = regex; _stringValue = null; } public StringOrRegex(string? str) { ArgumentNullException.ThrowIfNull(str, "str"); _regex = null; _stringValue = str; } public bool IsMatch(string other) { if (_regex != null) { return _regex.IsMatch(other); } return GameFunctions.GameStringEquals(_stringValue, other); } public string? GetString() { if (_stringValue == null) { throw new InvalidOperationException(); } return _stringValue; } public override string? ToString() { return _regex?.ToString() ?? _stringValue; } }