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

◆ ToUtf8()

static unsafe OperationStatus System.Text.Json.JsonWriterHelper.ToUtf8 ( ReadOnlySpan< byte > utf16Source,
Span< byte > utf8Destination,
out int bytesConsumed,
out int bytesWritten )
inlinestatic

Definition at line 508 of file JsonWriterHelper.cs.

509 {
510 fixed (byte* ptr = &MemoryMarshal.GetReference(utf16Source))
511 {
512 fixed (byte* ptr3 = &MemoryMarshal.GetReference(utf8Destination))
513 {
514 char* ptr2 = (char*)ptr;
515 byte* ptr4 = ptr3;
516 char* ptr5 = (char*)(ptr + utf16Source.Length);
517 byte* ptr6 = ptr4 + utf8Destination.Length;
518 while (true)
519 {
520 IL_025a:
521 if (ptr5 - ptr2 > 13)
522 {
523 int num = Math.Min(PtrDiff(ptr5, ptr2), PtrDiff(ptr6, ptr4));
524 char* ptr7 = ptr2 + num - 5;
525 if (ptr2 < ptr7)
526 {
527 while (true)
528 {
529 int num2 = *ptr2;
530 ptr2++;
531 if (num2 > 127)
532 {
533 goto IL_0181;
534 }
535 *ptr4 = (byte)num2;
536 ptr4++;
537 if (((uint)(int)ptr2 & 2u) != 0)
538 {
539 num2 = *ptr2;
540 ptr2++;
541 if (num2 > 127)
542 {
543 goto IL_0181;
544 }
545 *ptr4 = (byte)num2;
546 ptr4++;
547 }
548 while (ptr2 < ptr7)
549 {
550 num2 = *(int*)ptr2;
551 int num3 = *(int*)(ptr2 + 2);
552 if (((num2 | num3) & -8323200) == 0)
553 {
554 if (!BitConverter.IsLittleEndian)
555 {
556 *ptr4 = (byte)(num2 >> 16);
557 ptr4[1] = (byte)num2;
558 ptr2 += 4;
559 ptr4[2] = (byte)(num3 >> 16);
560 ptr4[3] = (byte)num3;
561 ptr4 += 4;
562 }
563 else
564 {
565 *ptr4 = (byte)num2;
566 ptr4[1] = (byte)(num2 >> 16);
567 ptr2 += 4;
568 ptr4[2] = (byte)num3;
569 ptr4[3] = (byte)(num3 >> 16);
570 ptr4 += 4;
571 }
572 continue;
573 }
574 goto IL_014f;
575 }
576 goto IL_0251;
577 IL_014f:
578 num2 = (BitConverter.IsLittleEndian ? ((ushort)num2) : (num2 >>> 16));
579 ptr2++;
580 if (num2 > 127)
581 {
582 goto IL_0181;
583 }
584 *ptr4 = (byte)num2;
585 ptr4++;
586 goto IL_0251;
587 IL_0251:
588 if (ptr2 < ptr7)
589 {
590 continue;
591 }
592 goto IL_025a;
593 IL_0181:
594 int num4;
595 if (num2 <= 2047)
596 {
597 num4 = -64 | (num2 >> 6);
598 }
599 else
600 {
601 if (!JsonHelpers.IsInRangeInclusive(num2, 55296, 57343))
602 {
603 num4 = -32 | (num2 >> 12);
604 }
605 else
606 {
607 if (num2 > 56319)
608 {
609 break;
610 }
611 num4 = *ptr2;
612 if (!JsonHelpers.IsInRangeInclusive(num4, 56320, 57343))
613 {
614 break;
615 }
616 ptr2++;
617 num2 = num4 + (num2 << 10) + -56613888;
618 *ptr4 = (byte)(0xFFFFFFF0u | (uint)(num2 >> 18));
619 ptr4++;
620 num4 = -128 | ((num2 >> 12) & 0x3F);
621 }
622 *ptr4 = (byte)num4;
623 ptr7--;
624 ptr4++;
625 num4 = -128 | ((num2 >> 6) & 0x3F);
626 }
627 *ptr4 = (byte)num4;
628 ptr7--;
629 ptr4[1] = (byte)(0xFFFFFF80u | ((uint)num2 & 0x3Fu));
630 ptr4 += 2;
631 goto IL_0251;
632 }
633 break;
634 }
635 }
636 while (true)
637 {
638 int num5;
639 int num6;
640 if (ptr2 < ptr5)
641 {
642 num5 = *ptr2;
643 ptr2++;
644 if (num5 <= 127)
645 {
646 if (ptr6 - ptr4 > 0)
647 {
648 *ptr4 = (byte)num5;
649 ptr4++;
650 continue;
651 }
652 }
653 else if (num5 <= 2047)
654 {
655 if (ptr6 - ptr4 > 1)
656 {
657 num6 = -64 | (num5 >> 6);
658 goto IL_0380;
659 }
660 }
661 else if (!JsonHelpers.IsInRangeInclusive(num5, 55296, 57343))
662 {
663 if (ptr6 - ptr4 > 2)
664 {
665 num6 = -32 | (num5 >> 12);
666 goto IL_0368;
667 }
668 }
669 else if (ptr6 - ptr4 > 3)
670 {
671 if (num5 > 56319)
672 {
673 break;
674 }
675 if (ptr2 < ptr5)
676 {
677 num6 = *ptr2;
678 if (!JsonHelpers.IsInRangeInclusive(num6, 56320, 57343))
679 {
680 break;
681 }
682 ptr2++;
683 num5 = num6 + (num5 << 10) + -56613888;
684 *ptr4 = (byte)(0xFFFFFFF0u | (uint)(num5 >> 18));
685 ptr4++;
686 num6 = -128 | ((num5 >> 12) & 0x3F);
687 goto IL_0368;
688 }
689 bytesConsumed = (int)((byte*)(ptr2 - 1) - ptr);
690 bytesWritten = (int)(ptr4 - ptr3);
691 return OperationStatus.NeedMoreData;
692 }
693 bytesConsumed = (int)((byte*)(ptr2 - 1) - ptr);
694 bytesWritten = (int)(ptr4 - ptr3);
695 return OperationStatus.DestinationTooSmall;
696 }
697 bytesConsumed = (int)((byte*)ptr2 - ptr);
698 bytesWritten = (int)(ptr4 - ptr3);
699 return OperationStatus.Done;
700 IL_0368:
701 *ptr4 = (byte)num6;
702 ptr4++;
703 num6 = -128 | ((num5 >> 6) & 0x3F);
704 goto IL_0380;
705 IL_0380:
706 *ptr4 = (byte)num6;
707 ptr4[1] = (byte)(0xFFFFFF80u | ((uint)num5 & 0x3Fu));
708 ptr4 += 2;
709 }
710 break;
711 }
712 bytesConsumed = (int)((byte*)(ptr2 - 1) - ptr);
713 bytesWritten = (int)(ptr4 - ptr3);
714 return OperationStatus.InvalidData;
715 }
716 }
717 }
static unsafe int PtrDiff(char *a, char *b)

References System.Text.Json.Dictionary, System.Text.Json.JsonHelpers.IsInRangeInclusive(), System.BitConverter.IsLittleEndian, System.Math.Min(), and System.Text.Json.JsonWriterHelper.PtrDiff().

Referenced by System.Text.Json.JsonDocument.TextEquals(), System.Text.Json.Utf8JsonWriter.TranscodeAndWrite(), System.Text.Json.Utf8JsonReader.ValueTextEquals(), System.Text.Json.Utf8JsonWriter.WriteCommentIndented(), and System.Text.Json.Utf8JsonWriter.WriteCommentMinimized().