1
using System;
2
using System.Collections.Generic;
3
using System.Text;
4
using System.Text.RegularExpressions;
5

6
namespace TurnerSoftware.RobotsExclusionTools.Tokenization
7
{
8
	public class TokenDefinition
9
	{
10 1
		private Regex Regex { get; }
11 1
		private TokenType TokenType { get; }
12

13 1
		public TokenDefinition(TokenType tokenType, string regex)
14 1
		{
15 1
			Regex = new Regex(regex, RegexOptions.IgnoreCase);
16 1
			TokenType = tokenType;
17 1
		}
18

19
		public TokenMatch Match(string input, int offset = 0)
20 1
		{
21 1
			var match = Regex.Match(input, offset);
22 1
			if (match.Success)
23 1
			{
24 1
				return new TokenMatch
25 1
				{
26 1
					IsMatch = true,
27 1
					MatchLength = match.Length,
28 1
					TokenType = TokenType,
29 1
					Value = match.Value
30 1
				};
31
			}
32
			else
33 1
			{
34 1
				return TokenMatch.NoMatch;
35
			}
36 1
		}
37
	}
38
}

Read our documentation on viewing source code .

Loading