Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
QEncoder.cs
Go to the documentation of this file.
1namespace System.Net.Mime;
2
3internal sealed class QEncoder : ByteEncoder
4{
6
7 internal override WriteStateInfoBase WriteState => _writeState;
8
9 protected override bool HasSpecialEncodingForCRLF => true;
10
12 {
13 _writeState = wsi;
14 }
15
16 protected override void AppendEncodedCRLF()
17 {
18 WriteState.Append(61, 48, 68, 61, 48, 65);
19 }
20
21 protected override bool LineBreakNeeded(byte b)
22 {
23 int num = WriteState.CurrentLineLength + 3 + WriteState.FooterLength;
24 bool flag = b == 32 || b == 9 || b == 13 || b == 10;
25 if (num >= WriteState.MaxLineLength && flag)
26 {
27 return true;
28 }
29 int num2 = WriteState.CurrentLineLength + WriteState.FooterLength;
30 if (num2 >= WriteState.MaxLineLength)
31 {
32 return true;
33 }
34 return false;
35 }
36
37 protected override bool LineBreakNeeded(byte[] bytes, int count)
38 {
39 if (count == 1 || IsCRLF(bytes, count))
40 {
41 return LineBreakNeeded(bytes[0]);
42 }
43 int num = count * 3;
44 return WriteState.CurrentLineLength + num + _writeState.FooterLength > WriteState.MaxLineLength;
45 }
46
47 protected override int GetCodepointSize(string value, int i)
48 {
49 if (value[i] == '\r' && i + 1 < value.Length && value[i + 1] == '\n')
50 {
51 return 2;
52 }
53 if (IsSurrogatePair(value, i))
54 {
55 return 2;
56 }
57 return 1;
58 }
59
60 public override void AppendPadding()
61 {
62 }
63
64 protected override void ApppendEncodedByte(byte b)
65 {
66 if (b == 32)
67 {
68 WriteState.Append(95);
69 return;
70 }
71 if (IsAsciiLetterOrDigit((char)b))
72 {
73 WriteState.Append(b);
74 return;
75 }
76 WriteState.Append(61);
77 WriteState.Append((byte)System.HexConverter.ToCharUpper(b >> 4));
78 WriteState.Append((byte)System.HexConverter.ToCharUpper(b));
79 }
80
81 private static bool IsAsciiLetterOrDigit(char character)
82 {
83 if (!IsAsciiLetter(character))
84 {
85 if (character >= '0')
86 {
87 return character <= '9';
88 }
89 return false;
90 }
91 return true;
92 }
93
94 private static bool IsAsciiLetter(char character)
95 {
96 if (character < 'a' || character > 'z')
97 {
98 if (character >= 'A')
99 {
100 return character <= 'Z';
101 }
102 return false;
103 }
104 return true;
105 }
106}
static char ToCharUpper(int value)
bool IsSurrogatePair(string value, int i)
bool IsCRLF(byte[] bytes, int count)
readonly WriteStateInfoBase _writeState
Definition QEncoder.cs:5
override bool HasSpecialEncodingForCRLF
Definition QEncoder.cs:9
QEncoder(WriteStateInfoBase wsi)
Definition QEncoder.cs:11
override void ApppendEncodedByte(byte b)
Definition QEncoder.cs:64
override int GetCodepointSize(string value, int i)
Definition QEncoder.cs:47
override bool LineBreakNeeded(byte b)
Definition QEncoder.cs:21
static bool IsAsciiLetter(char character)
Definition QEncoder.cs:94
override void AppendPadding()
Definition QEncoder.cs:60
override void AppendEncodedCRLF()
Definition QEncoder.cs:16
override bool LineBreakNeeded(byte[] bytes, int count)
Definition QEncoder.cs:37
static bool IsAsciiLetterOrDigit(char character)
Definition QEncoder.cs:81