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

◆ GetCharsCP5022xJP()

unsafe int System.Text.ISO2022Encoding.GetCharsCP5022xJP ( byte * bytes,
int byteCount,
char * chars,
int charCount,
ISO2022Decoder decoder )
inlineprivate

Definition at line 614 of file ISO2022Encoding.cs.

615 {
616 EncodingCharBuffer encodingCharBuffer = new EncodingCharBuffer(this, decoder, chars, charCount, bytes, byteCount);
617 ISO2022Modes iSO2022Modes = ISO2022Modes.ModeASCII;
618 ISO2022Modes iSO2022Modes2 = ISO2022Modes.ModeASCII;
619 byte[] bytes2 = new byte[4];
620 int count = 0;
621 if (decoder != null)
622 {
623 iSO2022Modes = decoder.currentMode;
624 iSO2022Modes2 = decoder.shiftInOutMode;
625 count = decoder.bytesLeftOverCount;
626 for (int i = 0; i < count; i++)
627 {
628 bytes2[i] = decoder.bytesLeftOver[i];
629 }
630 }
631 while (encodingCharBuffer.MoreData || count > 0)
632 {
633 byte b;
634 if (count > 0)
635 {
636 if (bytes2[0] == 27)
637 {
638 if (!encodingCharBuffer.MoreData)
639 {
640 if (decoder != null && !decoder.MustFlush)
641 {
642 break;
643 }
644 }
645 else
646 {
647 bytes2[count++] = encodingCharBuffer.GetNextByte();
648 ISO2022Modes iSO2022Modes3 = CheckEscapeSequenceJP(bytes2, count);
649 switch (iSO2022Modes3)
650 {
651 default:
652 count = 0;
653 iSO2022Modes = (iSO2022Modes2 = iSO2022Modes3);
654 continue;
655 case ISO2022Modes.ModeInvalidEscape:
656 break;
657 case ISO2022Modes.ModeIncompleteEscape:
658 continue;
659 }
660 }
661 }
662 b = DecrementEscapeBytes(ref bytes2, ref count);
663 }
664 else
665 {
666 b = encodingCharBuffer.GetNextByte();
667 if (b == 27)
668 {
669 if (count == 0)
670 {
671 bytes2[0] = b;
672 count = 1;
673 continue;
674 }
675 encodingCharBuffer.AdjustBytes(-1);
676 }
677 }
678 switch (b)
679 {
680 case 14:
681 iSO2022Modes2 = iSO2022Modes;
682 iSO2022Modes = ISO2022Modes.ModeHalfwidthKatakana;
683 continue;
684 case 15:
685 iSO2022Modes = iSO2022Modes2;
686 continue;
687 }
688 ushort num = b;
689 bool flag = false;
690 if (iSO2022Modes == ISO2022Modes.ModeJIS0208)
691 {
692 if (count > 0)
693 {
694 if (bytes2[0] != 27)
695 {
696 num <<= 8;
697 num |= DecrementEscapeBytes(ref bytes2, ref count);
698 flag = true;
699 }
700 }
701 else
702 {
703 if (!encodingCharBuffer.MoreData)
704 {
705 if (decoder == null || decoder.MustFlush)
706 {
707 encodingCharBuffer.Fallback(b);
708 }
709 else if (chars != null)
710 {
711 bytes2[0] = b;
712 count = 1;
713 }
714 break;
715 }
716 num <<= 8;
717 num |= encodingCharBuffer.GetNextByte();
718 flag = true;
719 }
720 if (flag && (num & 0xFF00) == 10752)
721 {
722 num = (ushort)(num & 0xFFu);
723 num = (ushort)(num | 0x1000u);
724 }
725 }
726 else if (num >= 161 && num <= 223)
727 {
728 num = (ushort)(num | 0x1000u);
729 num = (ushort)(num & 0xFF7Fu);
730 }
731 else if (iSO2022Modes == ISO2022Modes.ModeHalfwidthKatakana)
732 {
733 num = (ushort)(num | 0x1000u);
734 }
735 char c = mapBytesToUnicode[(int)num];
736 if (c == '\0' && num != 0)
737 {
738 if (flag)
739 {
740 if (!encodingCharBuffer.Fallback((byte)(num >> 8), (byte)num))
741 {
742 break;
743 }
744 }
745 else if (!encodingCharBuffer.Fallback(b))
746 {
747 break;
748 }
749 }
750 else if (!encodingCharBuffer.AddChar(c, (!flag) ? 1 : 2))
751 {
752 break;
753 }
754 }
755 if (chars != null && decoder != null)
756 {
757 if (!decoder.MustFlush || count != 0)
758 {
759 decoder.currentMode = iSO2022Modes;
760 decoder.shiftInOutMode = iSO2022Modes2;
761 decoder.bytesLeftOverCount = count;
762 decoder.bytesLeftOver = bytes2;
763 }
764 else
765 {
766 decoder.currentMode = ISO2022Modes.ModeASCII;
767 decoder.shiftInOutMode = ISO2022Modes.ModeASCII;
768 decoder.bytesLeftOverCount = 0;
769 }
770 decoder.m_bytesUsed = encodingCharBuffer.BytesUsed;
771 }
772 return encodingCharBuffer.Count;
773 }
ISO2022Modes CheckEscapeSequenceJP(byte[] bytes, int escapeCount)
byte DecrementEscapeBytes(ref byte[] bytes, ref int count)

References System.Text.Encoding.EncodingCharBuffer.AddChar(), System.Text.Encoding.EncodingCharBuffer.AdjustBytes(), System.byteCount, System.bytes, System.Text.ISO2022Encoding.ISO2022Decoder.bytesLeftOver, System.Text.ISO2022Encoding.ISO2022Decoder.bytesLeftOverCount, System.Text.Encoding.EncodingCharBuffer.BytesUsed, System.charCount, System.chars, System.Text.ISO2022Encoding.CheckEscapeSequenceJP(), System.count, System.Text.Encoding.EncodingCharBuffer.Count, System.Text.ISO2022Encoding.ISO2022Decoder.currentMode, System.Text.ISO2022Encoding.DecrementEscapeBytes(), System.Text.Encoding.EncodingCharBuffer.Fallback(), System.Text.Encoding.EncodingCharBuffer.GetNextByte(), System.Text.DBCSCodePageEncoding.mapBytesToUnicode, System.Text.Encoding.EncodingCharBuffer.MoreData, System.Text.DecoderNLS.MustFlush, and System.Text.ISO2022Encoding.ISO2022Decoder.shiftInOutMode.

Referenced by System.Text.ISO2022Encoding.GetChars().