pws->mParser->SetDocumentCharset(guess, guessSource); }
nsCOMPtr<nsICharsetAlias> alias(do_GetService(NS_CHARSETALIAS_CONTRACTID)); result = alias->GetPreferred(guess, preferred); if (NS_SUCCEEDED(result)) { guess.Assign(preferred); } pws->mParser->SetDocumentCharset(guess, guessSource); pws->mParser->SetSinkCharset(guess); nsCOMPtr<nsICachingChannel> channel(do_QueryInterface(pws->mRequest)); if (channel) { nsCOMPtr<nsISupports> cacheToken; channel->GetCacheToken(getter_AddRefs(cacheToken)); if (cacheToken) { nsCOMPtr<nsICacheEntryDescriptor> cacheDescriptor(do_QueryInterface(cacheToken)); if (cacheDescriptor) { nsresult rv = cacheDescriptor->SetMetaDataElement("charset", NS_ConvertUCS2toUTF8(guess).get()); NS_ASSERTION(NS_SUCCEEDED(rv),"cannot SetMetaDataElement"); } } } }
ParserWriteFunc(nsIInputStream* in,                void* closure,                const char* fromRawSegment,                PRUint32 toOffset,                PRUint32 count,                PRUint32 *writeCount){  nsresult result;  ParserWriteStruct* pws = NS_STATIC_CAST(ParserWriteStruct*, closure);  const char* buf = fromRawSegment;  PRUint32 theNumRead = count;  if (!pws) {    return NS_ERROR_FAILURE;  }  if(pws->mNeedCheckFirst4Bytes && (count >= 4)) {     nsCharsetSource guessSource;     nsAutoString guess;       pws->mNeedCheckFirst4Bytes = PR_FALSE;     if(detectByteOrderMark((const unsigned char*)buf,                            theNumRead, guess, guessSource))       { #ifdef DEBUG_XMLENCODING         printf("xmlencoding detect- %s\n", guess.ToNewCString()); #endif         pws->mParser->SetDocumentCharset(guess, guessSource);       }   }   if(pws->mParserFilter)     pws->mParserFilter->RawBuffer(buf, &theNumRead);     result = pws->mScanner->Append(buf, theNumRead);  if (NS_SUCCEEDED(result)) {    *writeCount = count;  }  return result;}