private int GetHexCharEntity(int offset, int length)
{
byte[] buffer = _buffer;
DiagnosticUtility.DebugAssert(buffer[offset + 0] == '&', "");
DiagnosticUtility.DebugAssert(buffer[offset + 1] == '#', "");
DiagnosticUtility.DebugAssert(buffer[offset + 2] == 'x', "");
DiagnosticUtility.DebugAssert(buffer[offset + length - 1] == ';', "");
int value = 0;
for (int i = 3; i < length - 1; i++)
{
byte ch = buffer[offset + i];
int digit = 0;
if (ch >= '0' && ch <= '9')
digit = (ch - '0');
else if (ch >= 'a' && ch <= 'f')
digit = 10 + (ch - 'a');
else if (ch >= 'A' && ch <= 'F')
digit = 10 + (ch - 'A');
else
XmlExceptionHelper.ThrowInvalidCharRef(_reader);
DiagnosticUtility.DebugAssert(digit >= 0 && digit < 16, "");
value = value * 16 + digit;
if (value > SurrogateChar.MaxValue)
XmlExceptionHelper.ThrowInvalidCharRef(_reader);
}
return value;
}