Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ Replace()

string System.Text.RegularExpressions.RegexReplacement.Replace ( Regex regex,
string input,
int count,
int startat )
inline

Definition at line 151 of file RegexReplacement.cs.

152 {
153 if (count < -1)
154 {
155 ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.count, ExceptionResource.CountTooSmall);
156 }
157 if ((uint)startat > (uint)input.Length)
158 {
159 ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startat, ExceptionResource.BeginIndexNotNegative);
160 }
161 if (count == 0)
162 {
163 return input;
164 }
165 (RegexReplacement, SegmentStringBuilder, ReadOnlyMemory<char>, int, int) state2 = (this, SegmentStringBuilder.Create(), input.AsMemory(), 0, count);
166 if (!regex.RightToLeft)
167 {
168 regex.Run<(RegexReplacement, SegmentStringBuilder, ReadOnlyMemory<char>, int, int)>(input, startat, ref state2, delegate(ref (RegexReplacement thisRef, SegmentStringBuilder segments, ReadOnlyMemory<char> inputMemory, int prevat, int count) state, Match match)
169 {
170 state.segments.Add(state.inputMemory.Slice(state.prevat, match.Index - state.prevat));
171 state.prevat = match.Index + match.Length;
172 state.thisRef.ReplacementImpl(ref state.segments, match);
173 return --state.count != 0;
174 }, reuseMatchObject: true);
175 if (state2.Item2.Count == 0)
176 {
177 return input;
178 }
179 state2.Item2.Add(state2.Item3.Slice(state2.Item4, input.Length - state2.Item4));
180 }
181 else
182 {
183 state2.Item4 = input.Length;
184 regex.Run<(RegexReplacement, SegmentStringBuilder, ReadOnlyMemory<char>, int, int)>(input, startat, ref state2, delegate(ref (RegexReplacement thisRef, SegmentStringBuilder segments, ReadOnlyMemory<char> inputMemory, int prevat, int count) state, Match match)
185 {
186 state.segments.Add(state.inputMemory.Slice(match.Index + match.Length, state.prevat - match.Index - match.Length));
187 state.prevat = match.Index;
188 state.thisRef.ReplacementImplRTL(ref state.segments, match);
189 return --state.count != 0;
190 }, reuseMatchObject: true);
191 if (state2.Item2.Count == 0)
192 {
193 return input;
194 }
195 state2.Item2.Add(state2.Item3.Slice(0, state2.Item4));
196 state2.Item2.AsSpan().Reverse();
197 }
198 return state2.Item2.ToString();
199 }
void Add(TKey key, TValue value)
RegexReplacement(string rep, RegexNode concat, Hashtable _caps)

References System.Text.RegularExpressions.RegexReplacement.RegexReplacement(), System.Collections.Generic.Dictionary< TKey, TValue >.Add(), System.Collections.Generic.Dictionary< TKey, TValue >.Count, System.Text.RegularExpressions.count, System.Text.SegmentStringBuilder.Create(), System.Text.RegularExpressions.input, System.match, System.Text.RegularExpressions.startat, System.state, and System.Text.RegularExpressions.ThrowHelper.ThrowArgumentOutOfRangeException().