Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
EncodingCharBuffer.cs
Go to the documentation of this file.
1namespace System.Text;
2
3internal sealed class EncodingCharBuffer
4{
5 private unsafe char* _chars;
6
7 private unsafe readonly char* _charStart;
8
9 private unsafe readonly char* _charEnd;
10
11 private int _charCountResult;
12
13 private readonly EncodingNLS _enc;
14
16
17 private unsafe readonly byte* _byteStart;
18
19 private unsafe readonly byte* _byteEnd;
20
21 private unsafe byte* _bytes;
22
24
26
27 internal unsafe bool MoreData => _bytes < _byteEnd;
28
29 internal unsafe int BytesUsed => (int)(_bytes - _byteStart);
30
31 internal int Count => _charCountResult;
32
33 internal unsafe EncodingCharBuffer(EncodingNLS enc, System.Text.DecoderNLS decoder, char* charStart, int charCount, byte* byteStart, int byteCount)
34 {
35 _enc = enc;
36 _decoder = decoder;
37 _chars = charStart;
38 _charStart = charStart;
39 _charEnd = charStart + charCount;
40 _byteStart = byteStart;
41 _bytes = byteStart;
42 _byteEnd = byteStart + byteCount;
43 if (_decoder == null)
44 {
46 }
47 else
48 {
49 _fallbackBuffer = _decoder.FallbackBuffer;
50 }
53 }
54
55 internal unsafe bool AddChar(char ch, int numBytes)
56 {
57 if (_chars != null)
58 {
59 if (_chars >= _charEnd)
60 {
61 _bytes -= numBytes;
63 return false;
64 }
65 *(_chars++) = ch;
66 }
68 return true;
69 }
70
71 internal bool AddChar(char ch)
72 {
73 return AddChar(ch, 1);
74 }
75
76 internal unsafe bool AddChar(char ch1, char ch2, int numBytes)
77 {
78 if (_chars >= _charEnd - 1)
79 {
80 _bytes -= numBytes;
82 return false;
83 }
84 if (AddChar(ch1, numBytes))
85 {
86 return AddChar(ch2, numBytes);
87 }
88 return false;
89 }
90
91 internal unsafe void AdjustBytes(int count)
92 {
93 _bytes += count;
94 }
95
96 internal unsafe bool EvenMoreData(int count)
97 {
98 return _bytes <= _byteEnd - count;
99 }
100
101 internal unsafe byte GetNextByte()
102 {
103 if (_bytes >= _byteEnd)
104 {
105 return 0;
106 }
107 return *(_bytes++);
108 }
109
110 internal bool Fallback(byte fallbackByte)
111 {
112 byte[] byteBuffer = new byte[1] { fallbackByte };
113 return Fallback(byteBuffer);
114 }
115
116 internal bool Fallback(byte byte1, byte byte2)
117 {
118 byte[] byteBuffer = new byte[2] { byte1, byte2 };
119 return Fallback(byteBuffer);
120 }
121
122 internal bool Fallback(byte byte1, byte byte2, byte byte3, byte byte4)
123 {
124 byte[] byteBuffer = new byte[4] { byte1, byte2, byte3, byte4 };
125 return Fallback(byteBuffer);
126 }
127
128 internal unsafe bool Fallback(byte[] byteBuffer)
129 {
130 if (_chars != null)
131 {
132 char* chars = _chars;
134 {
135 _bytes -= byteBuffer.Length;
138 return false;
139 }
140 _charCountResult += (int)(_chars - chars);
141 }
142 else
143 {
145 }
146 return true;
147 }
148}
DecoderFallbackBuffer CreateFallbackBuffer()
unsafe readonly char * _charStart
bool Fallback(byte fallbackByte)
unsafe readonly byte * _byteStart
unsafe bool Fallback(byte[] byteBuffer)
unsafe EncodingCharBuffer(EncodingNLS enc, System.Text.DecoderNLS decoder, char *charStart, int charCount, byte *byteStart, int byteCount)
unsafe readonly char * _charEnd
bool Fallback(byte byte1, byte byte2, byte byte3, byte byte4)
unsafe readonly byte * _byteEnd
readonly DecoderFallbackBuffer _fallbackBuffer
readonly System.Text.DecoderNLS _decoder
unsafe bool AddChar(char ch, int numBytes)
bool Fallback(byte byte1, byte byte2)
DecoderFallbackBufferHelper _fallbackBufferHelper
unsafe bool EvenMoreData(int count)
unsafe bool AddChar(char ch1, char ch2, int numBytes)
unsafe void AdjustBytes(int count)
void ThrowCharsOverflow(System.Text.DecoderNLS decoder, bool nothingDecoded)
DecoderFallback DecoderFallback
Definition Encoding.cs:480
unsafe bool InternalFallback(byte[] bytes, byte *pBytes, ref char *chars)
unsafe void InternalInitialize(byte *_byteStart, char *_charEnd)