nsPromiseFlatString flat(aString);
const nsPromiseFlatString& flat = PromiseFlatString(aString);
ConvertAndWrite(nsAReadableString& aString,                nsIOutputStream* aStream,                nsIUnicodeEncoder* aEncoder){  NS_ENSURE_ARG_POINTER(aStream);  NS_ENSURE_ARG_POINTER(aEncoder);  nsresult rv;  PRInt32 charLength, startCharLength;  nsPromiseFlatString flat(aString);  const PRUnichar* unicodeBuf = flat.get();  PRInt32 unicodeLength = aString.Length();  PRInt32 startLength = unicodeLength;  rv = aEncoder->GetMaxLength(unicodeBuf, unicodeLength, &charLength);  startCharLength = charLength;  NS_ENSURE_SUCCESS(rv, rv);  nsCAutoString charXferString;  charXferString.SetCapacity(charLength);  char* charXferBuf = (char*)charXferString.get();  nsresult convert_rv = NS_OK;  do {    unicodeLength = startLength;    charLength = startCharLength;    convert_rv = aEncoder->Convert(unicodeBuf, &unicodeLength, charXferBuf, &charLength);    NS_ENSURE_SUCCESS(convert_rv, convert_rv);        PRUint32 written;    rv = aStream->Write(charXferBuf, charLength, &written);    NS_ENSURE_SUCCESS(rv, rv);    // If the converter couldn't convert a chraacer we replace the    // character with a characre entity.    if (convert_rv == NS_ERROR_UENC_NOMAPPING) {      // Finishes the conversion.       // The converter has the possibility to write some extra data and flush its final state.      char finish_buf[32];      charLength = 32;      rv = aEncoder->Finish(finish_buf, &charLength);      NS_ENSURE_SUCCESS(rv, rv);      rv = aStream->Write(finish_buf, charLength, &written);      NS_ENSURE_SUCCESS(rv, rv);      nsCAutoString entString("&#");      entString.AppendInt(unicodeBuf[unicodeLength - 1]);      entString.Append(';');      rv = aStream->Write(entString.get(), entString.Length(), &written);      NS_ENSURE_SUCCESS(rv, rv);      unicodeBuf += unicodeLength;      startLength -= unicodeLength;    }  } while (convert_rv == NS_ERROR_UENC_NOMAPPING);  return rv;}