private int ParseNamedCharRefInline(int startPos, bool expand, StringBuilder internalSubsetBuilder)
{
Debug.Assert(startPos < _ps.charsUsed);
Debug.Assert(_ps.chars[startPos] == '&');
Debug.Assert(_ps.chars[startPos + 1] != '#');
int pos = startPos + 1;
char[] chars = _ps.chars;
char ch;
switch (chars[pos])
{
// ' or &
case 'a':
pos++;
// &
if (chars[pos] == 'm')
{
if (_ps.charsUsed - pos >= 3)
{
if (chars[pos + 1] == 'p' && chars[pos + 2] == ';')
{
pos += 3;
ch = '&';
goto FoundCharRef;
}
else
{
return -1;
}
}
}
// '
else if (chars[pos] == 'p')
{
if (_ps.charsUsed - pos >= 4)
{
if (chars[pos + 1] == 'o' && chars[pos + 2] == 's' &&
chars[pos + 3] == ';')
{
pos += 4;
ch = '\'';
goto FoundCharRef;
}
else
{
return -1;
}
}
}
else if (pos < _ps.charsUsed)
{
return -1;
}
break;
// &guot;
case 'q':
if (_ps.charsUsed - pos >= 5)
{
if (chars[pos + 1] == 'u' && chars[pos + 2] == 'o' &&
chars[pos + 3] == 't' && chars[pos + 4] == ';')
{
pos += 5;
ch = '"';
goto FoundCharRef;
}
else
{
return -1;
}
}
break;
// <
case 'l':
if (_ps.charsUsed - pos >= 3)
{
if (chars[pos + 1] == 't' && chars[pos + 2] == ';')
{
pos += 3;
ch = '<';
goto FoundCharRef;
}
else
{
return -1;
}
}
break;
// >
case 'g':
if (_ps.charsUsed - pos >= 3)
{
if (chars[pos + 1] == 't' && chars[pos + 2] == ';')
{
pos += 3;
ch = '>';
goto FoundCharRef;
}
else
{
return -1;
}
}
break;
default:
return -1;
}
// need more data in the buffer
return -2;
FoundCharRef:
Debug.Assert(pos > 0);
if (expand)
{
if (internalSubsetBuilder != null)
{
internalSubsetBuilder.Append(_ps.chars, _ps.charPos, pos - _ps.charPos);
}
_ps.chars[pos - 1] = ch;
}
return pos;
}