public override void WriteEscapedText(byte[] chars, int offset, int count)
{
bool[] isEscapedChar = (_inAttribute ? _isEscapedAttributeChar : _isEscapedElementChar);
int isEscapedCharLength = isEscapedChar.Length;
int i = 0;
for (int j = 0; j < count; j++)
{
byte ch = chars[offset + j];
if (ch < isEscapedCharLength && isEscapedChar[ch])
{
WriteUTF8Chars(chars, offset + i, j - i);
WriteCharEntity(ch);
i = j + 1;
}
else if (ch == 239 && offset + j + 2 < count)
{
// 0xFFFE and 0xFFFF must be written as char entities
// UTF8(239, 191, 190) = (char) 0xFFFE
// UTF8(239, 191, 191) = (char) 0xFFFF
byte ch2 = chars[offset + j + 1];
byte ch3 = chars[offset + j + 2];
if (ch2 == 191 && (ch3 == 190 || ch3 == 191))
{
WriteUTF8Chars(chars, offset + i, j - i);
WriteCharEntity(ch3 == 190 ? (char)0xFFFE : (char)0xFFFF);
i = j + 3;
}
}
}
WriteUTF8Chars(chars, offset + i, count - i);
}