internal static string Unescape (string str, bool excludeSpecial)
{
if (str == null)
return String.Empty;
StringBuilder s = new StringBuilder ();
int len = str.Length;
for (int i = 0; i < len; i++) {
char c = str [i];
if (c == '%') {
char surrogate;
char x = HexUnescapeMultiByte (str, ref i, out surrogate);
if (excludeSpecial && x == '#')
s.Append ("%23");
else if (excludeSpecial && x == '%')
s.Append ("%25");
else if (excludeSpecial && x == '?')
s.Append ("%3F");
else {
s.Append (x);
if (surrogate != char.MinValue)
s.Append (surrogate);
}
i--;
} else
s.Append (c);
}
return s.ToString ();
}