diff --git a/htmlparser/src/nsHTMLToTXTSinkStream.cpp b/htmlparser/src/nsHTMLToTXTSinkStream.cpp index f9920d145b86..163672ede870 100644 --- a/htmlparser/src/nsHTMLToTXTSinkStream.cpp +++ b/htmlparser/src/nsHTMLToTXTSinkStream.cpp @@ -423,6 +423,12 @@ void nsHTMLToTXTSinkStream::UnicodeToTXTString(const nsString& aSrc) } +NS_IMETHODIMP +nsHTMLToTXTSinkStream::GetStringBuffer(nsString & aStrBuffer) +{ + aStrBuffer = mStrBuffer; + return NS_OK; +} @@ -449,6 +455,7 @@ nsHTMLToTXTSinkStream::AddLeaf(const nsIParserNode& aNode, ostream& aStream) UnicodeToTXTString(text); aStream << mBuffer; + mStrBuffer.Append(mBuffer); mColPos += text.Length(); } else if (type == eHTMLTag_whitespace) @@ -458,6 +465,7 @@ nsHTMLToTXTSinkStream::AddLeaf(const nsIParserNode& aNode, ostream& aStream) const nsString& text = aNode.GetText(); UnicodeToTXTString(text); aStream << mBuffer; + mStrBuffer.Append(mBuffer); mColPos += text.Length(); } } @@ -466,6 +474,7 @@ nsHTMLToTXTSinkStream::AddLeaf(const nsIParserNode& aNode, ostream& aStream) if (PR_TRUE) { aStream << endl; + mStrBuffer.Append("\n"); mColPos += 1; } } @@ -543,7 +552,9 @@ nsHTMLToTXTSinkStream::CloseContainer(const nsIParserNode& aNode){ { if (mColPos != 0) { - *mOutput << endl; + if (mOutput) + *mOutput << endl; + mStrBuffer.Append("\n"); mColPos = 0; } } diff --git a/htmlparser/src/nsHTMLToTXTSinkStream.h b/htmlparser/src/nsHTMLToTXTSinkStream.h index 119632e725b2..6058c04c3fa0 100644 --- a/htmlparser/src/nsHTMLToTXTSinkStream.h +++ b/htmlparser/src/nsHTMLToTXTSinkStream.h @@ -68,6 +68,7 @@ class nsHTMLToTXTSinkStream : public nsIHTMLContentSink { virtual ~nsHTMLToTXTSinkStream(); NS_IMETHOD_(void) SetOutputStream(ostream& aStream); + NS_IMETHOD GetStringBuffer(nsString & aStrBuffer); // nsISupports NS_DECL_ISUPPORTS @@ -124,6 +125,8 @@ protected: char* mBuffer; PRInt32 mBufferSize; + nsString mStrBuffer; + }; extern NS_HTMLPARS nsresult diff --git a/parser/htmlparser/src/nsHTMLToTXTSinkStream.cpp b/parser/htmlparser/src/nsHTMLToTXTSinkStream.cpp index f9920d145b86..163672ede870 100644 --- a/parser/htmlparser/src/nsHTMLToTXTSinkStream.cpp +++ b/parser/htmlparser/src/nsHTMLToTXTSinkStream.cpp @@ -423,6 +423,12 @@ void nsHTMLToTXTSinkStream::UnicodeToTXTString(const nsString& aSrc) } +NS_IMETHODIMP +nsHTMLToTXTSinkStream::GetStringBuffer(nsString & aStrBuffer) +{ + aStrBuffer = mStrBuffer; + return NS_OK; +} @@ -449,6 +455,7 @@ nsHTMLToTXTSinkStream::AddLeaf(const nsIParserNode& aNode, ostream& aStream) UnicodeToTXTString(text); aStream << mBuffer; + mStrBuffer.Append(mBuffer); mColPos += text.Length(); } else if (type == eHTMLTag_whitespace) @@ -458,6 +465,7 @@ nsHTMLToTXTSinkStream::AddLeaf(const nsIParserNode& aNode, ostream& aStream) const nsString& text = aNode.GetText(); UnicodeToTXTString(text); aStream << mBuffer; + mStrBuffer.Append(mBuffer); mColPos += text.Length(); } } @@ -466,6 +474,7 @@ nsHTMLToTXTSinkStream::AddLeaf(const nsIParserNode& aNode, ostream& aStream) if (PR_TRUE) { aStream << endl; + mStrBuffer.Append("\n"); mColPos += 1; } } @@ -543,7 +552,9 @@ nsHTMLToTXTSinkStream::CloseContainer(const nsIParserNode& aNode){ { if (mColPos != 0) { - *mOutput << endl; + if (mOutput) + *mOutput << endl; + mStrBuffer.Append("\n"); mColPos = 0; } } diff --git a/parser/htmlparser/src/nsHTMLToTXTSinkStream.h b/parser/htmlparser/src/nsHTMLToTXTSinkStream.h index 119632e725b2..6058c04c3fa0 100644 --- a/parser/htmlparser/src/nsHTMLToTXTSinkStream.h +++ b/parser/htmlparser/src/nsHTMLToTXTSinkStream.h @@ -68,6 +68,7 @@ class nsHTMLToTXTSinkStream : public nsIHTMLContentSink { virtual ~nsHTMLToTXTSinkStream(); NS_IMETHOD_(void) SetOutputStream(ostream& aStream); + NS_IMETHOD GetStringBuffer(nsString & aStrBuffer); // nsISupports NS_DECL_ISUPPORTS @@ -124,6 +125,8 @@ protected: char* mBuffer; PRInt32 mBufferSize; + nsString mStrBuffer; + }; extern NS_HTMLPARS nsresult