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

◆ NlsNormalize()

static unsafe string System.Globalization.Normalization.NlsNormalize ( string strInput,
NormalizationForm normalizationForm )
inlinestaticprivate

Definition at line 169 of file Normalization.cs.

170 {
171 if (strInput.Length == 0)
172 {
173 return string.Empty;
174 }
175 char[] array = null;
176 try
177 {
178 Span<char> span = ((strInput.Length > 512) ? ((Span<char>)(array = ArrayPool<char>.Shared.Rent(strInput.Length))) : stackalloc char[512]);
179 Span<char> span2 = span;
180 while (true)
181 {
182 int num;
183 fixed (char* source = strInput)
184 {
185 fixed (char* destination = &MemoryMarshal.GetReference(span2))
186 {
187 num = Interop.Normaliz.NormalizeString(normalizationForm, source, strInput.Length, destination, span2.Length);
188 }
189 }
190 int lastPInvokeError = Marshal.GetLastPInvokeError();
191 switch (lastPInvokeError)
192 {
193 case 0:
194 {
195 ReadOnlySpan<char> readOnlySpan = span2.Slice(0, num);
196 return readOnlySpan.SequenceEqual(strInput) ? strInput : new string(readOnlySpan);
197 }
198 case 122:
199 num = Math.Abs(num);
200 if (array != null)
201 {
202 char[] array2 = array;
203 array = null;
204 ArrayPool<char>.Shared.Return(array2);
205 }
206 break;
207 case 87:
208 case 1113:
209 if (normalizationForm != NormalizationForm.FormC && normalizationForm != NormalizationForm.FormD && normalizationForm != NormalizationForm.FormKC && normalizationForm != NormalizationForm.FormKD)
210 {
211 throw new ArgumentException(SR.Argument_InvalidNormalizationForm, "normalizationForm");
212 }
213 throw new ArgumentException(SR.Argument_InvalidCharSequenceNoIndex, "strInput");
214 case 8:
215 throw new OutOfMemoryException();
216 default:
217 throw new InvalidOperationException(SR.Format(SR.UnknownError_Num, lastPInvokeError));
218 }
219 span2 = (array = ArrayPool<char>.Shared.Rent(num));
220 }
221 }
222 finally
223 {
224 if (array != null)
225 {
227 }
228 }
229 }
static unsafe int NormalizeString(NormalizationForm normForm, char *source, int sourceLength, char *destination, int destinationLength)
static ArrayPool< T > Shared
Definition ArrayPool.cs:7

References System.Math.Abs(), System.SR.Argument_InvalidCharSequenceNoIndex, System.SR.Argument_InvalidNormalizationForm, System.array, System.destination, System.SR.Format(), System.Runtime.InteropServices.Marshal.GetLastPInvokeError(), System.Span< T >.Length, Interop.Normaliz.NormalizeString(), System.Buffers.ArrayPool< T >.Shared, System.Span< T >.Slice(), System.source, and System.SR.UnknownError_Num.

Referenced by System.Globalization.Normalization.Normalize().