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

◆ PunycodeDecode()

static string System.Globalization.IdnMapping.PunycodeDecode ( string ascii)
inlinestaticprivate

Definition at line 458 of file IdnMapping.cs.

459 {
460 if (ascii.Length == 0)
461 {
462 throw new ArgumentException(SR.Argument_IdnBadLabelSize, "ascii");
463 }
464 if (ascii.Length > 255 - ((!IsDot(ascii[^1])) ? 1 : 0))
465 {
466 throw new ArgumentException(SR.Format(SR.Argument_IdnBadNameSize, 255 - ((!IsDot(ascii[^1])) ? 1 : 0)), "ascii");
467 }
468 StringBuilder stringBuilder = new StringBuilder(ascii.Length);
469 int num = 0;
470 int num2 = 0;
471 int num3 = 0;
472 while (num < ascii.Length)
473 {
474 num = ascii.IndexOf('.', num2);
475 if (num < 0 || num > ascii.Length)
476 {
477 num = ascii.Length;
478 }
479 if (num == num2)
480 {
481 if (num == ascii.Length)
482 {
483 break;
484 }
485 throw new ArgumentException(SR.Argument_IdnBadLabelSize, "ascii");
486 }
487 if (num - num2 > 63)
488 {
489 throw new ArgumentException(SR.Argument_IdnBadLabelSize, "ascii");
490 }
491 if (ascii.Length < "xn--".Length + num2 || string.Compare(ascii, num2, "xn--", 0, "xn--".Length, StringComparison.OrdinalIgnoreCase) != 0)
492 {
493 stringBuilder.Append(ascii, num2, num - num2);
494 }
495 else
496 {
497 num2 += "xn--".Length;
498 int num4 = ascii.LastIndexOf('-', num - 1);
499 if (num4 == num - 1)
500 {
501 throw new ArgumentException(SR.Argument_IdnBadPunycode, "ascii");
502 }
503 int num5;
504 if (num4 <= num2)
505 {
506 num5 = 0;
507 }
508 else
509 {
510 num5 = num4 - num2;
511 for (int i = num2; i < num2 + num5; i++)
512 {
513 if (ascii[i] > '\u007f')
514 {
515 throw new ArgumentException(SR.Argument_IdnBadPunycode, "ascii");
516 }
517 stringBuilder.Append((char)((ascii[i] >= 'A' && ascii[i] <= 'Z') ? (ascii[i] - 65 + 97) : ascii[i]));
518 }
519 }
520 int num6 = num2 + ((num5 > 0) ? (num5 + 1) : 0);
521 int num7 = 128;
522 int num8 = 72;
523 int num9 = 0;
524 int num10 = 0;
525 while (num6 < num)
526 {
527 int num11 = num9;
528 int num12 = 1;
529 int num13 = 36;
530 while (true)
531 {
532 if (num6 >= num)
533 {
534 throw new ArgumentException(SR.Argument_IdnBadPunycode, "ascii");
535 }
536 int num14 = DecodeDigit(ascii[num6++]);
537 if (num14 > (134217727 - num9) / num12)
538 {
539 throw new ArgumentException(SR.Argument_IdnBadPunycode, "ascii");
540 }
541 num9 += num14 * num12;
542 int num15 = ((num13 <= num8) ? 1 : ((num13 >= num8 + 26) ? 26 : (num13 - num8)));
543 if (num14 < num15)
544 {
545 break;
546 }
547 if (num12 > 134217727 / (36 - num15))
548 {
549 throw new ArgumentException(SR.Argument_IdnBadPunycode, "ascii");
550 }
551 num12 *= 36 - num15;
552 num13 += 36;
553 }
554 num8 = Adapt(num9 - num11, stringBuilder.Length - num3 - num10 + 1, num11 == 0);
555 if (num9 / (stringBuilder.Length - num3 - num10 + 1) > 134217727 - num7)
556 {
557 throw new ArgumentException(SR.Argument_IdnBadPunycode, "ascii");
558 }
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))
562 {
563 throw new ArgumentException(SR.Argument_IdnBadPunycode, "ascii");
564 }
565 string value = char.ConvertFromUtf32(num7);
566 int num17;
567 if (num10 > 0)
568 {
569 int num16 = num9;
570 num17 = num3;
571 while (num16 > 0)
572 {
573 if (num17 >= stringBuilder.Length)
574 {
575 throw new ArgumentException(SR.Argument_IdnBadPunycode, "ascii");
576 }
577 if (char.IsSurrogate(stringBuilder[num17]))
578 {
579 num17++;
580 }
581 num16--;
582 num17++;
583 }
584 }
585 else
586 {
587 num17 = num3 + num9;
588 }
589 stringBuilder.Insert(num17, value);
590 if (IsSupplementary(num7))
591 {
592 num10++;
593 }
594 num9++;
595 }
596 bool flag = false;
597 StrongBidiCategory bidiCategory = CharUnicodeInfo.GetBidiCategory(stringBuilder, num3);
598 if (bidiCategory == StrongBidiCategory.StrongRightToLeft)
599 {
600 flag = true;
601 }
602 for (int j = num3; j < stringBuilder.Length; j++)
603 {
604 if (!char.IsLowSurrogate(stringBuilder[j]))
605 {
606 bidiCategory = CharUnicodeInfo.GetBidiCategory(stringBuilder, j);
607 if ((flag && bidiCategory == StrongBidiCategory.StrongLeftToRight) || (!flag && bidiCategory == StrongBidiCategory.StrongRightToLeft))
608 {
609 throw new ArgumentException(SR.Argument_IdnBadBidi, "ascii");
610 }
611 }
612 }
613 if (flag && bidiCategory != StrongBidiCategory.StrongRightToLeft)
614 {
615 throw new ArgumentException(SR.Argument_IdnBadBidi, "ascii");
616 }
617 }
618 if (num - num2 > 63)
619 {
620 throw new ArgumentException(SR.Argument_IdnBadLabelSize, "ascii");
621 }
622 if (num != ascii.Length)
623 {
624 stringBuilder.Append('.');
625 }
626 num2 = num + 1;
627 num3 = stringBuilder.Length;
628 }
629 if (stringBuilder.Length > 255 - ((!IsDot(stringBuilder[stringBuilder.Length - 1])) ? 1 : 0))
630 {
631 throw new ArgumentException(SR.Format(SR.Argument_IdnBadNameSize, 255 - ((!IsDot(stringBuilder[stringBuilder.Length - 1])) ? 1 : 0)), "ascii");
632 }
633 return stringBuilder.ToString();
634 }
static int DecodeDigit(char cp)
static bool IsDot(char c)
static bool IsSupplementary(int cTest)
static int Adapt(int delta, int numpoints, bool firsttime)
unsafe StringBuilder Insert(int index, string? value, int count)
override string ToString()
StringBuilder Append(char value, int repeatCount)

References System.Globalization.IdnMapping.Adapt(), System.Text.StringBuilder.Append(), System.SR.Argument_IdnBadBidi, System.SR.Argument_IdnBadLabelSize, System.SR.Argument_IdnBadNameSize, System.SR.Argument_IdnBadPunycode, System.Globalization.IdnMapping.DecodeDigit(), System.SR.Format(), System.Globalization.CharUnicodeInfo.GetBidiCategory(), System.Text.StringBuilder.Insert(), System.Globalization.IdnMapping.IsDot(), System.Globalization.IdnMapping.IsSupplementary(), System.Text.StringBuilder.Length, System.Text.StringBuilder.ToString(), and System.value.

Referenced by System.Globalization.IdnMapping.GetUnicodeInvariant().