60
62
return String.Format ("[Match: Color={0}, Pattern={1}]", Color, Pattern);
63
public virtual int TryMatch (string text, int matchOffset)
65
protected readonly static int[] emptyMatch = new int[0];
66
public virtual int[] TryMatch (string text, int matchOffset)
66
// System.Text.RegularExpressions.Match match = regex.Match (text, matchOffset);
67
68
string matchStr = text.Substring (matchOffset);
68
System.Text.RegularExpressions.Match match = regex.Match (matchStr);
69
var match = regex.Match (matchStr);
71
var result = new int[match.Groups.Count];
72
for (int i = 0; i < result.Length; i++) {
73
result[i] = match.Groups[i].Length;
75
80
public const string Node = "Match";
82
public bool IsGroupMatch {
84
return groups != null && string.IsNullOrEmpty (Color);
88
List<string> groups = null;
89
public List<string> Groups {
92
groups = new List<string> ();
76
97
public static Match Read (XmlReader reader)
99
string expression = reader.GetAttribute ("expression");
100
if (!string.IsNullOrEmpty (expression)) {
101
var result = new Match ();
103
result.Pattern = "^" + expression;
104
result.regex = new System.Text.RegularExpressions.Regex (result.Pattern, RegexOptions.Compiled | RegexOptions.IgnoreCase);
106
XmlReadHelper.ReadList (reader, Node, delegate () {
107
switch (reader.LocalName) {
109
result.Groups.Add (reader.GetAttribute ("color"));
78
118
string color = reader.GetAttribute ("color");
79
119
string pattern = reader.ReadElementString ();
80
Match result = pattern == "CSharpNumber" ? new CSharpNumberMatch () : new Match ();
82
result.Pattern = "^" + pattern;
83
result.regex = new System.Text.RegularExpressions.Regex (result.Pattern, RegexOptions.Compiled | RegexOptions.IgnoreCase);
120
Match result2 = pattern == "CSharpNumber" ? new CSharpNumberMatch () : new Match ();
121
result2.Color = color;
122
result2.Pattern = "^" + pattern;
123
result2.regex = new System.Text.RegularExpressions.Regex (result2.Pattern, RegexOptions.Compiled | RegexOptions.IgnoreCase);
137
177
ReadNonFloatEnd (text, ref i);
138
return i - matchOffset;
178
return new [] {i - matchOffset};
140
180
if (i >= text.Length || !Char.IsDigit (text[i]))
143
183
while (i < text.Length && Char.IsDigit (text[i]))
146
186
if (ReadNonFloatEnd (text, ref i))
147
return i - matchOffset;
187
return new [] {i - matchOffset};
148
188
if (i < text.Length && text[i] == '.') {
150
if (i >= text.Length)
151
return (i - 1) - matchOffset;
152
if (!Char.IsDigit (text[i]))
190
if (i >= text.Length || !char.IsDigit (text[i]))
191
return new [] { (i - 1) - matchOffset };
155
193
while (i < text.Length && Char.IsDigit (text[i]))