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

◆ GetCharCount() [2/5]

unsafe override int System.Text.UnicodeEncoding.GetCharCount ( byte * bytes,
int count,
DecoderNLS baseDecoder )
inlinesealedpackagevirtual

Reimplemented from System.Text.Encoding.

Definition at line 698 of file UnicodeEncoding.cs.

699 {
700 Decoder decoder = (Decoder)baseDecoder;
701 byte* ptr = bytes + count;
702 byte* byteStart = bytes;
703 int num = -1;
704 char c = '\0';
705 int num2 = count >> 1;
706 DecoderFallbackBuffer decoderFallbackBuffer = null;
707 if (decoder != null)
708 {
709 num = decoder.lastByte;
710 c = decoder.lastChar;
711 if (c > '\0')
712 {
713 num2++;
714 }
715 if (num >= 0 && (count & 1) == 1)
716 {
717 num2++;
718 }
719 }
720 while (bytes < ptr)
721 {
722 if ((bigEndian ^ BitConverter.IsLittleEndian) && ((ulong)bytes & 7uL) == 0L && num == -1 && c == '\0')
723 {
724 ulong* ptr2 = (ulong*)(ptr - 7);
725 ulong* ptr3;
726 for (ptr3 = (ulong*)bytes; ptr3 < ptr2; ptr3++)
727 {
728 if ((0x8000800080008000uL & *ptr3) == 0L)
729 {
730 continue;
731 }
732 ulong num3 = (0xF800F800F800F800uL & *ptr3) ^ 0xD800D800D800D800uL;
733 if ((num3 & 0xFFFF000000000000uL) == 0L || (num3 & 0xFFFF00000000L) == 0L || (num3 & 0xFFFF0000u) == 0L || (num3 & 0xFFFF) == 0L)
734 {
735 long num4 = -287953294993589248L & (long)(*ptr3);
736 if (!BitConverter.IsLittleEndian)
737 {
738 }
739 if (num4 != -2593835887162763264L)
740 {
741 break;
742 }
743 }
744 }
745 bytes = (byte*)ptr3;
746 if (bytes >= ptr)
747 {
748 break;
749 }
750 }
751 if (num < 0)
752 {
753 num = *(bytes++);
754 if (bytes >= ptr)
755 {
756 break;
757 }
758 }
759 char c2 = ((!bigEndian) ? ((char)((*(bytes++) << 8) | num)) : ((char)((num << 8) | *(bytes++))));
760 num = -1;
761 if (c2 >= '\ud800' && c2 <= '\udfff')
762 {
763 if (c2 <= '\udbff')
764 {
765 if (c > '\0')
766 {
767 num2--;
768 byte[] array = null;
769 array = ((!bigEndian) ? new byte[2]
770 {
771 (byte)c,
772 (byte)((int)c >> 8)
773 } : new byte[2]
774 {
775 (byte)((int)c >> 8),
776 (byte)c
777 });
778 if (decoderFallbackBuffer == null)
779 {
780 decoderFallbackBuffer = ((decoder != null) ? decoder.FallbackBuffer : decoderFallback.CreateFallbackBuffer());
781 decoderFallbackBuffer.InternalInitialize(byteStart, null);
782 }
783 num2 += decoderFallbackBuffer.InternalFallback(array, bytes);
784 }
785 c = c2;
786 }
787 else if (c == '\0')
788 {
789 num2--;
790 byte[] array2 = null;
791 array2 = ((!bigEndian) ? new byte[2]
792 {
793 (byte)c2,
794 (byte)((int)c2 >> 8)
795 } : new byte[2]
796 {
797 (byte)((int)c2 >> 8),
798 (byte)c2
799 });
800 if (decoderFallbackBuffer == null)
801 {
802 decoderFallbackBuffer = ((decoder != null) ? decoder.FallbackBuffer : decoderFallback.CreateFallbackBuffer());
803 decoderFallbackBuffer.InternalInitialize(byteStart, null);
804 }
805 num2 += decoderFallbackBuffer.InternalFallback(array2, bytes);
806 }
807 else
808 {
809 c = '\0';
810 }
811 }
812 else if (c > '\0')
813 {
814 num2--;
815 byte[] array3 = null;
816 array3 = ((!bigEndian) ? new byte[2]
817 {
818 (byte)c,
819 (byte)((int)c >> 8)
820 } : new byte[2]
821 {
822 (byte)((int)c >> 8),
823 (byte)c
824 });
825 if (decoderFallbackBuffer == null)
826 {
827 decoderFallbackBuffer = ((decoder != null) ? decoder.FallbackBuffer : decoderFallback.CreateFallbackBuffer());
828 decoderFallbackBuffer.InternalInitialize(byteStart, null);
829 }
830 num2 += decoderFallbackBuffer.InternalFallback(array3, bytes);
831 c = '\0';
832 }
833 }
834 if (decoder == null || decoder.MustFlush)
835 {
836 if (c > '\0')
837 {
838 num2--;
839 byte[] array4 = null;
840 array4 = ((!bigEndian) ? new byte[2]
841 {
842 (byte)c,
843 (byte)((int)c >> 8)
844 } : new byte[2]
845 {
846 (byte)((int)c >> 8),
847 (byte)c
848 });
849 if (decoderFallbackBuffer == null)
850 {
851 decoderFallbackBuffer = ((decoder != null) ? decoder.FallbackBuffer : decoderFallback.CreateFallbackBuffer());
852 decoderFallbackBuffer.InternalInitialize(byteStart, null);
853 }
854 num2 += decoderFallbackBuffer.InternalFallback(array4, bytes);
855 c = '\0';
856 }
857 if (num >= 0)
858 {
859 if (decoderFallbackBuffer == null)
860 {
861 decoderFallbackBuffer = ((decoder != null) ? decoder.FallbackBuffer : decoderFallback.CreateFallbackBuffer());
862 decoderFallbackBuffer.InternalInitialize(byteStart, null);
863 }
864 num2 += decoderFallbackBuffer.InternalFallback(new byte[1] { (byte)num }, bytes);
865 num = -1;
866 }
867 }
868 if (c > '\0')
869 {
870 num2--;
871 }
872 return num2;
873 }
DecoderFallback decoderFallback
Definition Encoding.cs:343

References System.array, System.Text.UnicodeEncoding.bigEndian, System.bytes, System.count, System.Text.DecoderFallback.CreateFallbackBuffer(), System.Text.Encoding.decoderFallback, System.Text.DecoderNLS.FallbackBuffer, System.Text.DecoderFallbackBuffer.InternalFallback(), System.Text.DecoderFallbackBuffer.InternalInitialize(), System.BitConverter.IsLittleEndian, System.L, System.Text.UnicodeEncoding.Decoder.lastByte, System.Text.UnicodeEncoding.Decoder.lastChar, and System.Text.DecoderNLS.MustFlush.