Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
BufferBuilder.cs
Go to the documentation of this file.
1using System.Text;
2
3namespace System.Net.Mail;
4
5internal sealed class BufferBuilder
6{
7 private byte[] _buffer;
8
9 private int _offset;
10
11 internal int Length => _offset;
12
13 internal BufferBuilder()
14 : this(256)
15 {
16 }
17
18 internal BufferBuilder(int initialSize)
19 {
20 _buffer = new byte[initialSize];
21 }
22
23 private void EnsureBuffer(int count)
24 {
25 if (count > _buffer.Length - _offset)
26 {
27 byte[] array = new byte[(_buffer.Length * 2 > _buffer.Length + count) ? (_buffer.Length * 2) : (_buffer.Length + count)];
29 _buffer = array;
30 }
31 }
32
33 internal void Append(byte value)
34 {
35 EnsureBuffer(1);
37 }
38
39 internal void Append(byte[] value)
40 {
41 Append(value, 0, value.Length);
42 }
43
44 internal void Append(byte[] value, int offset, int count)
45 {
48 _offset += count;
49 }
50
51 internal void Append(string value)
52 {
53 Append(value, allowUnicode: false);
54 }
55
56 internal void Append(string value, bool allowUnicode)
57 {
58 if (!string.IsNullOrEmpty(value))
59 {
60 Append(value, 0, value.Length, allowUnicode);
61 }
62 }
63
64 internal void Append(string value, int offset, int count, bool allowUnicode)
65 {
66 if (allowUnicode)
67 {
68 int byteCount = Encoding.UTF8.GetByteCount(value, offset, count);
72 }
73 else
74 {
76 }
77 }
78
79 internal void Append(string value, int offset, int count)
80 {
82 for (int i = 0; i < count; i++)
83 {
84 char c = value[offset + i];
85 if (c > 'ΓΏ')
86 {
88 }
89 _buffer[_offset + i] = (byte)c;
90 }
91 _offset += count;
92 }
93
94 internal byte[] GetBuffer()
95 {
96 return _buffer;
97 }
98
99 internal void Reset()
100 {
101 _offset = 0;
102 }
103}
static void BlockCopy(Array src, int srcOffset, Array dst, int dstOffset, int count)
Definition Buffer.cs:102
void Append(string value, int offset, int count)
void Append(string value, bool allowUnicode)
void Append(byte[] value, int offset, int count)
void Append(string value, int offset, int count, bool allowUnicode)
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string MailHeaderFieldInvalidCharacter
Definition SR.cs:140
Definition SR.cs:7
static Encoding UTF8
Definition Encoding.cs:526