aParseMode = eDTDMode_almost_standards;
aParseMode = eDTDMode_quirks; aDocType = eHTML_Quirks;
static void DetermineHTMLParseMode(const nsString& aBuffer,                                   nsDTDMode& aParseMode,                                   eParserDocType& aDocType){#ifdef DEBUG  VerifyPublicIDs();#endif  PRInt32 resultFlags;  nsAutoString publicIDUCS2, sysIDUCS2;  if (ParseDocTypeDecl(aBuffer, &resultFlags, publicIDUCS2, sysIDUCS2)) {    if (!(resultFlags & PARSE_DTD_HAVE_DOCTYPE)) {      // no DOCTYPE      aParseMode = eDTDMode_quirks;      aDocType = eHTML_Quirks;    } else if ((resultFlags & PARSE_DTD_HAVE_INTERNAL_SUBSET) ||               !(resultFlags & PARSE_DTD_HAVE_PUBLIC_ID)) {      // A doctype with an internal subset is always full_standards.      // A doctype without a public ID is always full_standards.      aDocType = eHTML_Strict;      aParseMode = eDTDMode_full_standards;      // Special hack for IBM's custom DOCTYPE.      if (!(resultFlags & PARSE_DTD_HAVE_INTERNAL_SUBSET) &&          sysIDUCS2 == NS_LITERAL_STRING(               "http://www.ibm.com/data/dtd/v11/ibmxhtml1-transitional.dtd")) {        aParseMode = eDTDMode_almost_standards;      }    } else {      // We have to check our list of public IDs to see what to do.      // Yes, we want UCS2 to ASCII lossy conversion.      nsCAutoString publicID;      publicID.AssignWithConversion(publicIDUCS2);      // See comment above definition of kPublicIDs about case      // sensitivity.      ToLowerCase(publicID);      // binary search to see if we can find the correct public ID        // These must be signed since maximum can go below zero and we'll        // crash if it's unsigned.      PRInt32 minimum = 0;      PRInt32 maximum = ELEMENTS_OF(kPublicIDs) - 1;      PRInt32 index;      for (;;) {        index = (minimum + maximum) / 2;        PRInt32 comparison =            nsCRT::strcmp(publicID.get(), kPublicIDs[index].name);        if (comparison == 0)          break;        if (comparison < 0)          maximum = index - 1;        else          minimum = index + 1;        if (maximum < minimum) {          // The DOCTYPE is not in our list, so it must be full_standards.          aParseMode = eDTDMode_full_standards;          aDocType = eHTML_Strict;          return;        }      }      switch ((resultFlags & PARSE_DTD_HAVE_SYSTEM_ID)                ? kPublicIDs[index].mode_if_sysid                : kPublicIDs[index].mode_if_no_sysid)      {        case PubIDInfo::eQuirks3:          aParseMode = eDTDMode_quirks;          aDocType = eHTML3_Quirks;          break;        case PubIDInfo::eQuirks:          aParseMode = eDTDMode_quirks;          aDocType = eHTML_Quirks;          break;        case PubIDInfo::eAlmostStandards:          aParseMode = eDTDMode_almost_standards;          aDocType = eHTML_Strict;          break;        case PubIDInfo::eFullStandards:          aParseMode = eDTDMode_full_standards;          aDocType = eHTML_Strict;          break;        default:          NS_NOTREACHED("no other cases!");      }    }  } else {    // badly formed DOCTYPE -> quirks    aParseMode = eDTDMode_quirks;    aDocType = eHTML3_Quirks;  }}