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

◆ TryReadChars()

bool System.Xml.ValueHandle.TryReadChars ( char[] chars,
int offset,
int count,
out int actual )
inline

Definition at line 658 of file ValueHandle.cs.

659 {
660 if (_type == ValueHandleType.Unicode)
661 {
663 }
664 if (_type != ValueHandleType.UTF8)
665 {
666 actual = 0;
667 return false;
668 }
669 int num = offset;
670 int num2 = count;
671 byte[] buffer = _bufferReader.Buffer;
672 int num3 = _offset;
673 int num4 = _length;
674 bool flag = false;
676 while (true)
677 {
678 if (num2 > 0 && num4 > 0)
679 {
680 byte b = buffer[num3];
681 if (b < 128)
682 {
683 chars[num] = (char)b;
684 num3++;
685 num4--;
686 num++;
687 num2--;
688 continue;
689 }
690 }
691 if (num2 == 0 || num4 == 0 || flag)
692 {
693 break;
694 }
695 int chars2;
696 int num5;
697 try
698 {
699 if (num2 >= uTF8Encoding.GetMaxCharCount(num4) || num2 >= uTF8Encoding.GetCharCount(buffer, num3, num4))
700 {
701 chars2 = uTF8Encoding.GetChars(buffer, num3, num4, chars, num);
702 num5 = num4;
703 }
704 else
705 {
706 Decoder decoder = uTF8Encoding.GetDecoder();
707 num5 = Math.Min(num2, num4);
708 chars2 = decoder.GetChars(buffer, num3, num5, chars, num);
709 while (chars2 == 0)
710 {
711 if (num5 >= 3 && num2 < 2)
712 {
713 flag = true;
714 break;
715 }
716 chars2 = decoder.GetChars(buffer, num3 + num5, 1, chars, num);
717 num5++;
718 }
719 num5 = uTF8Encoding.GetByteCount(chars, num, chars2);
720 }
721 }
722 catch (FormatException exception)
723 {
724 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateEncodingException(buffer, num3, num4, exception));
725 }
726 num3 += num5;
727 num4 -= num5;
728 num += chars2;
729 num2 -= chars2;
730 }
731 _offset = num3;
732 _length = num4;
733 actual = count - num2;
734 return true;
735 }
int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex)
bool TryReadUnicodeChars(char[] chars, int offset, int count, out int actual)
ValueHandleType _type
readonly XmlBufferReader _bufferReader
Definition ValueHandle.cs:9

References System.Xml.ValueHandle._bufferReader, System.Xml.ValueHandle._length, System.Xml.ValueHandle._offset, System.Xml.ValueHandle._type, System.buffer, System.Xml.XmlBufferReader.Buffer, System.chars, System.count, System.Xml.XmlExceptionHelper.CreateEncodingException(), System.Xml.Dictionary, System.exception, System.Text.Decoder.GetChars(), System.Math.Min(), System.offset, System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(), and System.Xml.ValueHandle.TryReadUnicodeChars().

Referenced by System.Xml.XmlBaseReader.ReadValueChunk().