-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCharRangePattern.cs
More file actions
44 lines (37 loc) · 1.14 KB
/
CharRangePattern.cs
File metadata and controls
44 lines (37 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using System;
using Utility.BaseTypes;
using Utility.General;
using Utility.PrettyPrint;
namespace RegexParser.Patterns
{
public class CharRangePattern : CharPattern, IEquatable<CharRangePattern>
{
public CharRangePattern(char from, char to)
{
From = from;
To = to;
}
public readonly char From;
public readonly char To;
public override bool IsMatch(char c)
{
return From <= c && c <= To;
}
public override PPElement ToPrettyPrint()
{
return new PPText(Type.ToString(), string.Format("[{0}-{1}]", From.Show(), To.Show()));
}
bool IEquatable<CharRangePattern>.Equals(CharRangePattern other)
{
return other != null && this.From == other.From && this.To == other.To;
}
public override int GetHashCode()
{
return HashCodeCombiner.Combine(From.GetHashCode(), To.GetHashCode());
}
public override bool Equals(object obj)
{
return ((IEquatable<CharRangePattern>)this).Equals(obj as CharRangePattern);
}
}
}