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

◆ GetChars() [2/6]

unsafe override int System.Text.UTF32Encoding.GetChars ( byte * bytes,
int byteCount,
char * chars,
int charCount,
DecoderNLS baseDecoder )
inlinepackagevirtual

Reimplemented from System.Text.Encoding.

Definition at line 639 of file UTF32Encoding.cs.

640 {
641 UTF32Decoder uTF32Decoder = (UTF32Decoder)baseDecoder;
642 char* ptr = chars;
643 char* ptr2 = chars + charCount;
644 byte* ptr3 = bytes;
645 byte* ptr4 = bytes + byteCount;
646 int num = 0;
647 uint num2 = 0u;
648 DecoderFallbackBuffer decoderFallbackBuffer = null;
649 if (uTF32Decoder != null)
650 {
651 num = uTF32Decoder.readByteCount;
652 num2 = (uint)uTF32Decoder.iChar;
653 decoderFallbackBuffer = baseDecoder.FallbackBuffer;
654 }
655 else
656 {
657 decoderFallbackBuffer = decoderFallback.CreateFallbackBuffer();
658 }
659 decoderFallbackBuffer.InternalInitialize(bytes, chars + charCount);
660 while (bytes < ptr4)
661 {
662 if (_bigEndian)
663 {
664 num2 <<= 8;
665 num2 += *(bytes++);
666 }
667 else
668 {
669 num2 >>= 8;
670 num2 += (uint)(*(bytes++) << 24);
671 }
672 num++;
673 if (num < 4)
674 {
675 continue;
676 }
677 num = 0;
678 if (num2 > 1114111 || (num2 >= 55296 && num2 <= 57343))
679 {
680 byte[] bytes2 = ((!_bigEndian) ? new byte[4]
681 {
682 (byte)num2,
683 (byte)(num2 >> 8),
684 (byte)(num2 >> 16),
685 (byte)(num2 >> 24)
686 } : new byte[4]
687 {
688 (byte)(num2 >> 24),
689 (byte)(num2 >> 16),
690 (byte)(num2 >> 8),
691 (byte)num2
692 });
693 char* chars2 = chars;
694 bool flag = decoderFallbackBuffer.InternalFallback(bytes2, bytes, ref chars2);
695 chars = chars2;
696 if (!flag)
697 {
698 bytes -= 4;
699 num2 = 0u;
700 decoderFallbackBuffer.InternalReset();
701 ThrowCharsOverflow(uTF32Decoder, chars == ptr);
702 break;
703 }
704 num2 = 0u;
705 continue;
706 }
707 if (num2 >= 65536)
708 {
709 if (chars >= ptr2 - 1)
710 {
711 bytes -= 4;
712 num2 = 0u;
713 ThrowCharsOverflow(uTF32Decoder, chars == ptr);
714 break;
715 }
716 *(chars++) = GetHighSurrogate(num2);
717 num2 = GetLowSurrogate(num2);
718 }
719 else if (chars >= ptr2)
720 {
721 bytes -= 4;
722 num2 = 0u;
723 ThrowCharsOverflow(uTF32Decoder, chars == ptr);
724 break;
725 }
726 *(chars++) = (char)num2;
727 num2 = 0u;
728 }
729 if (num > 0 && (uTF32Decoder == null || uTF32Decoder.MustFlush))
730 {
731 byte[] array = new byte[num];
732 int num3 = num;
733 if (_bigEndian)
734 {
735 while (num3 > 0)
736 {
737 array[--num3] = (byte)num2;
738 num2 >>= 8;
739 }
740 }
741 else
742 {
743 while (num3 > 0)
744 {
745 array[--num3] = (byte)(num2 >> 24);
746 num2 <<= 8;
747 }
748 }
749 char* chars2 = chars;
750 bool flag2 = decoderFallbackBuffer.InternalFallback(array, bytes, ref chars2);
751 chars = chars2;
752 if (!flag2)
753 {
754 decoderFallbackBuffer.InternalReset();
755 ThrowCharsOverflow(uTF32Decoder, chars == ptr);
756 }
757 else
758 {
759 num = 0;
760 num2 = 0u;
761 }
762 }
763 if (uTF32Decoder != null)
764 {
765 uTF32Decoder.iChar = (int)num2;
766 uTF32Decoder.readByteCount = num;
767 uTF32Decoder._bytesUsed = (int)(bytes - ptr3);
768 }
769 return (int)(chars - ptr);
770 }
unsafe void InternalInitialize(byte *byteStart, char *charEnd)
DecoderFallbackBuffer CreateFallbackBuffer()
DecoderFallback decoderFallback
Definition Encoding.cs:343
static char GetHighSurrogate(uint iChar)
static char GetLowSurrogate(uint iChar)

References System.Text.UTF32Encoding._bigEndian, System.array, System.byteCount, System.bytes, System.charCount, System.chars, System.Text.DecoderFallback.CreateFallbackBuffer(), System.Text.Encoding.decoderFallback, System.Text.DecoderNLS.FallbackBuffer, System.Text.UTF32Encoding.GetHighSurrogate(), System.Text.UTF32Encoding.GetLowSurrogate(), System.Text.UTF32Encoding.UTF32Decoder.iChar, System.Text.DecoderFallbackBuffer.InternalFallback(), System.Text.DecoderFallbackBuffer.InternalInitialize(), System.Text.DecoderFallbackBuffer.InternalReset(), System.Text.DecoderNLS.MustFlush, System.Text.UTF32Encoding.UTF32Decoder.readByteCount, and System.Text.Encoding.ThrowCharsOverflow().