aString+=aChar;
nsresult ConsumeComment(PRUnichar aChar, nsScanner& aScanner,nsString& aString) {    nsresult  result=NS_OK;   /*********************************************************    NOTE: This algorithm does a fine job of handling comments          commonly used, but it doesn't really consume them          per spec (But then, neither does IE or Nav).   *********************************************************/  aString="<!";  nsAutoString  theRightChars;  PRInt32       theBestAltPos=kNotFound;  PRUint32      theStartOffset=0;  result=aScanner.GetChar(aChar);  if(NS_OK==result) {    aString+=aChar;    if(kMinus==aChar) {      result=aScanner.GetChar(aChar);      if(NS_OK==result) {        if(kMinus==aChar) {          //in this case, we're reading a long-form comment <-- xxx -->          aString+=aChar;                    PRInt32 findpos=kNotFound;          while((kNotFound==findpos) && (NS_OK==result)) {            result=aScanner.ReadUntil(aString,kGreaterThan,PR_TRUE);                      if(NS_OK==result){              aChar=aString.CharAt(aString.Length()-3);              if(kMinus==aChar) {                aChar=aString.CharAt(aString.Length()-2);                if(kMinus==aChar) return result; // We have found the dflt end comment delimiter ("-->")              }              if(kNotFound==theBestAltPos) {                // If we did not find the dflt then assume that '>' is the end comment                // until we find '-->'. Nav. Compatibility -- Ref: Bug# 24006                theBestAltPos=aString.Length();                theStartOffset=aScanner.GetOffset();              }            }          } //while          if((kNotFound==findpos) && (!aScanner.IsIncremental())) {            //if you're here, then we're in a special state.             //The problem at hand is that we've hit the end of the document without finding the normal endcomment delimiter "-->".            //In this case, the first thing we try is to see if we found one of the alternate endcomment delimiter ">".            //If so, rewind just pass than, and use everything up to that point as your comment.            //If not, the document has no end comment and should be treated as one big comment.            if(kNotFound<theBestAltPos) {              aString.Truncate(theBestAltPos);              aScanner.Mark(theStartOffset);              result=NS_OK;            }          }          return result;        } //if      }//if    }//if  }//if  if(NS_OK==result) {     //Read up to the closing '>', unless you already did!  (such as <!>).    if(kGreaterThan!=aChar) {      result=aScanner.ReadUntil(aString,kGreaterThan,PR_TRUE);    }  }  return result;}