case 0xEF: if((0xBB==aBytes[1]) && (0xBF==aBytes[2])) {   oCharset.AssignWithConversion(UTF8); oCharsetSource= kCharsetFromByteOrderMark; } break;
static PRBool detectByteOrderMark(const unsigned char* aBytes, PRInt32 aLen, nsString& oCharset, nsCharsetSource& oCharsetSource) { oCharsetSource= kCharsetFromAutoDetection; oCharset.SetLength(0); // see http://www.w3.org/TR/1998/REC-xml-19980210#sec-oCharseting // for details switch(aBytes[0])	 {   case 0x00:     if(0x00==aBytes[1]) {        // 00 00        if((0x00==aBytes[2]) && (0x3C==aBytes[3])) {           // 00 00 00 3C UCS-4, big-endian machine (1234 order)           oCharset.AssignWithConversion(UCS4_BE);        } else if((0x3C==aBytes[2]) && (0x00==aBytes[3])) {           // 00 00 3C 00 UCS-4, unusual octet order (2143)           oCharset.AssignWithConversion(UCS4_2143);        }      } else if(0x3C==aBytes[1]) {        // 00 3C        if((0x00==aBytes[2]) && (0x00==aBytes[3])) {           // 00 3C 00 00 UCS-4, unusual octet order (3412)           oCharset.AssignWithConversion(UCS4_3412);        } else if((0x3C==aBytes[2]) && (0x3F==aBytes[3])) {           // 00 3C 00 3F UTF-16, big-endian, no Byte Order Mark           oCharset.AssignWithConversion(UCS2_BE); // should change to UTF-16BE        }      }   break;   case 0x3C:     if(0x00==aBytes[1]) {        // 3C 00        if((0x00==aBytes[2]) && (0x00==aBytes[3])) {           // 3C 00 00 00 UCS-4, little-endian machine (4321 order)           oCharset.AssignWithConversion(UCS4_LE);        } else if((0x3F==aBytes[2]) && (0x00==aBytes[3])) {           // 3C 00 3F 00 UTF-16, little-endian, no Byte Order Mark           oCharset.AssignWithConversion(UCS2_LE); // should change to UTF-16LE        }      } else if((0x3C==aBytes[0]) && (0x3F==aBytes[1]) &&               (0x78==aBytes[2]) && (0x6D==aBytes[3]) &&               (0 == PL_strncmp("<?xml version", (char*)aBytes, 13 ))) {       // 3C 3F 78 6D       nsAutoString firstXbytes;       firstXbytes.AppendWithConversion((const char*)aBytes, (PRInt32)                       ((aLen > XMLENCODING_PEEKBYTES)?                       XMLENCODING_PEEKBYTES:                       aLen));        PRInt32 xmlDeclEnd = firstXbytes.Find("?>", PR_FALSE, 13);	   // 27 == strlen("<xml? version="1" encoding=");       if((kNotFound != xmlDeclEnd) &&(xmlDeclEnd > 27 )){           firstXbytes.Cut(xmlDeclEnd, firstXbytes.Length()-xmlDeclEnd);           PRInt32 encStart = firstXbytes.Find("encoding", PR_FALSE,13);           if(kNotFound != encStart) {             encStart = firstXbytes.FindCharInSet("\"'", encStart+8);                              // 8 == strlen("encoding")             if(kNotFound != encStart) {                PRUnichar q = firstXbytes.CharAt(encStart);                 PRInt32 encEnd = firstXbytes.FindChar(q, PR_FALSE, encStart+1);                if(kNotFound != encEnd) {                   PRInt32 count = encEnd - encStart -1;                   if(count >0) {                      firstXbytes.Mid(oCharset,(encStart+1), count);                      oCharsetSource= kCharsetFromMetaTag;                   }                }             }           }       }     }   break;   case 0xFE:     if(0xFF==aBytes[1]) {        // FE FF        // UTF-16, big-endian         oCharset.AssignWithConversion(UCS2_BE); // should change to UTF-16BE        oCharsetSource= kCharsetFromByteOrderMark;     }   break;   case 0xFF:     if(0xFE==aBytes[1]) {        // FF FE        // UTF-16, little-endian         oCharset.AssignWithConversion(UCS2_LE); // should change to UTF-16LE        oCharsetSource= kCharsetFromByteOrderMark;     }   break;   // case 0x4C: if((0x6F==aBytes[1]) && ((0xA7==aBytes[2] && (0x94==aBytes[3])) {   //   We do not care EBCIDIC here....   // }   // break; }  // switch return oCharset.Length() > 0;}