namespace Zinnia.Pattern
{
using System.Text.RegularExpressions;
using UnityEngine;
///
/// A base to describe how to match a source string to a given pattern via a regular expression.
///
public abstract class PatternMatcher : MonoBehaviour
{
[Tooltip("The pattern to match the source against.")]
[SerializeField]
private string pattern;
///
/// The pattern to match the source against.
///
public string Pattern
{
get
{
return pattern;
}
set
{
pattern = value;
}
}
///
/// The current value of the source string.
///
public string SourceValue { get; protected set; }
///
/// Processes the source string to match against.
///
/// The string to match against.
public virtual string ProcessSourceString()
{
SourceValue = DefineSourceString();
return SourceValue;
}
///
/// Determines whether the given matches against the source string.
///
///
public virtual bool DoMatch()
{
return Regex.IsMatch(ProcessSourceString(), Pattern);
}
///
/// Defindes the source string to match against.
///
/// The string to match against.
protected abstract string DefineSourceString();
protected virtual void OnEnable()
{
ProcessSourceString();
}
}
}