private int DecodedLength(string text)
{
// Workaround required as the parser does not provide offset information.
// Calculate length considering the offset shifts caused by the entities.
System.Text.RegularExpressions.MatchCollection entities = System.Text.RegularExpressions.Regex.Matches(text, "&\\w+?;");
var length = 0;
var lastMatchEnd = 0;
foreach (System.Text.RegularExpressions.Match match in entities)
{
length += match.Index - lastMatchEnd;
lastMatchEnd = match.Index + match.Length;
var resolvedEntity = XmlDecode(match.Value);
length += resolvedEntity.Length;
}
length += text.Length - lastMatchEnd;
return length;
}