Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
PrefixHandle.cs
Go to the documentation of this file.
2
3namespace System.Xml;
4
5internal sealed class PrefixHandle : IEquatable<PrefixHandle>
6{
7 private readonly XmlBufferReader _bufferReader;
8
10
11 private int _offset;
12
13 private int _length;
14
15 private static readonly string[] s_prefixStrings = new string[27]
16 {
17 "", "a", "b", "c", "d", "e", "f", "g", "h", "i",
18 "j", "k", "l", "m", "n", "o", "p", "q", "r", "s",
19 "t", "u", "v", "w", "x", "y", "z"
20 };
21
22 private static readonly byte[] s_prefixBuffer = new byte[26]
23 {
24 97, 98, 99, 100, 101, 102, 103, 104, 105, 106,
25 107, 108, 109, 110, 111, 112, 113, 114, 115, 116,
26 117, 118, 119, 120, 121, 122
27 };
28
29 public bool IsEmpty => _type == PrefixHandleType.Empty;
30
31 public bool IsXmlns
32 {
33 get
34 {
35 if (_type != PrefixHandleType.Buffer)
36 {
37 return false;
38 }
39 if (_length != 5)
40 {
41 return false;
42 }
44 int offset = _offset;
45 if (buffer[offset] == 120 && buffer[offset + 1] == 109 && buffer[offset + 2] == 108 && buffer[offset + 3] == 110)
46 {
47 return buffer[offset + 4] == 115;
48 }
49 return false;
50 }
51 }
52
53 public bool IsXml
54 {
55 get
56 {
57 if (_type != PrefixHandleType.Buffer)
58 {
59 return false;
60 }
61 if (_length != 3)
62 {
63 return false;
64 }
66 int offset = _offset;
67 if (buffer[offset] == 120 && buffer[offset + 1] == 109)
68 {
69 return buffer[offset + 2] == 108;
70 }
71 return false;
72 }
73 }
74
79
81 {
82 _type = type;
83 }
84
86 {
87 _type = prefix._type;
88 _offset = prefix._offset;
89 _length = prefix._length;
90 }
91
92 public void SetValue(int offset, int length)
93 {
94 switch (length)
95 {
96 case 0:
98 return;
99 case 1:
100 {
101 byte @byte = _bufferReader.GetByte(offset);
102 if (@byte >= 97 && @byte <= 122)
103 {
104 SetValue(GetAlphaPrefix(@byte - 97));
105 return;
106 }
107 break;
108 }
109 }
110 _type = PrefixHandleType.Buffer;
111 _offset = offset;
112 _length = length;
113 }
114
116 {
117 type = _type;
118 return type != PrefixHandleType.Buffer;
119 }
120
121 public static string GetString(PrefixHandleType type)
122 {
123 return s_prefixStrings[(int)type];
124 }
125
127 {
128 return (PrefixHandleType)(1 + index);
129 }
130
131 public static byte[] GetString(PrefixHandleType type, out int offset, out int length)
132 {
133 if (type == PrefixHandleType.Empty)
134 {
135 offset = 0;
136 length = 0;
137 }
138 else
139 {
140 length = 1;
141 offset = (int)(type - 1);
142 }
143 return s_prefixBuffer;
144 }
145
147 {
149 if (type != PrefixHandleType.Buffer)
150 {
151 return GetString(type);
152 }
154 }
155
156 public string GetString()
157 {
159 if (type != PrefixHandleType.Buffer)
160 {
161 return GetString(type);
162 }
164 }
165
166 public byte[] GetString(out int offset, out int length)
167 {
169 if (type != PrefixHandleType.Buffer)
170 {
171 return GetString(type, out offset, out length);
172 }
173 offset = _offset;
174 length = _length;
175 return _bufferReader.Buffer;
176 }
177
179 {
180 return GetString().CompareTo(that.GetString());
181 }
182
184 {
185 if ((object)prefix2 == null)
186 {
187 return false;
188 }
191 if (type != type2)
192 {
193 return false;
194 }
195 if (type != PrefixHandleType.Buffer)
196 {
197 return true;
198 }
199 if (_bufferReader == prefix2._bufferReader)
200 {
201 return _bufferReader.Equals2(_offset, _length, prefix2._offset, prefix2._length);
202 }
203 return _bufferReader.Equals2(_offset, _length, prefix2._bufferReader, prefix2._offset, prefix2._length);
204 }
205
206 private bool Equals2(string prefix2)
207 {
209 if (type != PrefixHandleType.Buffer)
210 {
211 return GetString(type) == prefix2;
212 }
214 }
215
217 {
218 return Equals2(prefix2.Value);
219 }
220
221 public static bool operator ==(PrefixHandle prefix1, string prefix2)
222 {
223 return prefix1.Equals2(prefix2);
224 }
225
226 public static bool operator !=(PrefixHandle prefix1, string prefix2)
227 {
228 return !prefix1.Equals2(prefix2);
229 }
230
232 {
233 return prefix1.Equals2(prefix2);
234 }
235
237 {
238 return !prefix1.Equals2(prefix2);
239 }
240
242 {
243 return prefix1.Equals(prefix2);
244 }
245
247 {
248 return !prefix1.Equals(prefix2);
249 }
250
251 public override bool Equals([NotNullWhen(true)] object obj)
252 {
253 return Equals(obj as PrefixHandle);
254 }
255
256 public override string ToString()
257 {
258 return GetString();
259 }
260
261 public override int GetHashCode()
262 {
263 return GetString().GetHashCode();
264 }
265}
byte[] GetString(out int offset, out int length)
static string GetString(PrefixHandleType type)
PrefixHandle(XmlBufferReader bufferReader)
void SetValue(PrefixHandleType type)
static bool operator!=(PrefixHandle prefix1, string prefix2)
override string ToString()
static PrefixHandleType GetAlphaPrefix(int index)
void SetValue(int offset, int length)
int CompareTo(PrefixHandle that)
static byte[] GetString(PrefixHandleType type, out int offset, out int length)
readonly XmlBufferReader _bufferReader
PrefixHandleType _type
bool Equals2(XmlDictionaryString prefix2)
void SetValue(PrefixHandle prefix)
bool Equals2(string prefix2)
string GetString(XmlNameTable nameTable)
static readonly byte[] s_prefixBuffer
bool TryGetShortPrefix(out PrefixHandleType type)
override int GetHashCode()
static readonly string[] s_prefixStrings
override bool Equals([NotNullWhen(true)] object obj)
bool Equals([NotNullWhen(true)] PrefixHandle prefix2)
static bool operator==(PrefixHandle prefix1, string prefix2)
bool Equals2(int key1, int key2, XmlBufferReader bufferReader2)
string GetString(int offset, int length)