2 // System.Web.HttpUtility
\r
5 // Patrik Torstensson (Patrik.Torstensson@labs2.com)
\r
6 // Wictor Wilén (decode/encode functions) (wictor@ibizkit.se)
\r
12 namespace System.Web {
\r
13 public sealed class HttpUtility {
\r
15 private const string _hex = "0123456789ABCDEF";
\r
16 private const string _chars = "<>;:.?=&@*+%/\\";
\r
18 public HttpUtility() {
\r
21 public static void HtmlAttributeEncode(string s, TextWriter output) {
\r
22 output.Write(HtmlAttributeEncode(s));
\r
25 public static string HtmlAttributeEncode(string s) {
\r
30 StringBuilder oStr = new StringBuilder(128);
\r
32 for (int i = 0; i != s.Length; i++) {
\r
34 oStr.Append("&");
\r
37 oStr.Append(""");
\r
43 return oStr.ToString();
\r
46 public static string UrlDecode(string str) {
\r
47 return UrlDecode(str, Encoding.UTF8);
\r
50 [MonoTODO("Use Encoding")]
\r
51 public static string UrlDecode(string s, Encoding Enc) {
\r
57 long len = s.Length;
\r
61 for(int i = 0; i < len; i++) {
\r
63 tmp = s[i+1].ToString ();
\r
65 dest += char.Parse(tmp);
\r
67 else if( s[i] == '+') {
\r
79 public static string UrlEncode(string str) {
\r
80 return UrlDecode(str, Encoding.UTF8);
\r
83 [MonoTODO("Use encoding")]
\r
84 public static string UrlEncode(string s, Encoding Enc) {
\r
90 long len = s.Length;
\r
93 for(int i = 0; i < len; i++) {
\r
94 if(s[i] == ' ') // space character is replaced with '+'
\r
96 else if ( _chars.IndexOf(s[i]) >= 0 ) {
\r
97 h1 = (int)s[i] % 16;
\r
98 h2 = (int)s[i] / 16;
\r
100 dest += _hex[h1].ToString();
\r
101 dest += _hex[h2].ToString();
\r
104 dest += s[i].ToString();
\r
111 /// Decodes an HTML-encoded string and returns the decoded string.
\r
113 /// <param name="s">The HTML string to decode. </param>
\r
114 /// <returns>The decoded text.</returns>
\r
116 public static string HtmlDecode(string s) {
\r
117 throw new System.NotImplementedException();
\r
121 /// Decodes an HTML-encoded string and sends the resulting output to a TextWriter output stream.
\r
123 /// <param name="s">The HTML string to decode</param>
\r
124 /// <param name="output">The TextWriter output stream containing the decoded string. </param>
\r
126 public static void HtmlDecode(string s, TextWriter output) {
\r
127 throw new System.NotImplementedException();
\r
131 /// HTML-encodes a string and returns the encoded string.
\r
133 /// <param name="s">The text string to encode. </param>
\r
134 /// <returns>The HTML-encoded text.</returns>
\r
135 public static string HtmlEncode(string s) {
\r
137 long len = s.Length;
\r
142 for(int i = 0; i < len; i++) {
\r
160 dest += v.ToString() ;
\r
172 /// HTML-encodes a string and sends the resulting output to a TextWriter output stream.
\r
174 /// <param name="s">The string to encode. </param>
\r
175 /// <param name="output">The TextWriter output stream containing the encoded string. </param>
\r
176 public static void HtmlEncode( string s, TextWriter output) {
\r
177 output.Write(HtmlEncode(s));
\r