TemplateVariableProcessorIsMatch Method

Check whether the input string matches the template. See remarks.

Definition

Namespace: Quine.Schemas.Core
Assembly: Quine.Schemas.Core (in Quine.Schemas.Core.dll) Version: 1.0.0+0ea0706914ee4edf2b0ed66bec3ab4d062a43b68
C#
public static Dictionary<string, string> IsMatch(
	string template,
	string input,
	TemplateVariableMapper translator
)

Parameters

template  String
Template string with variables to match against.
input  String
Input string to match.
translator  TemplateVariableMapper
A method mapping variable name to matching regex. If null is returned, IsMatch will return null. To signal errors, the method must throw an exception. This delegate must return literal string by using Escape(String).

Return Value

DictionaryString, String
Non-null if input matches template. If template contains any parameters, the dictionary is populated with parameters as keys and their text as values. Otherwise, an empty dictionary is returned, meaning that the input matches the template either literally or that the template is a prefix of input with '/' in between.

Remarks

This method first converts template to a regex by using translator, as if by calling Replace(String, TemplateVariableMapper). The generated regex is then used to match input and then: if a no matches or a single match are found, null or the match is returned; otherwise (multiple matches), TemplateFormatException is thrown.

This method does not cache regular expressions internally; it relies on the static cache built in to Regex class.

Exceptions

TemplateFormatException Wraps any exception that translator threw. - OR - translator returned a string that resulted in an invalid regex - OR - input generates multiple matches (see remarks) - OR - some parameter occurs multiple times in the template.

See Also