Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
StringHandle.cs
Go to the documentation of this file.
2
3namespace System.Xml;
4
5internal sealed class StringHandle : IEquatable<StringHandle>
6{
7 private enum StringHandleType
8 {
10 UTF8,
13 }
14
16
18
19 private int _key;
20
21 private int _offset;
22
23 private int _length;
24
25 private static readonly string[] s_constStrings = new string[3] { "type", "root", "item" };
26
27 public bool IsEmpty
28 {
29 get
30 {
31 if (_type == StringHandleType.UTF8)
32 {
33 return _length == 0;
34 }
35 return Equals2(string.Empty);
36 }
37 }
38
39 public bool IsXmlns
40 {
41 get
42 {
43 if (_type == StringHandleType.UTF8)
44 {
45 if (_length != 5)
46 {
47 return false;
48 }
50 int offset = _offset;
51 if (buffer[offset] == 120 && buffer[offset + 1] == 109 && buffer[offset + 2] == 108 && buffer[offset + 3] == 110)
52 {
53 return buffer[offset + 4] == 115;
54 }
55 return false;
56 }
57 return Equals2("xmlns");
58 }
59 }
60
66
67 public void SetValue(int offset, int length)
68 {
72 }
73
79
80 public void SetValue(int offset, int length, bool escaped)
81 {
82 _type = ((!escaped) ? StringHandleType.UTF8 : StringHandleType.EscapedUTF8);
85 }
86
87 public void SetValue(int key)
88 {
89 _type = StringHandleType.Dictionary;
90 _key = key;
91 }
92
94 {
95 _type = value._type;
96 _key = value._key;
97 _offset = value._offset;
98 _length = value._length;
99 }
100
102 {
103 prefix.SetValue(_offset, _length);
104 }
105
115
125
126 public byte[] GetString(out int offset, out int length)
127 {
128 switch (_type)
129 {
130 case StringHandleType.UTF8:
131 offset = _offset;
132 length = _length;
133 return _bufferReader.Buffer;
134 case StringHandleType.Dictionary:
135 {
137 offset = 0;
138 length = array3.Length;
139 return array3;
140 }
141 case StringHandleType.ConstString:
142 {
144 offset = 0;
145 length = array2.Length;
146 return array2;
147 }
148 default:
149 {
151 offset = 0;
152 length = array.Length;
153 return array;
154 }
155 }
156 }
157
159 {
160 if (_type == StringHandleType.Dictionary)
161 {
163 return true;
164 }
165 if (IsEmpty)
166 {
168 return true;
169 }
170 value = null;
171 return false;
172 }
173
174 public override string ToString()
175 {
176 return GetString();
177 }
178
188
198
199 private bool Equals2(string s2)
200 {
201 return _type switch
202 {
205 _ => GetString() == s2,
206 };
207 }
208
218
220 {
221 if ((object)other == null)
222 {
223 return false;
224 }
225 return other._type switch
226 {
227 StringHandleType.Dictionary => Equals2(other._key, other._bufferReader),
228 StringHandleType.UTF8 => Equals2(other._offset, other._length, other._bufferReader),
229 _ => Equals2(other.GetString()),
230 };
231 }
232
234 {
235 return s1.Equals2(xmlString2);
236 }
237
239 {
240 return !s1.Equals2(xmlString2);
241 }
242
243 public static bool operator ==(StringHandle s1, string s2)
244 {
245 return s1.Equals2(s2);
246 }
247
248 public static bool operator !=(StringHandle s1, string s2)
249 {
250 return !s1.Equals2(s2);
251 }
252
254 {
255 return s1.Equals(s2);
256 }
257
259 {
260 return !s1.Equals(s2);
261 }
262
264 {
265 if (_type == StringHandleType.UTF8 && that._type == StringHandleType.UTF8)
266 {
267 return _bufferReader.Compare(_offset, _length, that._offset, that._length);
268 }
269 return string.Compare(GetString(), that.GetString(), StringComparison.Ordinal);
270 }
271
272 public override bool Equals([NotNullWhen(true)] object obj)
273 {
274 return Equals(obj as StringHandle);
275 }
276
277 public override int GetHashCode()
278 {
279 return GetString().GetHashCode();
280 }
281}
bool Equals2(string s2)
override int GetHashCode()
void SetValue(StringHandle value)
bool TryGetDictionaryString([NotNullWhen(true)] out XmlDictionaryString value)
int CompareTo(StringHandle that)
bool Equals([NotNullWhen(true)] StringHandle other)
static bool operator!=(StringHandle s1, XmlDictionaryString xmlString2)
void ToPrefixHandle(PrefixHandle prefix)
StringHandle(XmlBufferReader bufferReader)
void SetValue(int offset, int length)
bool Equals2(XmlDictionaryString xmlString2)
void SetValue(int offset, int length, bool escaped)
StringHandleType _type
static readonly string[] s_constStrings
static bool operator==(StringHandle s1, XmlDictionaryString xmlString2)
readonly XmlBufferReader _bufferReader
byte[] GetString(out int offset, out int length)
bool Equals2(int key2, XmlBufferReader bufferReader2)
override string ToString()
void SetConstantValue(StringHandleConstStringType constStringType)
string GetString(XmlNameTable nameTable)
bool Equals2(int offset2, int length2, XmlBufferReader bufferReader2)
override bool Equals([NotNullWhen(true)] object obj)
XmlDictionaryString GetDictionaryString(int key)
bool Equals2(int key1, int key2, XmlBufferReader bufferReader2)
int Compare(int offset1, int length1, int offset2, int length2)
string GetEscapedString(int offset, int length)
string GetString(int offset, int length)
static byte[] ToBytes(string value)
static XmlDictionaryString Empty