static int FromHex(char c)
{
if (c < '0')
{
throw new InvalidOperationException(
"Invalid percent-encoded string: bad character '" + c + "' in "
+ "escape sequence.");
}
if (c <= '9')
{
return (c - '0');
}
if (c < 'A')
{
throw new InvalidOperationException(
"Invalid percent-encoded string: bad character '" + c + "' in "
+ "escape sequence.");
}
if (c <= 'F')
{
return (c - 'A') + 10;
}
if (c < 'a')
{
throw new InvalidOperationException(
"Invalid percent-encoded string: bad character '" + c + "' in "
+ "escape sequence.");
}
if (c <= 'f')
{
return (c - 'a') + 10;
}
throw new InvalidOperationException(
"Invalid percent-encoded string: bad character '" + c + "' in "
+ "escape sequence.");
}
}