14 private static readonly
char[]
s_dotSeparators =
new char[4] {
'.',
'。',
'.',
'。' };
68 if (
index > unicode.Length)
88 fixed (
char* ptr = unicode)
122 if (
index > ascii.Length)
138 fixed (
char* ptr = ascii)
148 public override bool Equals([NotNullWhen(
true)]
object?
obj)
163 private unsafe
static string GetStringForOutput(
string originalString,
char*
input,
int inputLength,
char* output,
int outputLength)
165 if (originalString.Length == inputLength && inputLength == outputLength &&
Ordinal.
EqualsIgnoreCase(ref *
input, ref *output, inputLength))
167 return originalString;
169 return new string(output, 0, outputLength);
182 if (unicode[^1] <=
'\u001f')
195 if (unicode.Length == 0)
200 for (
int i = 0; i < unicode.Length; i++)
202 if (unicode[i] <=
'\u001f')
206 if (bCheckAscii && unicode[i] >=
'\u007f')
210 if (
IsDot(unicode[i]))
220 if (bUseStd3 && i > 0)
231 if (num == -1 && unicode.Length > 63)
235 if (unicode.Length > 255 - ((!
IsDot(unicode[^1])) ? 1 : 0))
239 if (bUseStd3 && !
IsDot(unicode[^1]))
248 if (unicode.Length == 0)
256 while (num < unicode.Length)
261 num = unicode.Length;
265 if (num == unicode.Length)
271 stringBuilder.
Append(
"xn--");
278 if (
char.IsLowSurrogate(unicode, num4))
289 for (
int i = num2; i < num; i++)
300 if (
Basic(unicode[i]))
305 else if (
char.IsSurrogatePair(unicode, i))
311 if (num6 == num - num2)
313 stringBuilder.
Remove(num3,
"xn--".Length);
317 if (unicode.Length - num2 >=
"xn--".Length && unicode.Substring(num2,
"xn--".Length).Equals(
"xn--",
StringComparison.OrdinalIgnoreCase))
324 stringBuilder.
Append(
'-');
329 while (num5 < num - num2)
332 int num12 = 134217727;
335 num11 =
char.ConvertToUtf32(unicode, j);
336 if (num11 >= num8 && num11 < num12)
341 num9 += (num12 - num8) * (num5 - num7 + 1);
345 num11 =
char.ConvertToUtf32(unicode, j);
358 int num15 = ((num14 <= num10) ? 1 : ((num14 >= num10 + 26) ? 26 : (num14 - num10)));
364 num13 = (num13 - num15) / (36 - num15);
368 num10 =
Adapt(num9, num5 - num7 + 1, num5 == num6);
381 if (stringBuilder.
Length - num3 > 63)
385 if (num != unicode.Length)
387 stringBuilder.
Append(
'.');
390 num3 = stringBuilder.
Length;
392 if (stringBuilder.
Length > 255 - ((!
IsDot(unicode[^1])) ? 1 : 0))
401 if (c !=
'.' && c !=
'。' && c !=
'.')
410 return cTest >= 65536;
425 if ((c <
'[' || c >
'`') && (c <
'{' || c >
'\u007f') && !(c ==
'-' && bNextToDot))
460 if (ascii.Length == 0)
464 if (ascii.Length > 255 - ((!
IsDot(ascii[^1])) ? 1 : 0))
472 while (num < ascii.Length)
474 num = ascii.IndexOf(
'.', num2);
475 if (num < 0 || num > ascii.Length)
481 if (num == ascii.Length)
491 if (ascii.Length <
"xn--".Length + num2 ||
string.Compare(ascii, num2,
"xn--", 0,
"xn--".Length,
StringComparison.OrdinalIgnoreCase) != 0)
493 stringBuilder.
Append(ascii, num2, num - num2);
497 num2 +=
"xn--".Length;
498 int num4 = ascii.LastIndexOf(
'-', num - 1);
511 for (
int i = num2; i < num2 + num5; i++)
513 if (ascii[i] >
'\u007f')
517 stringBuilder.
Append((
char)((ascii[i] >=
'A' && ascii[i] <=
'Z') ? (ascii[i] - 65 + 97) : ascii[i]));
520 int num6 = num2 + ((num5 > 0) ? (num5 + 1) : 0);
537 if (num14 > (134217727 - num9) / num12)
541 num9 += num14 * num12;
542 int num15 = ((num13 <= num8) ? 1 : ((num13 >= num8 + 26) ? 26 : (num13 - num8)));
547 if (num12 > 134217727 / (36 - num15))
554 num8 =
Adapt(num9 - num11, stringBuilder.
Length - num3 - num10 + 1, num11 == 0);
555 if (num9 / (stringBuilder.
Length - num3 - num10 + 1) > 134217727 - num7)
559 num7 += num9 / (stringBuilder.Length - num3 - num10 + 1);
560 num9 %= stringBuilder.Length - num3 - num10 + 1;
561 if (num7 < 0 || num7 > 1114111 || (num7 >= 55296 && num7 <= 57343))
565 string value =
char.ConvertFromUtf32(num7);
573 if (num17 >= stringBuilder.
Length)
577 if (
char.IsSurrogate(stringBuilder[num17]))
602 for (
int j = num3; j < stringBuilder.
Length; j++)
604 if (!
char.IsLowSurrogate(stringBuilder[j]))
622 if (num != ascii.Length)
624 stringBuilder.
Append(
'.');
627 num3 = stringBuilder.
Length;
629 if (stringBuilder.
Length > 255 - ((!
IsDot(stringBuilder[stringBuilder.
Length - 1])) ? 1 : 0))
638 if (cp >=
'0' && cp <=
'9')
642 if (cp >=
'a' && cp <=
'z')
646 if (cp >=
'A' && cp <=
'Z')
653 private static int Adapt(
int delta,
int numpoints,
bool firsttime)
655 delta = (firsttime ? (delta / 700) : (delta / 2));
656 delta += delta / numpoints;
663 return (
int)(num + 36 * delta / (delta + 38));
670 bcp = (char)(bcp + 32);
679 return punychar <=
'Z';
688 return (
char)(d - 26 + 48);
690 return (
char)(d + 97);
701 char* ptr = stackalloc
char[num];
703 if (num2 > 0 && num2 <= num)
716 char[]
array =
new char[num2];
717 fixed (
char* ptr2 = &
array[0])
720 if (num2 == 0 || num2 >
array.Length)
734 char* output = stackalloc
char[
count];
738 fixed (
char* output2 = &
array[0])
744 private unsafe
string IcuGetUnicodeCore(
string asciiString,
char* ascii,
int count, uint flags,
char* output,
int outputLength,
bool reattempt)
751 if (num <= outputLength)
757 fixed (
char* output2 =
new char[num])
767 if ((flags & 2u) != 0)
771 for (
int i = 0; i <
count; i++)
774 if (c <=
'\u001f' || c ==
'\u007f')
791 char* output = stackalloc
char[num];
794 char[]
array =
new char[num];
795 fixed (
char* output2 = &
array[0])
801 private unsafe
static string NlsGetAsciiCore(
string unicodeString,
char* unicode,
int count, uint flags,
char* output,
int outputLength)
821 char* output = stackalloc
char[num];
824 char[]
array =
new char[num];
825 fixed (
char* output2 = &
array[0])
831 private unsafe
static string NlsGetUnicodeCore(
string asciiString,
char* ascii,
int count, uint flags,
char* output,
int outputLength)
static unsafe int ToUnicode(uint flags, char *src, int srcLen, char *dstBuffer, int dstBufferCapacity)
static unsafe int ToAscii(uint flags, char *src, int srcLen, char *dstBuffer, int dstBufferCapacity)
static unsafe int IdnToAscii(uint dwFlags, char *lpUnicodeCharStr, int cchUnicodeChar, char *lpASCIICharStr, int cchASCIIChar)
static unsafe int IdnToUnicode(uint dwFlags, char *lpASCIICharStr, int cchASCIIChar, char *lpUnicodeCharStr, int cchUnicodeChar)
static StrongBidiCategory GetBidiCategory(string s, int index)
static unsafe void CheckInvalidIdnCharacters(char *s, int count, uint flags, string paramName)
string GetUnicode(string ascii)
unsafe string NlsGetUnicodeCore(string asciiString, char *ascii, int count)
static int DecodeDigit(char cp)
unsafe string GetAscii(string unicode, int index, int count)
static void ThrowForZeroLength(bool unicode)
unsafe string IcuGetUnicodeCore(string asciiString, char *ascii, int count)
static bool IsDot(char c)
override bool Equals([NotNullWhen(true)] object? obj)
static char EncodeDigit(int d)
static readonly char[] s_dotSeparators
static void ValidateStd3(char c, bool bNextToDot)
static unsafe string GetStringForOutput(string originalString, char *input, int inputLength, char *output, int outputLength)
static bool Basic(uint cp)
static char EncodeBasic(char bcp)
string GetAscii(string unicode)
static bool IsSupplementary(int cTest)
unsafe string IcuGetUnicodeCore(string asciiString, char *ascii, int count, uint flags, char *output, int outputLength, bool reattempt)
static bool HasUpperCaseFlag(char punychar)
unsafe string GetUnicode(string ascii, int index, int count)
static unsafe string NlsGetUnicodeCore(string asciiString, char *ascii, int count, uint flags, char *output, int outputLength)
static unsafe string NlsGetAsciiCore(string unicodeString, char *unicode, int count, uint flags, char *output, int outputLength)
unsafe string IcuGetAsciiCore(string unicodeString, char *unicode, int count)
string GetAsciiInvariant(string unicode, int index, int count)
override int GetHashCode()
static string PunycodeEncode(string unicode)
unsafe string NlsGetAsciiCore(string unicodeString, char *unicode, int count)
string GetUnicodeInvariant(string ascii, int index, int count)
static string PunycodeDecode(string ascii)
string GetAscii(string unicode, int index)
static bool ValidateStd3AndAscii(string unicode, bool bUseStd3, bool bCheckAscii)
string GetUnicode(string ascii, int index)
static int Adapt(int delta, int numpoints, bool firsttime)
static bool EqualsIgnoreCase(ref char charA, ref char charB, int length)
static byte Min(byte val1, byte val2)
static int GetLastPInvokeError()
static string ArgumentOutOfRange_Index
static string Argument_IdnBadStd3
static string Argument_InvalidCharSequence
static string Format(string resourceFormat, object p1)
static string Argument_IdnBadNameSize
static string Argument_IdnBadPunycode
static string ArgumentOutOfRange_IndexCountBuffer
static string Argument_IdnIllegalName
static string Argument_IdnBadBidi
static string ArgumentOutOfRange_NeedNonNegNum
static string Argument_IdnBadLabelSize
unsafe StringBuilder Insert(int index, string? value, int count)
StringBuilder Remove(int startIndex, int length)
override string ToString()
StringBuilder Append(char value, int repeatCount)