Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
HttpUtility.cs
Go to the documentation of this file.
4using System.IO;
5using System.Text;
7
8namespace System.Web;
9
10public sealed class HttpUtility
11{
13 {
16 {
17 }
18
19 public override string ToString()
20 {
21 int count = Count;
22 if (count == 0)
23 {
24 return "";
25 }
26 StringBuilder stringBuilder = new StringBuilder();
27 string[] allKeys = AllKeys;
28 for (int i = 0; i < count; i++)
29 {
30 string text = allKeys[i];
31 string[] values = GetValues(text);
32 if (values == null)
33 {
34 continue;
35 }
36 string[] array = values;
37 foreach (string str in array)
38 {
39 if (!string.IsNullOrEmpty(text))
40 {
41 stringBuilder.Append(text).Append('=');
42 }
43 stringBuilder.Append(UrlEncode(str)).Append('&');
44 }
45 }
46 return stringBuilder.ToString(0, stringBuilder.Length - 1);
47 }
48 }
49
50 public static NameValueCollection ParseQueryString(string query)
51 {
52 return ParseQueryString(query, Encoding.UTF8);
53 }
54
55 public static NameValueCollection ParseQueryString(string query, Encoding encoding)
56 {
57 if (query == null)
58 {
59 throw new ArgumentNullException("query");
60 }
61 if (encoding == null)
62 {
63 throw new ArgumentNullException("encoding");
64 }
65 HttpQSCollection httpQSCollection = new HttpQSCollection();
66 int length = query.Length;
67 int num = ((length > 0 && query[0] == '?') ? 1 : 0);
68 if (length == num)
69 {
70 return httpQSCollection;
71 }
72 while (num <= length)
73 {
74 int num2 = -1;
75 int num3 = -1;
76 for (int i = num; i < length; i++)
77 {
78 if (num2 == -1 && query[i] == '=')
79 {
80 num2 = i + 1;
81 }
82 else if (query[i] == '&')
83 {
84 num3 = i;
85 break;
86 }
87 }
88 string name;
89 if (num2 == -1)
90 {
91 name = null;
92 num2 = num;
93 }
94 else
95 {
96 name = UrlDecode(query.Substring(num, num2 - num - 1), encoding);
97 }
98 if (num3 < 0)
99 {
100 num3 = query.Length;
101 }
102 num = num3 + 1;
103 string value = UrlDecode(query.Substring(num2, num3 - num2), encoding);
104 httpQSCollection.Add(name, value);
105 }
106 return httpQSCollection;
107 }
108
109 [return: NotNullIfNotNull("s")]
110 public static string? HtmlDecode(string? s)
111 {
112 return HttpEncoder.HtmlDecode(s);
113 }
114
115 public static void HtmlDecode(string? s, TextWriter output)
116 {
117 HttpEncoder.HtmlDecode(s, output);
118 }
119
120 [return: NotNullIfNotNull("s")]
121 public static string? HtmlEncode(string? s)
122 {
123 return HttpEncoder.HtmlEncode(s);
124 }
125
126 [return: NotNullIfNotNull("value")]
127 public static string? HtmlEncode(object? value)
128 {
129 if (value != null)
130 {
131 return HtmlEncode(Convert.ToString(value, CultureInfo.CurrentCulture) ?? string.Empty);
132 }
133 return null;
134 }
135
136 public static void HtmlEncode(string? s, TextWriter output)
137 {
138 HttpEncoder.HtmlEncode(s, output);
139 }
140
141 [return: NotNullIfNotNull("s")]
142 public static string? HtmlAttributeEncode(string? s)
143 {
145 }
146
147 public static void HtmlAttributeEncode(string? s, TextWriter output)
148 {
150 }
151
152 [return: NotNullIfNotNull("str")]
153 public static string? UrlEncode(string? str)
154 {
155 return UrlEncode(str, Encoding.UTF8);
156 }
157
158 [return: NotNullIfNotNull("str")]
159 public static string? UrlPathEncode(string? str)
160 {
162 }
163
164 [return: NotNullIfNotNull("str")]
165 public static string? UrlEncode(string? str, Encoding e)
166 {
167 if (str != null)
168 {
169 return Encoding.ASCII.GetString(UrlEncodeToBytes(str, e));
170 }
171 return null;
172 }
173
174 [return: NotNullIfNotNull("bytes")]
175 public static string? UrlEncode(byte[]? bytes)
176 {
177 if (bytes != null)
178 {
179 return Encoding.ASCII.GetString(UrlEncodeToBytes(bytes));
180 }
181 return null;
182 }
183
184 [return: NotNullIfNotNull("bytes")]
185 public static string? UrlEncode(byte[]? bytes, int offset, int count)
186 {
187 if (bytes != null)
188 {
189 return Encoding.ASCII.GetString(UrlEncodeToBytes(bytes, offset, count));
190 }
191 return null;
192 }
193
194 [return: NotNullIfNotNull("str")]
195 public static byte[]? UrlEncodeToBytes(string? str)
196 {
198 }
199
200 [return: NotNullIfNotNull("bytes")]
201 public static byte[]? UrlEncodeToBytes(byte[]? bytes)
202 {
203 if (bytes != null)
204 {
205 return UrlEncodeToBytes(bytes, 0, bytes.Length);
206 }
207 return null;
208 }
209
210 [Obsolete("This method produces non-standards-compliant output and has interoperability issues. The preferred alternative is UrlEncodeToBytes(String).")]
211 [return: NotNullIfNotNull("str")]
212 public static byte[]? UrlEncodeUnicodeToBytes(string? str)
213 {
214 if (str != null)
215 {
216 return Encoding.ASCII.GetBytes(UrlEncodeUnicode(str));
217 }
218 return null;
219 }
220
221 [return: NotNullIfNotNull("str")]
222 public static string? UrlDecode(string? str)
223 {
224 return UrlDecode(str, Encoding.UTF8);
225 }
226
227 [return: NotNullIfNotNull("bytes")]
228 public static string? UrlDecode(byte[]? bytes, Encoding e)
229 {
230 if (bytes != null)
231 {
232 return UrlDecode(bytes, 0, bytes.Length, e);
233 }
234 return null;
235 }
236
237 [return: NotNullIfNotNull("str")]
238 public static byte[]? UrlDecodeToBytes(string? str)
239 {
241 }
242
243 [return: NotNullIfNotNull("str")]
244 public static byte[]? UrlDecodeToBytes(string? str, Encoding e)
245 {
246 if (str != null)
247 {
248 return UrlDecodeToBytes(e.GetBytes(str));
249 }
250 return null;
251 }
252
253 [return: NotNullIfNotNull("bytes")]
254 public static byte[]? UrlDecodeToBytes(byte[]? bytes)
255 {
256 if (bytes != null)
257 {
258 return UrlDecodeToBytes(bytes, 0, bytes.Length);
259 }
260 return null;
261 }
262
263 [return: NotNullIfNotNull("str")]
264 public static byte[]? UrlEncodeToBytes(string? str, Encoding e)
265 {
266 if (str == null)
267 {
268 return null;
269 }
270 byte[] bytes = e.GetBytes(str);
271 return HttpEncoder.UrlEncode(bytes, 0, bytes.Length, alwaysCreateNewReturnValue: false);
272 }
273
274 [return: NotNullIfNotNull("bytes")]
275 public static byte[]? UrlEncodeToBytes(byte[]? bytes, int offset, int count)
276 {
277 return HttpEncoder.UrlEncode(bytes, offset, count, alwaysCreateNewReturnValue: true);
278 }
279
280 [Obsolete("This method produces non-standards-compliant output and has interoperability issues. The preferred alternative is UrlEncode(String).")]
281 [return: NotNullIfNotNull("str")]
282 public static string? UrlEncodeUnicode(string? str)
283 {
285 }
286
287 [return: NotNullIfNotNull("str")]
288 public static string? UrlDecode(string? str, Encoding e)
289 {
290 return HttpEncoder.UrlDecode(str, e);
291 }
292
293 [return: NotNullIfNotNull("bytes")]
294 public static string? UrlDecode(byte[]? bytes, int offset, int count, Encoding e)
295 {
297 }
298
299 [return: NotNullIfNotNull("bytes")]
300 public static byte[]? UrlDecodeToBytes(byte[]? bytes, int offset, int count)
301 {
303 }
304
305 public static string JavaScriptStringEncode(string? value)
306 {
308 }
309
310 public static string JavaScriptStringEncode(string? value, bool addDoubleQuotes)
311 {
313 if (!addDoubleQuotes)
314 {
315 return text;
316 }
317 return "\"" + text + "\"";
318 }
319}
static ? string ToString(object? value)
Definition Convert.cs:2321
static CultureInfo CurrentCulture
static Encoding UTF8
Definition Encoding.cs:526
static Encoding ASCII
Definition Encoding.cs:511
virtual byte[] GetBytes(char[] chars)
Definition Encoding.cs:781
override string ToString()
StringBuilder Append(char value, int repeatCount)
static ? string HtmlEncode(string? s)
static string JavaScriptStringEncode(string? value, bool addDoubleQuotes)
static ? byte[] UrlEncodeToBytes(byte[]? bytes, int offset, int count)
static ? string UrlEncodeUnicode(string? str)
static ? string UrlPathEncode(string? str)
static ? string UrlDecode(string? str)
static ? string UrlDecode(string? str, Encoding e)
static ? string UrlEncode(string? str, Encoding e)
static ? string HtmlEncode(object? value)
static ? string UrlDecode(byte[]? bytes, Encoding e)
static ? string UrlEncode(byte[]? bytes, int offset, int count)
static ? string UrlEncode(string? str)
static ? byte[] UrlEncodeToBytes(byte[]? bytes)
static ? string UrlDecode(byte[]? bytes, int offset, int count, Encoding e)
static ? byte[] UrlEncodeToBytes(string? str, Encoding e)
static ? byte[] UrlDecodeToBytes(string? str, Encoding e)
static ? byte[] UrlDecodeToBytes(byte[]? bytes, int offset, int count)
static NameValueCollection ParseQueryString(string query, Encoding encoding)
static void HtmlDecode(string? s, TextWriter output)
static ? byte[] UrlEncodeUnicodeToBytes(string? str)
static ? byte[] UrlEncodeToBytes(string? str)
static void HtmlEncode(string? s, TextWriter output)
static NameValueCollection ParseQueryString(string query)
static ? string UrlEncode(byte[]? bytes)
static string JavaScriptStringEncode(string? value)
static void HtmlAttributeEncode(string? s, TextWriter output)
static ? byte[] UrlDecodeToBytes(string? str)
static ? string HtmlDecode(string? s)
static ? byte[] UrlDecodeToBytes(byte[]? bytes)
static ? string HtmlAttributeEncode(string? s)
static byte[] UrlEncode(byte[] bytes, int offset, int count, bool alwaysCreateNewReturnValue)
static string HtmlDecode(string value)
static string UrlEncodeUnicode(string value)
static string JavaScriptStringEncode(string value)
static string HtmlEncode(string value)
static string UrlPathEncode(string value)
static string HtmlAttributeEncode(string value)
static byte[] UrlDecode(byte[] bytes, int offset, int count)