XmlExtensions
Useful helpers for the XML parser.
namespace AngleSharp.Extensions
{
internal static class XmlExtensions
{
public static bool IsPubidChar(this char c)
{
if (!c.IsAlphanumericAscii() && c != '-' && c != '\'' && c != '+' && c != ',' && c != '.' && c != '/' && c != ':' && c != '?' && c != '=' && c != '!' && c != '*' && c != '#' && c != '@' && c != '$' && c != '_' && c != '(' && c != ')' && c != ';' && c != '%')
return c.IsSpaceCharacter();
return true;
}
public static bool IsXmlNameStart(this char c)
{
if (!c.IsLetter() && c != ':' && c != '_' && !c.IsInRange(192, 214) && !c.IsInRange(216, 246) && !c.IsInRange(248, 767) && !c.IsInRange(880, 893) && !c.IsInRange(895, 8191) && !c.IsInRange(8204, 8205) && !c.IsInRange(8304, 8591) && !c.IsInRange(11264, 12271) && !c.IsInRange(12289, 55295) && !c.IsInRange(63744, 64975) && !c.IsInRange(65008, 65533))
return c.IsInRange(65536, 983039);
return true;
}
public static bool IsXmlName(this char c)
{
if (!c.IsXmlNameStart() && !c.IsDigit() && c != '-' && c != '.' && c != '·' && !c.IsInRange(768, 879))
return c.IsInRange(8255, 8256);
return true;
}
public static bool IsXmlName(this string str)
{
if (str.Length > 0 && str[0].IsXmlNameStart()) {
for (int i = 1; i < str.Length; i++) {
if (!str[i].IsXmlName())
return false;
}
return true;
}
return false;
}
public static bool IsQualifiedName(this string str)
{
int num = str.IndexOf(':');
if (num == -1)
return str.IsXmlName();
if (num > 0 && str[0].IsXmlNameStart()) {
for (int i = 1; i < num; i++) {
if (!str[i].IsXmlName())
return false;
}
num++;
}
if (str.Length > num && str[num++].IsXmlNameStart()) {
for (int j = num; j < str.Length; j++) {
if (str[j] == ':' || !str[j].IsXmlName())
return false;
}
return true;
}
return false;
}
public static bool IsXmlChar(this char chr)
{
if (chr != '\t' && chr != '\n' && chr != '\r' && (chr < ' ' || chr > '')) {
if (chr >= '')
return chr <= '�';
return false;
}
return true;
}
public static bool IsValidAsCharRef(this int chr)
{
if (chr != 9 && chr != 10 && chr != 13 && (chr < 32 || chr > 55295) && (chr < 57344 || chr > 65533)) {
if (chr >= 65536)
return chr <= 1114111;
return false;
}
return true;
}
}
}