nsAutoString currentCharset("unknown"); nsAutoString charsetSourceStr("unknown"); nsAutoString encoding("unknown");
nsAutoString currentCharset;    currentCharset.AssignWithConversion("unknown"); nsAutoString charsetSourceStr;  charsetSourceStr.AssignWithConversion("unknown"); nsAutoString encoding;          encoding.AssignWithConversion("unknown");
NS_IMETHODIMP nsXMLEncodingObserver::Notify(                     PRUint32 aDocumentID,                      PRUint32 numOfAttributes,                      const PRUnichar* nameArray[],                      const PRUnichar* valueArray[]){    nsresult res = NS_OK;    PRUint32 i;    if(numOfAttributes >= 3)    {      PRBool bGotCurrentCharset=PR_FALSE;      PRBool bGotCurrentCharsetSource = PR_FALSE;      PRBool bGotEncoding = PR_FALSE;      nsAutoString currentCharset("unknown");      nsAutoString charsetSourceStr("unknown");      nsAutoString encoding("unknown");      for(i=0; i < numOfAttributes; i++)       {         if(0==nsCRT::strcmp(nameArray[i], "charset"))          {           bGotCurrentCharset = PR_TRUE;           currentCharset = valueArray[i];         } else if(0==nsCRT::strcmp(nameArray[i], "charsetSource")) {           bGotCurrentCharsetSource = PR_TRUE;           charsetSourceStr = valueArray[i];         } else if(0==nsCRT::strcasecmp(nameArray[i], "encoding")) {            bGotEncoding = PR_TRUE;           encoding = valueArray[i];         }      }      // if we cannot find currentCharset or currentCharsetSource      // return error.      if( ! (bGotCurrentCharset && bGotCurrentCharsetSource))      {         return NS_ERROR_ILLEGAL_VALUE;      }      PRInt32 err;      PRInt32 charsetSourceInt = charsetSourceStr.ToInteger(&err);      // if we cannot convert the string into nsCharsetSource, return error      if(NS_FAILED(err))         return NS_ERROR_ILLEGAL_VALUE;      nsCharsetSource currentCharsetSource = (nsCharsetSource)charsetSourceInt;      if(kCharsetFromMetaTag > currentCharsetSource)      {           if(! encoding.Equals(currentCharset))            {               nsICharsetAlias* calias = nsnull;               res = nsServiceManager::GetService(                              kCharsetAliasCID,                              nsICharsetAlias::GetIID(),                              (nsISupports**) &calias);               if(NS_SUCCEEDED(res) && (nsnull != calias) )                {                    PRBool same = PR_FALSE;                    res = calias->Equals( encoding, currentCharset, &same);                    if(NS_SUCCEEDED(res) && (! same))                    {                          nsAutoString preferred;                          res = calias->GetPreferred(encoding, preferred);                          if(NS_SUCCEEDED(res))                          {                              const char* charsetInCStr = preferred.ToNewCString();                              if(nsnull != charsetInCStr) {                                 res = NotifyWebShell(aDocumentID, charsetInCStr, kCharsetFromMetaTag );                                 delete [] (char*)charsetInCStr;                                 return res;                              }                          } // if check for GetPreferred                    } // if check res for Equals                    nsServiceManager::ReleaseService(kCharsetAliasCID, calias);                } // if check res for GetService            } // if Equals       } // if     } // if     return NS_OK;}