punish v6.8.18.0
This commit is contained in:
commit
cfb4dea47e
316 changed files with 554088 additions and 0 deletions
49
Questionable/Questionable.Model/StringOrRegex.cs
Normal file
49
Questionable/Questionable.Model/StringOrRegex.cs
Normal file
|
@ -0,0 +1,49 @@
|
|||
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;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue