2 // System.Web.HttpUtility
5 // Patrik Torstensson (Patrik.Torstensson@labs2.com)
6 // Wictor Wilén (decode/encode functions) (wictor@ibizkit.se)
7 // Tim Coleman (tim@timcoleman.com)
8 // Gonzalo Paniagua Javier (gonzalo@ximian.com)
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System.Collections;
33 using System.Globalization;
36 // using System.Web.Util;
38 namespace HtmlHelp.ChmDecoding
40 public sealed class HttpUtility {
44 const string _hex = "0123456789ABCDEF";
45 const string _chars = "<>;:.?=&@*+%/\\";
46 static Hashtable entities;
47 static object lock_ = new object ();
51 static Hashtable Entities {
64 static void InitEntities ()
66 // Build the hash table of HTML entity references. This list comes
67 // from the HTML 4.01 W3C recommendation.
68 entities = new Hashtable ();
69 entities.Add ("nbsp", '\u00A0');
70 entities.Add ("iexcl", '\u00A1');
71 entities.Add ("cent", '\u00A2');
72 entities.Add ("pound", '\u00A3');
73 entities.Add ("curren", '\u00A4');
74 entities.Add ("yen", '\u00A5');
75 entities.Add ("brvbar", '\u00A6');
76 entities.Add ("sect", '\u00A7');
77 entities.Add ("uml", '\u00A8');
78 entities.Add ("copy", '\u00A9');
79 entities.Add ("ordf", '\u00AA');
80 entities.Add ("laquo", '\u00AB');
81 entities.Add ("not", '\u00AC');
82 entities.Add ("shy", '\u00AD');
83 entities.Add ("reg", '\u00AE');
84 entities.Add ("macr", '\u00AF');
85 entities.Add ("deg", '\u00B0');
86 entities.Add ("plusmn", '\u00B1');
87 entities.Add ("sup2", '\u00B2');
88 entities.Add ("sup3", '\u00B3');
89 entities.Add ("acute", '\u00B4');
90 entities.Add ("micro", '\u00B5');
91 entities.Add ("para", '\u00B6');
92 entities.Add ("middot", '\u00B7');
93 entities.Add ("cedil", '\u00B8');
94 entities.Add ("sup1", '\u00B9');
95 entities.Add ("ordm", '\u00BA');
96 entities.Add ("raquo", '\u00BB');
97 entities.Add ("frac14", '\u00BC');
98 entities.Add ("frac12", '\u00BD');
99 entities.Add ("frac34", '\u00BE');
100 entities.Add ("iquest", '\u00BF');
101 entities.Add ("Agrave", '\u00C0');
102 entities.Add ("Aacute", '\u00C1');
103 entities.Add ("Acirc", '\u00C2');
104 entities.Add ("Atilde", '\u00C3');
105 entities.Add ("Auml", '\u00C4');
106 entities.Add ("Aring", '\u00C5');
107 entities.Add ("AElig", '\u00C6');
108 entities.Add ("Ccedil", '\u00C7');
109 entities.Add ("Egrave", '\u00C8');
110 entities.Add ("Eacute", '\u00C9');
111 entities.Add ("Ecirc", '\u00CA');
112 entities.Add ("Euml", '\u00CB');
113 entities.Add ("Igrave", '\u00CC');
114 entities.Add ("Iacute", '\u00CD');
115 entities.Add ("Icirc", '\u00CE');
116 entities.Add ("Iuml", '\u00CF');
117 entities.Add ("ETH", '\u00D0');
118 entities.Add ("Ntilde", '\u00D1');
119 entities.Add ("Ograve", '\u00D2');
120 entities.Add ("Oacute", '\u00D3');
121 entities.Add ("Ocirc", '\u00D4');
122 entities.Add ("Otilde", '\u00D5');
123 entities.Add ("Ouml", '\u00D6');
124 entities.Add ("times", '\u00D7');
125 entities.Add ("Oslash", '\u00D8');
126 entities.Add ("Ugrave", '\u00D9');
127 entities.Add ("Uacute", '\u00DA');
128 entities.Add ("Ucirc", '\u00DB');
129 entities.Add ("Uuml", '\u00DC');
130 entities.Add ("Yacute", '\u00DD');
131 entities.Add ("THORN", '\u00DE');
132 entities.Add ("szlig", '\u00DF');
133 entities.Add ("agrave", '\u00E0');
134 entities.Add ("aacute", '\u00E1');
135 entities.Add ("acirc", '\u00E2');
136 entities.Add ("atilde", '\u00E3');
137 entities.Add ("auml", '\u00E4');
138 entities.Add ("aring", '\u00E5');
139 entities.Add ("aelig", '\u00E6');
140 entities.Add ("ccedil", '\u00E7');
141 entities.Add ("egrave", '\u00E8');
142 entities.Add ("eacute", '\u00E9');
143 entities.Add ("ecirc", '\u00EA');
144 entities.Add ("euml", '\u00EB');
145 entities.Add ("igrave", '\u00EC');
146 entities.Add ("iacute", '\u00ED');
147 entities.Add ("icirc", '\u00EE');
148 entities.Add ("iuml", '\u00EF');
149 entities.Add ("eth", '\u00F0');
150 entities.Add ("ntilde", '\u00F1');
151 entities.Add ("ograve", '\u00F2');
152 entities.Add ("oacute", '\u00F3');
153 entities.Add ("ocirc", '\u00F4');
154 entities.Add ("otilde", '\u00F5');
155 entities.Add ("ouml", '\u00F6');
156 entities.Add ("divide", '\u00F7');
157 entities.Add ("oslash", '\u00F8');
158 entities.Add ("ugrave", '\u00F9');
159 entities.Add ("uacute", '\u00FA');
160 entities.Add ("ucirc", '\u00FB');
161 entities.Add ("uuml", '\u00FC');
162 entities.Add ("yacute", '\u00FD');
163 entities.Add ("thorn", '\u00FE');
164 entities.Add ("yuml", '\u00FF');
165 entities.Add ("fnof", '\u0192');
166 entities.Add ("Alpha", '\u0391');
167 entities.Add ("Beta", '\u0392');
168 entities.Add ("Gamma", '\u0393');
169 entities.Add ("Delta", '\u0394');
170 entities.Add ("Epsilon", '\u0395');
171 entities.Add ("Zeta", '\u0396');
172 entities.Add ("Eta", '\u0397');
173 entities.Add ("Theta", '\u0398');
174 entities.Add ("Iota", '\u0399');
175 entities.Add ("Kappa", '\u039A');
176 entities.Add ("Lambda", '\u039B');
177 entities.Add ("Mu", '\u039C');
178 entities.Add ("Nu", '\u039D');
179 entities.Add ("Xi", '\u039E');
180 entities.Add ("Omicron", '\u039F');
181 entities.Add ("Pi", '\u03A0');
182 entities.Add ("Rho", '\u03A1');
183 entities.Add ("Sigma", '\u03A3');
184 entities.Add ("Tau", '\u03A4');
185 entities.Add ("Upsilon", '\u03A5');
186 entities.Add ("Phi", '\u03A6');
187 entities.Add ("Chi", '\u03A7');
188 entities.Add ("Psi", '\u03A8');
189 entities.Add ("Omega", '\u03A9');
190 entities.Add ("alpha", '\u03B1');
191 entities.Add ("beta", '\u03B2');
192 entities.Add ("gamma", '\u03B3');
193 entities.Add ("delta", '\u03B4');
194 entities.Add ("epsilon", '\u03B5');
195 entities.Add ("zeta", '\u03B6');
196 entities.Add ("eta", '\u03B7');
197 entities.Add ("theta", '\u03B8');
198 entities.Add ("iota", '\u03B9');
199 entities.Add ("kappa", '\u03BA');
200 entities.Add ("lambda", '\u03BB');
201 entities.Add ("mu", '\u03BC');
202 entities.Add ("nu", '\u03BD');
203 entities.Add ("xi", '\u03BE');
204 entities.Add ("omicron", '\u03BF');
205 entities.Add ("pi", '\u03C0');
206 entities.Add ("rho", '\u03C1');
207 entities.Add ("sigmaf", '\u03C2');
208 entities.Add ("sigma", '\u03C3');
209 entities.Add ("tau", '\u03C4');
210 entities.Add ("upsilon", '\u03C5');
211 entities.Add ("phi", '\u03C6');
212 entities.Add ("chi", '\u03C7');
213 entities.Add ("psi", '\u03C8');
214 entities.Add ("omega", '\u03C9');
215 entities.Add ("thetasym", '\u03D1');
216 entities.Add ("upsih", '\u03D2');
217 entities.Add ("piv", '\u03D6');
218 entities.Add ("bull", '\u2022');
219 entities.Add ("hellip", '\u2026');
220 entities.Add ("prime", '\u2032');
221 entities.Add ("Prime", '\u2033');
222 entities.Add ("oline", '\u203E');
223 entities.Add ("frasl", '\u2044');
224 entities.Add ("weierp", '\u2118');
225 entities.Add ("image", '\u2111');
226 entities.Add ("real", '\u211C');
227 entities.Add ("trade", '\u2122');
228 entities.Add ("alefsym", '\u2135');
229 entities.Add ("larr", '\u2190');
230 entities.Add ("uarr", '\u2191');
231 entities.Add ("rarr", '\u2192');
232 entities.Add ("darr", '\u2193');
233 entities.Add ("harr", '\u2194');
234 entities.Add ("crarr", '\u21B5');
235 entities.Add ("lArr", '\u21D0');
236 entities.Add ("uArr", '\u21D1');
237 entities.Add ("rArr", '\u21D2');
238 entities.Add ("dArr", '\u21D3');
239 entities.Add ("hArr", '\u21D4');
240 entities.Add ("forall", '\u2200');
241 entities.Add ("part", '\u2202');
242 entities.Add ("exist", '\u2203');
243 entities.Add ("empty", '\u2205');
244 entities.Add ("nabla", '\u2207');
245 entities.Add ("isin", '\u2208');
246 entities.Add ("notin", '\u2209');
247 entities.Add ("ni", '\u220B');
248 entities.Add ("prod", '\u220F');
249 entities.Add ("sum", '\u2211');
250 entities.Add ("minus", '\u2212');
251 entities.Add ("lowast", '\u2217');
252 entities.Add ("radic", '\u221A');
253 entities.Add ("prop", '\u221D');
254 entities.Add ("infin", '\u221E');
255 entities.Add ("ang", '\u2220');
256 entities.Add ("and", '\u2227');
257 entities.Add ("or", '\u2228');
258 entities.Add ("cap", '\u2229');
259 entities.Add ("cup", '\u222A');
260 entities.Add ("int", '\u222B');
261 entities.Add ("there4", '\u2234');
262 entities.Add ("sim", '\u223C');
263 entities.Add ("cong", '\u2245');
264 entities.Add ("asymp", '\u2248');
265 entities.Add ("ne", '\u2260');
266 entities.Add ("equiv", '\u2261');
267 entities.Add ("le", '\u2264');
268 entities.Add ("ge", '\u2265');
269 entities.Add ("sub", '\u2282');
270 entities.Add ("sup", '\u2283');
271 entities.Add ("nsub", '\u2284');
272 entities.Add ("sube", '\u2286');
273 entities.Add ("supe", '\u2287');
274 entities.Add ("oplus", '\u2295');
275 entities.Add ("otimes", '\u2297');
276 entities.Add ("perp", '\u22A5');
277 entities.Add ("sdot", '\u22C5');
278 entities.Add ("lceil", '\u2308');
279 entities.Add ("rceil", '\u2309');
280 entities.Add ("lfloor", '\u230A');
281 entities.Add ("rfloor", '\u230B');
282 entities.Add ("lang", '\u2329');
283 entities.Add ("rang", '\u232A');
284 entities.Add ("loz", '\u25CA');
285 entities.Add ("spades", '\u2660');
286 entities.Add ("clubs", '\u2663');
287 entities.Add ("hearts", '\u2665');
288 entities.Add ("diams", '\u2666');
289 entities.Add ("quot", '\u0022');
290 entities.Add ("amp", '\u0026');
291 entities.Add ("lt", '\u003C');
292 entities.Add ("gt", '\u003E');
293 entities.Add ("OElig", '\u0152');
294 entities.Add ("oelig", '\u0153');
295 entities.Add ("Scaron", '\u0160');
296 entities.Add ("scaron", '\u0161');
297 entities.Add ("Yuml", '\u0178');
298 entities.Add ("circ", '\u02C6');
299 entities.Add ("tilde", '\u02DC');
300 entities.Add ("ensp", '\u2002');
301 entities.Add ("emsp", '\u2003');
302 entities.Add ("thinsp", '\u2009');
303 entities.Add ("zwnj", '\u200C');
304 entities.Add ("zwj", '\u200D');
305 entities.Add ("lrm", '\u200E');
306 entities.Add ("rlm", '\u200F');
307 entities.Add ("ndash", '\u2013');
308 entities.Add ("mdash", '\u2014');
309 entities.Add ("lsquo", '\u2018');
310 entities.Add ("rsquo", '\u2019');
311 entities.Add ("sbquo", '\u201A');
312 entities.Add ("ldquo", '\u201C');
313 entities.Add ("rdquo", '\u201D');
314 entities.Add ("bdquo", '\u201E');
315 entities.Add ("dagger", '\u2020');
316 entities.Add ("Dagger", '\u2021');
317 entities.Add ("permil", '\u2030');
318 entities.Add ("lsaquo", '\u2039');
319 entities.Add ("rsaquo", '\u203A');
320 entities.Add ("euro", '\u20AC');
323 public HttpUtility ()
327 #endregion // Constructors
331 public static void HtmlAttributeEncode (string s, TextWriter output)
333 output.Write(HtmlAttributeEncode(s));
336 public static string HtmlAttributeEncode (string s)
341 if (s.IndexOf ('&') == -1 && s.IndexOf ('"') == -1)
344 StringBuilder output = new StringBuilder ();
345 foreach (char c in s)
348 output.Append ("&");
351 output.Append (""");
358 return output.ToString();
361 public static string UrlDecode (string str)
363 return UrlDecode(str, Encoding.UTF8);
366 private static char [] GetChars (MemoryStream b, Encoding e)
368 return e.GetChars (b.GetBuffer (), 0, (int) b.Length);
371 public static string UrlDecode (string s, Encoding e)
376 if (s.IndexOf ('%') == -1 && s.IndexOf ('+') == -1)
382 StringBuilder output = new StringBuilder ();
384 NumberStyles hexa = NumberStyles.HexNumber;
385 MemoryStream bytes = new MemoryStream ();
387 for (int i = 0; i < len; i++) {
388 if (s [i] == '%' && i + 2 < len) {
389 if (s [i + 1] == 'u' && i + 5 < len) {
390 if (bytes.Length > 0) {
391 output.Append (GetChars (bytes, e));
394 output.Append ((char) Int32.Parse (s.Substring (i + 2, 4), hexa));
397 bytes.WriteByte ((byte) Int32.Parse (s.Substring (i + 1, 2), hexa));
403 if (bytes.Length > 0) {
404 output.Append (GetChars (bytes, e));
411 output.Append (s [i]);
415 if (bytes.Length > 0) {
416 output.Append (GetChars (bytes, e));
420 return output.ToString ();
423 public static string UrlDecode (byte [] bytes, Encoding e)
428 return UrlDecode (bytes, 0, bytes.Length, e);
431 private static int GetInt (byte b)
433 char c = Char.ToUpper ((char) b);
434 if (c >= '0' && c <= '9')
437 if (c < 'A' || c > 'F')
440 return (c - 'A' + 10);
443 private static char GetChar (byte [] bytes, int offset, int length)
446 int end = length + offset;
447 for (int i = offset; i < end; i++)
448 value = (value << 4) + GetInt (bytes [offset]);
453 public static string UrlDecode (byte [] bytes, int offset, int count, Encoding e)
455 if (bytes == null || count == 0)
459 throw new ArgumentNullException ("bytes");
461 if (offset < 0 || offset > bytes.Length)
462 throw new ArgumentOutOfRangeException ("offset");
464 if (count < 0 || offset + count > bytes.Length)
465 throw new ArgumentOutOfRangeException ("count");
467 StringBuilder output = new StringBuilder ();
468 MemoryStream acc = new MemoryStream ();
470 int end = count + offset;
471 for (int i = offset; i < end; i++) {
472 if (bytes [i] == '%' && i + 2 < count) {
473 if (bytes [i + 1] == (byte) 'u' && i + 5 < end) {
474 if (acc.Length > 0) {
475 output.Append (GetChars (acc, e));
478 output.Append (GetChar (bytes, offset + 2, 4));
481 acc.WriteByte ((byte) GetChar (bytes, offset + 1, 2));
487 if (acc.Length > 0) {
488 output.Append (GetChars (acc, e));
492 if (bytes [i] == '+') {
495 output.Append ((char) bytes [i]);
499 if (acc.Length > 0) {
500 output.Append (GetChars (acc, e));
504 return output.ToString ();
507 public static byte [] UrlDecodeToBytes (byte [] bytes)
512 return UrlDecodeToBytes (bytes, 0, bytes.Length);
515 public static byte [] UrlDecodeToBytes (string str)
517 return UrlDecodeToBytes (str, Encoding.UTF8);
520 public static byte [] UrlDecodeToBytes (string str, Encoding e)
526 throw new ArgumentNullException ("e");
528 return UrlDecodeToBytes (e.GetBytes (str));
531 public static byte [] UrlDecodeToBytes (byte [] bytes, int offset, int count)
536 int len = bytes.Length;
537 if (offset < 0 || offset >= len)
538 throw new ArgumentOutOfRangeException("offset");
540 if (count < 0 || offset > len - count)
541 throw new ArgumentOutOfRangeException("count");
543 MemoryStream result = new MemoryStream ();
544 int end = offset + count;
545 for (int i = offset; i < end; i++){
546 char c = (char) bytes [i];
549 else if (c == '%' && i < end - 2) {
550 c = GetChar (bytes, i, 2);
553 result.WriteByte ((byte) c);
556 return result.ToArray ();
559 public static string UrlEncode(string str)
561 return UrlEncode(str, Encoding.UTF8);
564 public static string UrlEncode (string s, Encoding Enc)
572 byte [] bytes = Enc.GetBytes (s);
573 byte [] b =UrlEncodeToBytes (bytes, 0, bytes.Length);
574 return Encoding.ASCII.GetString (b,0,b.Length);
577 public static string UrlEncode (byte [] bytes)
582 if (bytes.Length == 0)
585 byte []b=UrlEncodeToBytes(bytes, 0, bytes.Length);
586 return Encoding.ASCII.GetString (b,0,b.Length);
589 public static string UrlEncode (byte [] bytes, int offset, int count)
594 if (bytes.Length == 0)
597 byte []b=UrlEncodeToBytes(bytes, offset, count);
598 return Encoding.ASCII.GetString (b,0,b.Length);
601 public static byte [] UrlEncodeToBytes (string str)
603 return UrlEncodeToBytes (str, Encoding.UTF8);
606 public static byte [] UrlEncodeToBytes (string str, Encoding e)
614 byte [] bytes = e.GetBytes (str);
615 return UrlEncodeToBytes (bytes, 0, bytes.Length);
618 public static byte [] UrlEncodeToBytes (byte [] bytes)
623 if (bytes.Length == 0)
626 return UrlEncodeToBytes (bytes, 0, bytes.Length);
629 static char [] hexChars = "0123456789abcdef".ToCharArray ();
631 public static byte [] UrlEncodeToBytes (byte [] bytes, int offset, int count)
636 int len = bytes.Length;
640 if (offset < 0 || offset >= len)
641 throw new ArgumentOutOfRangeException("offset");
643 if (count < 0 || count > len - offset)
644 throw new ArgumentOutOfRangeException("count");
646 MemoryStream result = new MemoryStream ();
647 int end = offset + count;
648 for (int i = offset; i < end; i++) {
649 char c = (char) bytes [i];
650 if ((c == ' ') || (c < '0' && c != '-' && c != '.') ||
651 (c < 'A' && c > '9') ||
652 (c > 'Z' && c < 'a' && c != '_') ||
654 result.WriteByte ((byte) '%');
655 int idx = ((int) c) >> 4;
656 result.WriteByte ((byte) hexChars [idx]);
657 idx = ((int) c) & 0x0F;
658 result.WriteByte ((byte) hexChars [idx]);
660 result.WriteByte ((byte) c);
664 return result.ToArray ();
667 public static string UrlEncodeUnicode (string str)
672 StringBuilder result = new StringBuilder ();
673 int end = str.Length;
674 for (int i = 0; i < end; i++) {
678 result.Append ("%u");
679 idx = ((int) c) >> 24;
680 result.Append (hexChars [idx]);
681 idx = (((int) c) >> 16) & 0x0F;
682 result.Append (hexChars [idx]);
683 idx = (((int) c) >> 8) & 0x0F;
684 result.Append (hexChars [idx]);
685 idx = ((int) c) & 0x0F;
686 result.Append (hexChars [idx]);
690 if ((c == ' ') || (c < '0' && c != '-' && c != '.') ||
691 (c < 'A' && c > '9') ||
692 (c > 'Z' && c < 'a' && c != '_') ||
695 idx = ((int) c) >> 4;
696 result.Append (hexChars [idx]);
697 idx = ((int) c) & 0x0F;
698 result.Append (hexChars [idx]);
705 return result.ToString ();
708 public static byte [] UrlEncodeUnicodeToBytes (string str)
716 return Encoding.ASCII.GetBytes (UrlEncodeUnicode (str));
720 /// Decodes an HTML-encoded string and returns the decoded string.
722 /// <param name="s">The HTML string to decode. </param>
723 /// <returns>The decoded text.</returns>
724 public static string HtmlDecode (string s)
727 throw new ArgumentNullException ("s");
729 if (s.IndexOf ('&') == -1)
732 bool insideEntity = false; // used to indicate that we are in a potential entity
733 string entity = String.Empty;
734 StringBuilder output = new StringBuilder ();
737 for (int i = 0; i < len; i++) {
741 output.Append (entity);
752 int length = entity.Length;
753 if (length >= 2 && entity[1] == '#' && entity[2] != ';')
754 entity = ((char) Int32.Parse (entity.Substring (2, entity.Length - 3))).ToString();
755 else if (length > 1 && Entities.ContainsKey (entity.Substring (1, entity.Length - 2)))
756 entity = Entities [entity.Substring (1, entity.Length - 2)].ToString ();
758 output.Append (entity);
759 entity = String.Empty;
760 insideEntity = false;
770 output.Append (entity);
771 return output.ToString ();
775 /// Decodes an HTML-encoded string and sends the resulting output to a TextWriter output stream.
777 /// <param name="s">The HTML string to decode</param>
778 /// <param name="output">The TextWriter output stream containing the decoded string. </param>
779 public static void HtmlDecode(string s, TextWriter output)
782 output.Write (HtmlDecode (s));
786 /// HTML-encodes a string and returns the encoded string.
788 /// <param name="s">The text string to encode. </param>
789 /// <returns>The HTML-encoded text.</returns>
790 public static string HtmlEncode (string s)
795 StringBuilder output = new StringBuilder ();
797 foreach (char c in s)
800 output.Append ("&");
803 output.Append (">");
806 output.Append ("<");
809 output.Append (""");
813 output.Append ("&#");
814 output.Append (((int) c).ToString ());
821 return output.ToString ();
825 /// HTML-encodes a string and sends the resulting output to a TextWriter output stream.
827 /// <param name="s">The string to encode. </param>
828 /// <param name="output">The TextWriter output stream containing the encoded string. </param>
829 public static void HtmlEncode(string s, TextWriter output)
832 output.Write (HtmlEncode (s));
836 public string UrlPathEncode (string s)
841 int idx = s.IndexOf ("?");
844 s2 = s.Substring (0, idx-1);
845 s2 = UrlEncode (s2) + s.Substring (idx);
853 #endregion // Methods