Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
EncodingByteBuffer.cs
Go to the documentation of this file.
1namespace System.Text;
2
3internal sealed class EncodingByteBuffer
4{
5 private unsafe byte* _bytes;
6
7 private unsafe readonly byte* _byteStart;
8
9 private unsafe readonly byte* _byteEnd;
10
11 private unsafe char* _chars;
12
13 private unsafe readonly char* _charStart;
14
15 private unsafe readonly char* _charEnd;
16
17 private int _byteCountResult;
18
19 private readonly EncodingNLS _enc;
20
22
24
26
27 internal unsafe bool MoreData
28 {
29 get
30 {
32 {
33 return _chars < _charEnd;
34 }
35 return true;
36 }
37 }
38
39 internal unsafe int CharsUsed => (int)(_chars - _charStart);
40
41 internal int Count => _byteCountResult;
42
43 internal unsafe EncodingByteBuffer(EncodingNLS inEncoding, System.Text.EncoderNLS inEncoder, byte* inByteStart, int inByteCount, char* inCharStart, int inCharCount)
44 {
45 _enc = inEncoding;
46 _encoder = inEncoder;
47 _charStart = inCharStart;
48 _chars = inCharStart;
49 _charEnd = inCharStart + inCharCount;
50 _bytes = inByteStart;
51 _byteStart = inByteStart;
52 _byteEnd = inByteStart + inByteCount;
53 if (_encoder == null)
54 {
56 }
57 else
58 {
59 fallbackBuffer = _encoder.FallbackBuffer;
60 if (_encoder.m_throwOnOverflow && _encoder.InternalHasFallbackBuffer && fallbackBuffer.Remaining > 0)
61 {
62 throw new ArgumentException(System.SR.Format(System.SR.Argument_EncoderFallbackNotEmpty, _encoder.Encoding.EncodingName, _encoder.Fallback.GetType()));
63 }
64 }
67 }
68
69 internal unsafe bool AddByte(byte b, int moreBytesExpected)
70 {
71 if (_bytes != null)
72 {
73 if (_bytes >= _byteEnd - moreBytesExpected)
74 {
75 MovePrevious(bThrow: true);
76 return false;
77 }
78 *(_bytes++) = b;
79 }
81 return true;
82 }
83
84 internal bool AddByte(byte b1)
85 {
86 return AddByte(b1, 0);
87 }
88
89 internal bool AddByte(byte b1, byte b2)
90 {
91 return AddByte(b1, b2, 0);
92 }
93
94 internal bool AddByte(byte b1, byte b2, int moreBytesExpected)
95 {
96 if (AddByte(b1, 1 + moreBytesExpected))
97 {
98 return AddByte(b2, moreBytesExpected);
99 }
100 return false;
101 }
102
103 internal bool AddByte(byte b1, byte b2, byte b3)
104 {
105 return AddByte(b1, b2, b3, 0);
106 }
107
108 internal bool AddByte(byte b1, byte b2, byte b3, int moreBytesExpected)
109 {
110 if (AddByte(b1, 2 + moreBytesExpected) && AddByte(b2, 1 + moreBytesExpected))
111 {
112 return AddByte(b3, moreBytesExpected);
113 }
114 return false;
115 }
116
117 internal bool AddByte(byte b1, byte b2, byte b3, byte b4)
118 {
119 if (AddByte(b1, 3) && AddByte(b2, 2) && AddByte(b3, 1))
120 {
121 return AddByte(b4, 0);
122 }
123 return false;
124 }
125
126 internal unsafe void MovePrevious(bool bThrow)
127 {
129 {
131 }
132 else if (_chars > _charStart)
133 {
134 _chars--;
135 }
136 if (bThrow)
137 {
139 }
140 }
141
142 internal unsafe bool Fallback(char charFallback)
143 {
144 return fallbackBufferHelper.InternalFallback(charFallback, ref _chars);
145 }
146
147 internal unsafe char GetNextChar()
148 {
150 if (c == '\0' && _chars < _charEnd)
151 {
152 c = *(_chars++);
153 }
154 return c;
155 }
156}
static string Argument_EncoderFallbackNotEmpty
Definition SR.cs:590
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
Definition SR.cs:7
EncoderFallbackBuffer CreateFallbackBuffer()
EncoderFallbackBuffer fallbackBuffer
bool AddByte(byte b1, byte b2, byte b3, byte b4)
unsafe bool Fallback(char charFallback)
unsafe void MovePrevious(bool bThrow)
unsafe readonly char * _charStart
unsafe readonly char * _charEnd
EncoderFallbackBufferHelper fallbackBufferHelper
bool AddByte(byte b1, byte b2, byte b3)
bool AddByte(byte b1, byte b2, byte b3, int moreBytesExpected)
bool AddByte(byte b1, byte b2, int moreBytesExpected)
unsafe readonly byte * _byteEnd
readonly System.Text.EncoderNLS _encoder
unsafe EncodingByteBuffer(EncodingNLS inEncoding, System.Text.EncoderNLS inEncoder, byte *inByteStart, int inByteCount, char *inCharStart, int inCharCount)
unsafe bool AddByte(byte b, int moreBytesExpected)
unsafe readonly byte * _byteStart
void ThrowBytesOverflow(System.Text.EncoderNLS encoder, bool nothingEncoded)
EncoderFallback EncoderFallback
Definition Encoding.cs:460
unsafe void InternalInitialize(char *_charStart, char *_charEnd, System.Text.EncoderNLS _encoder, bool _setEncoder)
unsafe bool InternalFallback(char ch, ref char *chars)