nsString str; PRBool setCharset = PR_FALSE;  if (aHTTPHeader.Length() > 0) {  PRInt32 charsetOffset; static const char charsetStr[] = "charset="; if ((charsetOffset = aHTTPHeader.Find(charsetStr,PR_TRUE)) > 0) { aHTTPHeader.Right(str, aHTTPHeader.Length() - (charsetOffset + sizeof(charsetStr)-1)); setCharset = PR_TRUE; } } else if (aStyleSheetData.Length() > 0) { static const char atCharsetStr[] = "@charset"; if (aStyleSheetData.Find(atCharsetStr) > -1) { nsString strValue;  aStyleSheetData.Right(str, aStyleSheetData.Length() - (sizeof(atCharsetStr)-1));  str.StripWhitespace();  PRInt32 pos = str.Find(";"); if (pos > -1) { str.Left(strValue,pos);
if (aCharsetSrc.Length() == 0) { mCharset.AssignWithConversion("ISO-8859-1"); } else { nsCOMPtr<nsICharsetAlias> calias(do_GetService(kCharsetAliasCID, &rv)); NS_ASSERTION(calias, "cannot find charset alias"); nsAutoString charsetName(aCharsetSrc); if( NS_SUCCEEDED(rv) && (nsnull != calias)) { PRBool same = PR_FALSE; rv = calias->Equals(aCharsetSrc, mCharset, &same); if(NS_SUCCEEDED(rv) && same) { return NS_OK;
nsresult CSSLoaderImpl::SetCharset(/*in*/ const nsString &aHTTPHeader,                                    /*in*/ const nsString &aStyleSheetData)  // sets the charset based upon the data passed in  //  - if HTTPHeader is not empty and it has a charset, use that  //  - otherwise, if the StyleSheetData is not empty and it has '@charset' as the first substring,  //    then use that  //  - othersise set the default charset{  nsresult rv = NS_OK;  nsString str;  PRBool setCharset = PR_FALSE;  if (aHTTPHeader.Length() > 0) {    // check if it has the charset= parameter    PRInt32 charsetOffset;    static const char charsetStr[] = "charset=";    if ((charsetOffset = aHTTPHeader.Find(charsetStr,PR_TRUE)) > 0) {      aHTTPHeader.Right(str, aHTTPHeader.Length() -                             (charsetOffset + sizeof(charsetStr)-1));      setCharset = PR_TRUE;    }  } else if (aStyleSheetData.Length() > 0) {    static const char atCharsetStr[] = "@charset";    if (aStyleSheetData.Find(atCharsetStr) > -1) {      nsString strValue;      // skip past the ident      aStyleSheetData.Right(str, aStyleSheetData.Length() -                                 (sizeof(atCharsetStr)-1));      // strip any whitespace      str.StripWhitespace();      // truncate everything past the delimiter (semicolon)      PRInt32 pos = str.Find(";");      if (pos > -1) {        str.Left(strValue,pos);      }      // strip any quotes      strValue.Trim("\"\'");      // that's the charset!      str = strValue;      setCharset = PR_TRUE;    }  }  if (PR_TRUE == setCharset) {    rv = SetCharset(str);  }  return rv;}