public static string UrlDecode(string str, Encoding e) { if (str != null) { return(UrlUtility.UrlDecodeStringFromStringInternal(str, e)); } else { return(null); } }
internal void FillFromString(string s, bool urlencoded, Encoding encoding) { int l = (s != null) ? s.Length : 0; int i = 0; while (i < l) { // find next & while noting first = on the way (and if there are more) int si = i; int ti = -1; while (i < l) { char ch = s[i]; if (ch == '=') { if (ti < 0) { ti = i; } } else if (ch == '&') { break; } i++; } // extract the name / value pair string name = null; string value = null; if (ti >= 0) { name = s.Substring(si, ti - si); value = s.Substring(ti + 1, i - ti - 1); } else { value = s.Substring(si, i - si); } // add name / value pair to the collection if (urlencoded) { base.Add( UrlUtility.UrlDecodeStringFromStringInternal(name, encoding), UrlUtility.UrlDecodeStringFromStringInternal(value, encoding)); } else { base.Add(name, value); } // trailing '&' if (i == l - 1 && s[i] == '&') { base.Add(null, string.Empty); } i++; } }