Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
Match.cs
Go to the documentation of this file.
2
3public class Match : Group
4{
6
7 internal Regex _regex;
8
9 internal int _textbeg;
10
11 internal int _textpos;
12
13 internal int _textend;
14
15 internal int _textstart;
16
17 internal int[][] _matches;
18
19 internal int[] _matchcount;
20
21 internal bool _balancing;
22
23 public static Match Empty { get; } = new Match(null, 1, string.Empty, 0, 0, 0);
24
25
26 public virtual GroupCollection Groups => _groupcoll ?? (_groupcoll = new GroupCollection(this, null));
27
28 internal Match(Regex regex, int capcount, string text, int begpos, int len, int startpos)
29 : base(text, new int[2], 0, "0")
30 {
31 _regex = regex;
32 _matchcount = new int[capcount];
33 _matches = new int[capcount][];
34 _matches[0] = _caps;
35 _textbeg = begpos;
36 _textend = begpos + len;
37 _textstart = startpos;
38 _balancing = false;
39 }
40
41 internal void Reset(Regex regex, string text, int textbeg, int textend, int textstart)
42 {
43 _regex = regex;
44 base.Text = text;
45 _textbeg = textbeg;
46 _textend = textend;
47 _textstart = textstart;
48 int[] matchcount = _matchcount;
49 for (int i = 0; i < matchcount.Length; i++)
50 {
51 matchcount[i] = 0;
52 }
53 _balancing = false;
55 }
56
58 {
59 Regex regex = _regex;
60 if (regex == null)
61 {
62 return this;
63 }
64 return regex.Run(quick: false, base.Length, base.Text, _textbeg, _textend - _textbeg, _textpos);
65 }
66
67 public virtual string Result(string replacement)
68 {
69 if (replacement == null)
70 {
72 }
73 Regex regex = _regex;
74 if (regex == null)
75 {
77 }
78 RegexReplacement orCreate = RegexReplacement.GetOrCreate(regex._replref, replacement, regex.caps, regex.capsize, regex.capnames, regex.roptions);
80 orCreate.ReplacementImpl(ref segments, this);
81 return segments.ToString();
82 }
83
85 {
86 int num = _matchcount[groupnum];
87 if (num == 0)
88 {
89 return default(ReadOnlyMemory<char>);
90 }
91 int[] array = _matches[groupnum];
92 return base.Text.AsMemory(array[(num - 1) * 2], array[num * 2 - 1]);
93 }
94
96 {
97 return GroupToStringImpl(_matchcount.Length - 1);
98 }
99
101 {
102 if (inner == null)
103 {
105 }
106 int num = inner._matchcount.Length;
107 for (int i = 0; i < num; i++)
108 {
109 Group.Synchronized(inner.Groups[i]);
110 }
111 return inner;
112 }
113
114 internal void AddMatch(int cap, int start, int len)
115 {
116 int[][] matches = _matches;
117 if (matches[cap] == null)
118 {
119 matches[cap] = new int[2];
120 }
121 int[][] matches2 = _matches;
122 int[] matchcount = _matchcount;
123 int num = matchcount[cap];
124 if (num * 2 + 2 > matches2[cap].Length)
125 {
126 int[] array = matches2[cap];
127 int[] array2 = new int[num * 8];
128 for (int i = 0; i < num * 2; i++)
129 {
130 array2[i] = array[i];
131 }
132 matches2[cap] = array2;
133 }
134 matches2[cap][num * 2] = start;
135 matches2[cap][num * 2 + 1] = len;
136 matchcount[cap] = num + 1;
137 }
138
139 internal void BalanceMatch(int cap)
140 {
141 _balancing = true;
142 int num = _matchcount[cap];
143 int num2 = num * 2 - 2;
144 int[][] matches = _matches;
145 if (matches[cap][num2] < 0)
146 {
147 num2 = -3 - matches[cap][num2];
148 }
149 num2 -= 2;
150 if (num2 >= 0 && matches[cap][num2] < 0)
151 {
152 AddMatch(cap, matches[cap][num2], matches[cap][num2 + 1]);
153 }
154 else
155 {
156 AddMatch(cap, -3 - num2, -4 - num2);
157 }
158 }
159
160 internal void RemoveMatch(int cap)
161 {
162 _matchcount[cap]--;
163 }
164
165 internal bool IsMatched(int cap)
166 {
167 int[] matchcount = _matchcount;
168 if ((uint)cap < (uint)matchcount.Length && matchcount[cap] > 0)
169 {
170 return _matches[cap][matchcount[cap] * 2 - 1] != -2;
171 }
172 return false;
173 }
174
175 internal int MatchIndex(int cap)
176 {
177 int[][] matches = _matches;
178 int num = matches[cap][_matchcount[cap] * 2 - 2];
179 if (num < 0)
180 {
181 return matches[cap][-3 - num];
182 }
183 return num;
184 }
185
186 internal int MatchLength(int cap)
187 {
188 int[][] matches = _matches;
189 int num = matches[cap][_matchcount[cap] * 2 - 1];
190 if (num < 0)
191 {
192 return matches[cap][-3 - num];
193 }
194 return num;
195 }
196
197 internal void Tidy(int textpos)
198 {
199 _textpos = textpos;
201 int[] array = _matches[0];
202 base.Index = array[0];
203 base.Length = array[1];
204 if (_balancing)
205 {
207 }
208 }
209
210 private void TidyBalancing()
211 {
212 int[] matchcount = _matchcount;
213 int[][] matches = _matches;
214 for (int i = 0; i < matchcount.Length; i++)
215 {
216 int num = matchcount[i] * 2;
217 int[] array = matches[i];
218 int j;
219 for (j = 0; j < num && array[j] >= 0; j++)
220 {
221 }
222 int num2 = j;
223 for (; j < num; j++)
224 {
225 if (array[j] < 0)
226 {
227 num2--;
228 continue;
229 }
230 if (j != num2)
231 {
232 array[num2] = array[j];
233 }
234 num2++;
235 }
236 matchcount[i] = num2 / 2;
237 }
238 _balancing = false;
239 }
240}
static string NoResultOnFailed
Definition SR.cs:62
Definition SR.cs:7
static Group Synchronized(Group inner)
Definition Group.cs:27
virtual GroupCollection Groups
Definition Match.cs:26
Match(Regex regex, int capcount, string text, int begpos, int len, int startpos)
Definition Match.cs:28
virtual string Result(string replacement)
Definition Match.cs:67
void Reset(Regex regex, string text, int textbeg, int textend, int textstart)
Definition Match.cs:41
void AddMatch(int cap, int start, int len)
Definition Match.cs:114
ReadOnlyMemory< char > LastGroupToStringImpl()
Definition Match.cs:95
static Match Synchronized(Match inner)
Definition Match.cs:100
ReadOnlyMemory< char > GroupToStringImpl(int groupnum)
Definition Match.cs:84
static RegexReplacement GetOrCreate(WeakReference< RegexReplacement > replRef, string replacement, Hashtable caps, int capsize, Hashtable capnames, RegexOptions roptions)
void ReplacementImpl(ref SegmentStringBuilder segments, Match match)
Match Run(bool quick, int prevlen, string input, int beginning, int length, int startat)
Definition Regex.cs:337
WeakReference< RegexReplacement > _replref
Definition Regex.cs:29
static void ThrowArgumentNullException(ExceptionArgument arg)
static SegmentStringBuilder Create()