Terraria
v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
ByteEncoder.cs
Go to the documentation of this file.
1
using
System.Text
;
2
3
namespace
System.Net.Mime
;
4
5
internal
abstract
class
ByteEncoder
:
IByteEncoder
6
{
7
internal
abstract
WriteStateInfoBase
WriteState {
get
; }
8
9
protected
abstract
bool
HasSpecialEncodingForCRLF
{
get
; }
10
11
public
string
GetEncodedString
()
12
{
13
return
Encoding
.
ASCII
.GetString(WriteState.Buffer, 0, WriteState.Length);
14
}
15
16
public
int
EncodeBytes
(
byte
[]
buffer
,
int
offset
,
int
count
,
bool
dontDeferFinalBytes,
bool
shouldAppendSpaceToCRLF)
17
{
18
WriteState.AppendHeader();
19
bool
hasSpecialEncodingForCRLF =
HasSpecialEncodingForCRLF
;
20
int
i;
21
for
(i =
offset
; i <
count
+
offset
; i++)
22
{
23
if
(
LineBreakNeeded
(
buffer
[i]))
24
{
25
AppendPadding
();
26
WriteState.AppendCRLF(shouldAppendSpaceToCRLF);
27
}
28
if
(hasSpecialEncodingForCRLF &&
IsCRLF
(
buffer
, i,
count
+
offset
))
29
{
30
AppendEncodedCRLF
();
31
i++;
32
}
33
else
34
{
35
ApppendEncodedByte
(
buffer
[i]);
36
}
37
}
38
if
(dontDeferFinalBytes)
39
{
40
AppendPadding
();
41
}
42
WriteState.AppendFooter();
43
return
i -
offset
;
44
}
45
46
public
int
EncodeString
(
string
value
,
Encoding
encoding)
47
{
48
if
(encoding ==
Encoding
.
Latin1
)
49
{
50
byte
[]
bytes
= encoding.
GetBytes
(
value
);
51
return
EncodeBytes
(
bytes
, 0,
bytes
.Length, dontDeferFinalBytes:
true
, shouldAppendSpaceToCRLF:
true
);
52
}
53
WriteState.AppendHeader();
54
bool
hasSpecialEncodingForCRLF =
HasSpecialEncodingForCRLF
;
55
int
num = 0;
56
byte
[] bytes2 =
new
byte
[encoding.
GetMaxByteCount
(2)];
57
for
(
int
i = 0; i <
value
.Length; i++)
58
{
59
int
codepointSize =
GetCodepointSize
(
value
, i);
60
int
bytes3 = encoding.
GetBytes
(
value
, i, codepointSize, bytes2, 0);
61
if
(codepointSize == 2)
62
{
63
i++;
64
}
65
if
(
LineBreakNeeded
(bytes2, bytes3))
66
{
67
AppendPadding
();
68
WriteState.AppendCRLF(includeSpace:
true
);
69
}
70
if
(hasSpecialEncodingForCRLF &&
IsCRLF
(bytes2, bytes3))
71
{
72
AppendEncodedCRLF
();
73
}
74
else
75
{
76
AppendEncodedCodepoint
(bytes2, bytes3);
77
}
78
num += bytes3;
79
}
80
AppendPadding
();
81
WriteState.AppendFooter();
82
return
num;
83
}
84
85
protected
abstract
void
AppendEncodedCRLF
();
86
87
protected
abstract
bool
LineBreakNeeded
(
byte
b);
88
89
protected
abstract
bool
LineBreakNeeded
(
byte
[]
bytes
,
int
count
);
90
91
protected
abstract
int
GetCodepointSize
(
string
value
,
int
i);
92
93
public
abstract
void
AppendPadding
();
94
95
protected
abstract
void
ApppendEncodedByte
(
byte
b);
96
97
private
void
AppendEncodedCodepoint
(
byte
[]
bytes
,
int
count
)
98
{
99
for
(
int
i = 0; i <
count
; i++)
100
{
101
ApppendEncodedByte
(
bytes
[i]);
102
}
103
}
104
105
protected
bool
IsSurrogatePair
(
string
value
,
int
i)
106
{
107
if
(
char
.IsSurrogate(
value
[i]) && i + 1 <
value
.Length)
108
{
109
return
char
.IsSurrogatePair(
value
[i],
value
[i + 1]);
110
}
111
return
false
;
112
}
113
114
protected
bool
IsCRLF
(
byte
[]
bytes
,
int
count
)
115
{
116
if
(
count
== 2)
117
{
118
return
IsCRLF
(
bytes
, 0,
count
);
119
}
120
return
false
;
121
}
122
123
private
bool
IsCRLF
(
byte
[]
buffer
,
int
i,
int
bufferSize)
124
{
125
if
(
buffer
[i] == 13 && i + 1 < bufferSize)
126
{
127
return
buffer
[i + 1] == 10;
128
}
129
return
false
;
130
}
131
}
System.Net.Mime.ByteEncoder.ApppendEncodedByte
void ApppendEncodedByte(byte b)
System.Net.Mime.ByteEncoder.LineBreakNeeded
bool LineBreakNeeded(byte[] bytes, int count)
System.Net.Mime.ByteEncoder.IsSurrogatePair
bool IsSurrogatePair(string value, int i)
Definition
ByteEncoder.cs:105
System.Net.Mime.ByteEncoder.EncodeBytes
int EncodeBytes(byte[] buffer, int offset, int count, bool dontDeferFinalBytes, bool shouldAppendSpaceToCRLF)
Definition
ByteEncoder.cs:16
System.Net.Mime.ByteEncoder.HasSpecialEncodingForCRLF
bool HasSpecialEncodingForCRLF
Definition
ByteEncoder.cs:9
System.Net.Mime.ByteEncoder.IsCRLF
bool IsCRLF(byte[] buffer, int i, int bufferSize)
Definition
ByteEncoder.cs:123
System.Net.Mime.ByteEncoder.AppendEncodedCodepoint
void AppendEncodedCodepoint(byte[] bytes, int count)
Definition
ByteEncoder.cs:97
System.Net.Mime.ByteEncoder.EncodeString
int EncodeString(string value, Encoding encoding)
Definition
ByteEncoder.cs:46
System.Net.Mime.ByteEncoder.AppendEncodedCRLF
void AppendEncodedCRLF()
System.Net.Mime.ByteEncoder.AppendPadding
void AppendPadding()
System.Net.Mime.ByteEncoder.GetCodepointSize
int GetCodepointSize(string value, int i)
System.Net.Mime.ByteEncoder.IsCRLF
bool IsCRLF(byte[] bytes, int count)
Definition
ByteEncoder.cs:114
System.Net.Mime.ByteEncoder.GetEncodedString
string GetEncodedString()
Definition
ByteEncoder.cs:11
System.Net.Mime.ByteEncoder.LineBreakNeeded
bool LineBreakNeeded(byte b)
System.Net.Mime.ByteEncoder
Definition
ByteEncoder.cs:6
System.Net.Mime.WriteStateInfoBase
Definition
WriteStateInfoBase.cs:4
System.Text.Encoding.Latin1
static Encoding Latin1
Definition
Encoding.cs:513
System.Text.Encoding.ASCII
static Encoding ASCII
Definition
Encoding.cs:511
System.Text.Encoding.GetBytes
virtual byte[] GetBytes(char[] chars)
Definition
Encoding.cs:781
System.Text.Encoding.GetMaxByteCount
int GetMaxByteCount(int charCount)
System.Text.Encoding
Definition
Encoding.cs:15
System.Net.Mime.IByteEncoder
Definition
IByteEncoder.cs:6
System.Net.Mime
Definition
Base64Encoder.cs:1
System.Text
Definition
ConsoleEncoding.cs:1
System.ExceptionArgument.value
@ value
System.ExceptionArgument.bytes
@ bytes
System.ExceptionArgument.offset
@ offset
System.ExceptionArgument.buffer
@ buffer
System.ExceptionArgument.count
@ count
source
System.Net.Mail
System.Net.Mime
ByteEncoder.cs
Generated by
1.10.0