static string UnescapeUserName (string escaped)
{
StringBuilder userName;
int startIndex, index;
if ((index = escaped.IndexOf ('%')) == -1)
return escaped;
userName = new StringBuilder ();
startIndex = 0;
do {
userName.Append (escaped, startIndex, index - startIndex);
userName.Append (HexUnescape (escaped, ref index));
startIndex = index;
if (startIndex >= escaped.Length)
break;
index = escaped.IndexOf ('%', startIndex);
} while (index != -1);
if (index == -1)
userName.Append (escaped, startIndex, escaped.Length - startIndex);
return userName.ToString ();
}