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

◆ GetCharCount() [2/5]

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

Reimplemented from System.Text.Encoding.

Definition at line 545 of file UTF32Encoding.cs.

546 {
547 UTF32Decoder uTF32Decoder = (UTF32Decoder)baseDecoder;
548 int num = 0;
549 byte* ptr = bytes + count;
550 byte* byteStart = bytes;
551 int num2 = 0;
552 uint num3 = 0u;
553 DecoderFallbackBuffer decoderFallbackBuffer = null;
554 if (uTF32Decoder != null)
555 {
556 num2 = uTF32Decoder.readByteCount;
557 num3 = (uint)uTF32Decoder.iChar;
558 decoderFallbackBuffer = uTF32Decoder.FallbackBuffer;
559 }
560 else
561 {
562 decoderFallbackBuffer = decoderFallback.CreateFallbackBuffer();
563 }
564 decoderFallbackBuffer.InternalInitialize(byteStart, null);
565 while (bytes < ptr && num >= 0)
566 {
567 if (_bigEndian)
568 {
569 num3 <<= 8;
570 num3 += *(bytes++);
571 }
572 else
573 {
574 num3 >>= 8;
575 num3 += (uint)(*(bytes++) << 24);
576 }
577 num2++;
578 if (num2 < 4)
579 {
580 continue;
581 }
582 num2 = 0;
583 if (num3 > 1114111 || (num3 >= 55296 && num3 <= 57343))
584 {
585 byte[] bytes2 = ((!_bigEndian) ? new byte[4]
586 {
587 (byte)num3,
588 (byte)(num3 >> 8),
589 (byte)(num3 >> 16),
590 (byte)(num3 >> 24)
591 } : new byte[4]
592 {
593 (byte)(num3 >> 24),
594 (byte)(num3 >> 16),
595 (byte)(num3 >> 8),
596 (byte)num3
597 });
598 num += decoderFallbackBuffer.InternalFallback(bytes2, bytes);
599 num3 = 0u;
600 }
601 else
602 {
603 if (num3 >= 65536)
604 {
605 num++;
606 }
607 num++;
608 num3 = 0u;
609 }
610 }
611 if (num2 > 0 && (uTF32Decoder == null || uTF32Decoder.MustFlush))
612 {
613 byte[] array = new byte[num2];
614 if (_bigEndian)
615 {
616 while (num2 > 0)
617 {
618 array[--num2] = (byte)num3;
619 num3 >>= 8;
620 }
621 }
622 else
623 {
624 while (num2 > 0)
625 {
626 array[--num2] = (byte)(num3 >> 24);
627 num3 <<= 8;
628 }
629 }
630 num += decoderFallbackBuffer.InternalFallback(array, bytes);
631 }
632 if (num < 0)
633 {
634 throw new ArgumentOutOfRangeException("count", SR.ArgumentOutOfRange_GetByteCountOverflow);
635 }
636 return num;
637 }
unsafe void InternalInitialize(byte *byteStart, char *charEnd)
DecoderFallbackBuffer CreateFallbackBuffer()
DecoderFallback decoderFallback
Definition Encoding.cs:343

References System.Text.UTF32Encoding._bigEndian, System.SR.ArgumentOutOfRange_GetByteCountOverflow, System.array, System.bytes, System.count, System.Text.DecoderFallback.CreateFallbackBuffer(), System.Text.Encoding.decoderFallback, System.Text.DecoderNLS.FallbackBuffer, System.Text.UTF32Encoding.UTF32Decoder.iChar, System.Text.DecoderFallbackBuffer.InternalFallback(), System.Text.DecoderFallbackBuffer.InternalInitialize(), System.Text.DecoderNLS.MustFlush, and System.Text.UTF32Encoding.UTF32Decoder.readByteCount.