nsString strStyleDataUndecoded; strStyleDataUndecoded.AssignWithConversion(aStyleSheetData, aDataLength); PRInt32 charsetOffset; if (!strStyleDataUndecoded.IsEmpty()) { nsString str; static const char atCharsetStr[] = "@charset"; if ((charsetOffset = strStyleDataUndecoded.Find(atCharsetStr)) > -1) { nsString strValue;  strStyleDataUndecoded.Right(str, strStyleDataUndecoded.Length() - (sizeof(atCharsetStr)-1));  str.StripWhitespace();  PRInt32 pos = str.Find(";"); if (pos > -1) { str.Left(strValue,pos);
if (! aCharsetSrc.IsEmpty()) { nsCOMPtr<nsICharsetAlias> calias(do_GetService(kCharsetAliasCID, &rv)); NS_ASSERTION(calias, "cannot find charset alias"); if (calias) { PRBool same = PR_FALSE; rv = calias->Equals(aCharsetSrc, mCharset, &same); if(NS_SUCCEEDED(rv) && same) { return NS_OK;
nsresult CSSLoaderImpl::SetCharset(/*in*/ const char* aStyleSheetData,                                   /*in*/ PRUint32 aDataLength)    // sets the charset based upon the data passed in    // - if the StyleSheetData is not empty and it has '@charset'    //   as the first substring, then use that    // - otherwise return an error{  nsresult rv = NS_ERROR_NOT_AVAILABLE;  nsString strStyleDataUndecoded;  strStyleDataUndecoded.AssignWithConversion(aStyleSheetData, aDataLength);  PRInt32 charsetOffset;  if (!strStyleDataUndecoded.IsEmpty()) {    nsString str;    static const char atCharsetStr[] = "@charset";    if ((charsetOffset = strStyleDataUndecoded.Find(atCharsetStr)) > -1) {      nsString strValue;      // skip past the ident      strStyleDataUndecoded.Right(str, strStyleDataUndecoded.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!      if (!strValue.IsEmpty()) {        rv = SetCharset(strValue);      }    }  }  return rv;}