public virtual HtmlVersion FindGivenVersion(Node doctype)
{
int i;
/* if root tag for doctype isn't html give up now */
string str1 = GetString(Lexbuf, doctype.Start, 5);
if (String.CompareOrdinal(str1, "html ") != 0)
{
return 0;
}
if (!CheckDocTypeKeyWords(doctype))
{
Report.Warning(this, doctype, null, Report.DTYPE_NOT_UPPER_CASE);
}
/* give up if all we are given is the system id for the doctype */
str1 = GetString(Lexbuf, doctype.Start + 5, 7);
if (String.CompareOrdinal(str1, "SYSTEM ") == 0)
{
/* but at least ensure the case is correct */
if (!str1.Substring(0, (6) - (0)).Equals("SYSTEM"))
{
Array.Copy(GetBytes("SYSTEM"), 0, Lexbuf, doctype.Start + 5, 6);
}
return 0; /* unrecognized */
}
if (String.CompareOrdinal(str1, "PUBLIC ") == 0)
{
if (!str1.Substring(0, (6) - (0)).Equals("PUBLIC"))
Array.Copy(GetBytes("PUBLIC "), 0, Lexbuf, doctype.Start + 5, 6);
}
else
{
BadDoctype = true;
}
for (i = doctype.Start; i < doctype.End; ++i)
{
if (Lexbuf[i] != (byte) '"') continue;
str1 = GetString(Lexbuf, i + 1, 12);
string str2 = GetString(Lexbuf, i + 1, 13);
string p;
string s;
int j;
int len;
if (str1.Equals("-//W3C//DTD "))
{
/* compute length of identifier e.g. "HTML 4.0 Transitional" */
//TODO:odd!
for (j = i + 13; j < doctype.End && Lexbuf[j] != (byte) '/'; ++j)
{
}
len = j - i - 13;
p = GetString(Lexbuf, i + 13, len);
for (j = 1; j < W3CVersion.Length; ++j)
{
s = W3CVersion[j].Name;
if (len == s.Length && s.Equals(p))
{
return W3CVersion[j].Version;
}
}
/* else unrecognized version */
}
else if (str2.Equals("-//IETF//DTD "))
{
/* compute length of identifier e.g. "HTML 2.0" */
//TODO:odd!
for (j = i + 14; j < doctype.End && Lexbuf[j] != (byte) '/'; ++j)
{
}
len = j - i - 14;
p = GetString(Lexbuf, i + 14, len);
s = W3CVersion[0].Name;
if (len == s.Length && s.Equals(p))
{
return W3CVersion[0].Version;
}
/* else unrecognized version */
}
break;
}
return 0;
}