using System.Linq;
using System.Text.RegularExpressions;
using JetBrains.Annotations;
namespace WireMock.Matchers
{
///
/// WildcardMatcher
///
///
public class WildcardMatcher : RegexMatcher
{
private readonly string[] _patterns;
///
/// Initializes a new instance of the class.
///
/// The pattern.
/// IgnoreCase
public WildcardMatcher([NotNull] string pattern, bool ignoreCase = false) : this(new[] { pattern }, ignoreCase)
{
}
///
/// Initializes a new instance of the class.
///
/// The match behaviour.
/// The pattern.
/// IgnoreCase
public WildcardMatcher(MatchBehaviour matchBehaviour, [NotNull] string pattern, bool ignoreCase = false) : this(matchBehaviour, new[] { pattern }, ignoreCase)
{
}
///
/// Initializes a new instance of the class.
///
/// The patterns.
/// IgnoreCase
public WildcardMatcher([NotNull] string[] patterns, bool ignoreCase = false) : this(MatchBehaviour.AcceptOnMatch, patterns, ignoreCase)
{
}
///
/// Initializes a new instance of the class.
///
/// The match behaviour.
/// The patterns.
/// IgnoreCase
public WildcardMatcher(MatchBehaviour matchBehaviour, [NotNull] string[] patterns, bool ignoreCase = false) : base(matchBehaviour, patterns.Select(pattern => "^" + Regex.Escape(pattern).Replace(@"\*", ".*").Replace(@"\?", ".") + "$").ToArray(), ignoreCase)
{
_patterns = patterns;
}
///
public override string[] GetPatterns()
{
return _patterns;
}
///
public override string Name => "WildcardMatcher";
}
}