-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathHttpUtility.cs
More file actions
72 lines (66 loc) · 2.25 KB
/
Copy pathHttpUtility.cs
File metadata and controls
72 lines (66 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
namespace ControlLibrary.Extensions
{
public static class HttpUtility
{
/// <summary>
/// HTML Encodes a string.
/// </summary>
/// <param name="buf"></param>
/// <returns></returns>
/// <remarks></remarks>
public static string HtmlEncode(this string buf)
{
return System.Net.WebUtility.HtmlEncode(buf);
}
/// <summary>
/// HTML Decodes a string.
/// </summary>
/// <param name="buf"></param>
/// <returns></returns>
/// <remarks></remarks>
public static string HtmlDecode(this string buf)
{
return System.Net.WebUtility.HtmlDecode(buf);
}
/// <summary>
/// Encodes text for use in a URL.
/// </summary>
/// <param name="urlText"></param>
/// <returns></returns>
/// <remarks></remarks>
public static string UrlEncode(this string urlText)
{
return System.Net.WebUtility.UrlEncode(urlText);
}
/// <summary>
/// Decodes text for use in a URL.
/// </summary>
/// <param name="urlText"></param>
/// <returns></returns>
/// <remarks></remarks>
public static string UrlDecode(this string urlText)
{
return System.Net.WebUtility.UrlDecode(urlText);
}
public static byte[] UrlEncodeToBytes(this byte[] urlBytes, int offset = 0, int count = int.MaxValue)
{
if (count == int.MaxValue)
return System.Net.WebUtility.UrlEncodeToBytes(urlBytes, offset, urlBytes.Length);
else
return System.Net.WebUtility.UrlEncodeToBytes(urlBytes, offset, count);
}
public static byte[] UrlDecodeToBytes(this byte[] urlBytes, int offset = 0, int count = int.MaxValue)
{
if (count == int.MaxValue)
return System.Net.WebUtility.UrlDecodeToBytes(urlBytes, offset, urlBytes.Length);
else
return System.Net.WebUtility.UrlDecodeToBytes(urlBytes, offset, count);
}
}
}