From 84c9d71b9a9a65e73b269480de2d825f35050b7f Mon Sep 17 00:00:00 2001 From: "akkana%netscape.com" Date: Mon, 10 Jul 2000 19:46:59 +0000 Subject: [PATCH] 38232 (nsbeta2+): Make line break character configurable in the output system, and use \n (the DOM linebreak character) when getting output from text controls. Also fix some warnings. r=kin. git-svn-id: svn://10.0.0.236/trunk@73925 18797224-902f-48f8-a5cc-f745e15eee43 --- .../content/base/public/nsIDocumentEncoder.h | 8 ++++- .../src/nsHTMLContentSinkStream.cpp | 36 +++++++++++-------- .../htmlparser/src/nsHTMLContentSinkStream.h | 5 ++- .../htmlparser/src/nsHTMLToTXTSinkStream.cpp | 21 ++++++----- .../htmlparser/src/nsHTMLToTXTSinkStream.h | 3 +- .../layout/base/public/nsIDocumentEncoder.h | 8 ++++- mozilla/layout/forms/nsITextControlFrame.h | 2 +- mozilla/layout/generic/nsFrame.cpp | 2 +- mozilla/layout/html/base/src/nsFrame.cpp | 2 +- .../forms/public/nsIGfxTextControlFrame.h | 2 +- .../html/forms/public/nsITextControlFrame.h | 2 +- .../html/forms/src/nsGfxTextControlFrame2.cpp | 15 ++------ .../html/forms/src/nsGfxTextControlFrame2.h | 2 +- .../src/nsHTMLContentSinkStream.cpp | 36 +++++++++++-------- .../htmlparser/src/nsHTMLContentSinkStream.h | 5 ++- .../htmlparser/src/nsHTMLToTXTSinkStream.cpp | 21 ++++++----- .../htmlparser/src/nsHTMLToTXTSinkStream.h | 3 +- 17 files changed, 98 insertions(+), 75 deletions(-) diff --git a/mozilla/content/base/public/nsIDocumentEncoder.h b/mozilla/content/base/public/nsIDocumentEncoder.h index ba2666a2df4..d505c9001fa 100644 --- a/mozilla/content/base/public/nsIDocumentEncoder.h +++ b/mozilla/content/base/public/nsIDocumentEncoder.h @@ -98,7 +98,13 @@ public: // Encode entities when outputting to a string. // E.g. If set, we'll output   if clear, we'll output 0xa0. - OutputEncodeEntities = 256 + OutputEncodeEntities = 256, + + // LineBreak processing: we can do either platform line breaks, + // CR, LF, or CRLF. If neither of these flags is set, then we + // will use platform line breaks. + OutputCRLineBreak = 512, + OutputLFLineBreak = 1024 }; static const nsIID& GetIID() { static nsIID iid = NS_IDOCUMENT_ENCODER_IID; return iid; } diff --git a/mozilla/htmlparser/src/nsHTMLContentSinkStream.cpp b/mozilla/htmlparser/src/nsHTMLContentSinkStream.cpp index 15b63854fa0..7708677c828 100644 --- a/mozilla/htmlparser/src/nsHTMLContentSinkStream.cpp +++ b/mozilla/htmlparser/src/nsHTMLContentSinkStream.cpp @@ -64,7 +64,6 @@ static PRInt32 BreakBeforeClose(eHTMLTags aTag); static PRInt32 BreakAfterClose(eHTMLTags aTag); static PRBool IndentChildren(eHTMLTags aTag); - /** * This method gets called as part of our COM-like interfaces. * Its purpose is to create an interface to parser object @@ -144,6 +143,17 @@ nsHTMLContentSinkStream::Initialize(nsIOutputStream* aOutStream, mMaxColumn = 72; mFlags = aFlags; + // Set the line break character: + if ((mFlags & nsIDocumentEncoder::OutputCRLineBreak) + && (mFlags & nsIDocumentEncoder::OutputLFLineBreak)) // Windows/mail + mLineBreak.AssignWithConversion("\r\n"); + else if (mFlags & nsIDocumentEncoder::OutputCRLineBreak) // Mac + mLineBreak.AssignWithConversion("\r"); + else if (mFlags & nsIDocumentEncoder::OutputLFLineBreak) // Unix/DOM + mLineBreak.AssignWithConversion("\n"); + else + mLineBreak.AssignWithConversion(NS_LINEBREAK); // Platform/default + mStream = aOutStream; mString = aOutString; if (aCharsetOverride != nsnull) @@ -638,7 +648,7 @@ void nsHTMLContentSinkStream::AddStartTag(const nsIParserNode& aNode) // If this turns out to be a problem, we could do this only if gMozDirty. else if (tag == eHTMLTag_br && mPreLevel > 0) { - Write(NS_LINEBREAK); + Write(mLineBreak); return; } @@ -660,7 +670,7 @@ void nsHTMLContentSinkStream::AddStartTag(const nsIParserNode& aNode) if ((mDoFormat || isDirty) && mPreLevel == 0 && mColPos != 0 && BreakBeforeOpen(tag)) { - Write(NS_LINEBREAK); + Write(mLineBreak); mColPos = 0; } if ((mDoFormat || isDirty) && mPreLevel == 0 && mColPos == 0) @@ -677,7 +687,7 @@ void nsHTMLContentSinkStream::AddStartTag(const nsIParserNode& aNode) if ((mDoFormat || isDirty) && mPreLevel == 0 && tag == eHTMLTag_style) { Write(kGreaterThan); - Write(NS_LINEBREAK); + Write(mLineBreak); const nsString& data = aNode.GetSkippedContent(); PRInt32 size = data.Length(); char* buffer = new char[size+1]; @@ -699,7 +709,7 @@ void nsHTMLContentSinkStream::AddStartTag(const nsIParserNode& aNode) if (((mDoFormat || isDirty) && mPreLevel == 0 && BreakAfterOpen(tag))) { - Write(NS_LINEBREAK); + Write(mLineBreak); mColPos = 0; } @@ -711,9 +721,9 @@ void nsHTMLContentSinkStream::AddStartTag(const nsIParserNode& aNode) if(mDoHeader) { Write(gHeaderComment); - Write(NS_LINEBREAK); + Write(mLineBreak); Write(gDocTypeHeader); - Write(NS_LINEBREAK); + Write(mLineBreak); } } } @@ -752,7 +762,7 @@ void nsHTMLContentSinkStream::AddEndTag(const nsIParserNode& aNode) if (!(mFlags & nsIDocumentEncoder::OutputSelectionOnly)) { Write(kGreaterThan); - Write(NS_LINEBREAK); + Write(mLineBreak); } if ( mHTMLTagStack[mHTMLStackPos-1] == eHTMLTag_markupDecl) { @@ -781,7 +791,7 @@ void nsHTMLContentSinkStream::AddEndTag(const nsIParserNode& aNode) { if (mColPos != 0) { - Write(NS_LINEBREAK); + Write(mLineBreak); mColPos = 0; } } @@ -809,7 +819,7 @@ void nsHTMLContentSinkStream::AddEndTag(const nsIParserNode& aNode) if (((mDoFormat || isDirty) && mPreLevel == 0 && BreakAfterClose(tag)) || tag == eHTMLTag_body || tag == eHTMLTag_html) { - Write(NS_LINEBREAK); + Write(mLineBreak); mColPos = 0; } mHTMLTagStack[--mHTMLStackPos] = eHTMLTag_unknown; @@ -898,7 +908,7 @@ nsHTMLContentSinkStream::AddLeaf(const nsIParserNode& aNode) { if (!mDoFormat || mPreLevel > 0) { - Write(NS_LINEBREAK); + Write(mLineBreak); mColPos = 0; } } @@ -970,7 +980,7 @@ void nsHTMLContentSinkStream::WriteWrapped(const nsString& text) first.Truncate(indx); Write(first); - Write(NS_LINEBREAK); + Write(mLineBreak); mColPos = 0; // cut the string from the beginning to the index @@ -1344,5 +1354,3 @@ static PRBool IndentChildren(eHTMLTags aTag) return result; } - - diff --git a/mozilla/htmlparser/src/nsHTMLContentSinkStream.h b/mozilla/htmlparser/src/nsHTMLContentSinkStream.h index cec9fdb8c05..a6fd3d91d57 100644 --- a/mozilla/htmlparser/src/nsHTMLContentSinkStream.h +++ b/mozilla/htmlparser/src/nsHTMLContentSinkStream.h @@ -18,7 +18,6 @@ * Rights Reserved. * * Contributor(s): - * Pierre Phaneuf */ /** @@ -142,10 +141,8 @@ class nsHTMLContentSinkStream : public nsIHTMLContentSinkStream NS_IMETHOD BeginContext(PRInt32 aPosition); NS_IMETHOD EndContext(PRInt32 aPosition); - public: void SetLowerCaseTags(PRBool aDoLowerCase) { mLowerCaseTags = aDoLowerCase; } - protected: @@ -196,6 +193,8 @@ protected: PRInt32 mMaxColumn; + nsString mLineBreak; + nsCOMPtr mCharsetEncoder; nsCOMPtr mEntityConverter; nsCAutoString mCharsetOverride; diff --git a/mozilla/htmlparser/src/nsHTMLToTXTSinkStream.cpp b/mozilla/htmlparser/src/nsHTMLToTXTSinkStream.cpp index bb3e0e4e4a5..17d1187af0b 100644 --- a/mozilla/htmlparser/src/nsHTMLToTXTSinkStream.cpp +++ b/mozilla/htmlparser/src/nsHTMLToTXTSinkStream.cpp @@ -262,15 +262,20 @@ nsHTMLToTXTSinkStream::Initialize(nsIOutputStream* aOutStream, mCacheLine = PR_TRUE; } + // Set the line break character: + if ((mFlags & nsIDocumentEncoder::OutputCRLineBreak) + && (mFlags & nsIDocumentEncoder::OutputLFLineBreak)) // Windows/mail + mLineBreak.AssignWithConversion("\r\n"); + else if (mFlags & nsIDocumentEncoder::OutputCRLineBreak) // Mac + mLineBreak.AssignWithConversion("\r"); + else if (mFlags & nsIDocumentEncoder::OutputLFLineBreak) // Unix/DOM + mLineBreak.AssignWithConversion("\n"); + else + mLineBreak.AssignWithConversion(NS_LINEBREAK); // Platform/default + return result; } -/** - * - * @update gpk04/30/99 - * @param - * @return - */ NS_IMETHODIMP nsHTMLToTXTSinkStream::SetCharsetOverride(const nsString* aCharset) { @@ -1179,7 +1184,7 @@ nsHTMLToTXTSinkStream::EndLine(PRBool softlinebreak) // Add the soft part of the soft linebreak (RFC 2646 4.1) mCurrentLine.AppendWithConversion(' '); } - mCurrentLine.AppendWithConversion(NS_LINEBREAK); + mCurrentLine.Append(mLineBreak); WriteSimple(mCurrentLine); mCurrentLine.Truncate(); mCurrentLineWidth = 0; @@ -1207,7 +1212,7 @@ nsHTMLToTXTSinkStream::EndLine(PRBool softlinebreak) (sig_delimiter != mCurrentLine)) mCurrentLine.SetLength(--currentlinelength); - mCurrentLine.AppendWithConversion(NS_LINEBREAK); + mCurrentLine.Append(mLineBreak); WriteSimple(mCurrentLine); mCurrentLine.Truncate(); mCurrentLineWidth = 0; diff --git a/mozilla/htmlparser/src/nsHTMLToTXTSinkStream.h b/mozilla/htmlparser/src/nsHTMLToTXTSinkStream.h index 3feb13da726..c544b0e5a93 100644 --- a/mozilla/htmlparser/src/nsHTMLToTXTSinkStream.h +++ b/mozilla/htmlparser/src/nsHTMLToTXTSinkStream.h @@ -18,7 +18,6 @@ * Rights Reserved. * * Contributor(s): - * Pierre Phaneuf */ /** @@ -91,7 +90,6 @@ class nsHTMLToTXTSinkStream : public nsIHTMLToTXTSinkStream NS_IMETHOD SetCharsetOverride(const nsString* aCharset); - // nsISupports NS_DECL_ISUPPORTS @@ -206,6 +204,7 @@ protected: nsIUnicodeEncoder* mUnicodeEncoder; nsString mCharsetOverride; + nsString mLineBreak; nsILineBreaker* mLineBreaker; }; diff --git a/mozilla/layout/base/public/nsIDocumentEncoder.h b/mozilla/layout/base/public/nsIDocumentEncoder.h index ba2666a2df4..d505c9001fa 100644 --- a/mozilla/layout/base/public/nsIDocumentEncoder.h +++ b/mozilla/layout/base/public/nsIDocumentEncoder.h @@ -98,7 +98,13 @@ public: // Encode entities when outputting to a string. // E.g. If set, we'll output   if clear, we'll output 0xa0. - OutputEncodeEntities = 256 + OutputEncodeEntities = 256, + + // LineBreak processing: we can do either platform line breaks, + // CR, LF, or CRLF. If neither of these flags is set, then we + // will use platform line breaks. + OutputCRLineBreak = 512, + OutputLFLineBreak = 1024 }; static const nsIID& GetIID() { static nsIID iid = NS_IDOCUMENT_ENCODER_IID; return iid; } diff --git a/mozilla/layout/forms/nsITextControlFrame.h b/mozilla/layout/forms/nsITextControlFrame.h index 2075c125ad6..8e8506f0734 100644 --- a/mozilla/layout/forms/nsITextControlFrame.h +++ b/mozilla/layout/forms/nsITextControlFrame.h @@ -71,5 +71,5 @@ public: NS_IMETHOD SetSelectionRange(PRInt32 aSelectionStart, PRInt32 aSelectionEnd) = 0; NS_IMETHOD GetSelectionRange(PRInt32* aSelectionStart, PRInt32* aSelectionEnd) = 0; - NS_IMETHOD GetSelectionController(nsISelectionController **aSelCon) = 0; + NS_IMETHOD GetSelectionContr(nsISelectionController **aSelCon) = 0; }; diff --git a/mozilla/layout/generic/nsFrame.cpp b/mozilla/layout/generic/nsFrame.cpp index e29bda05e0d..0f43ce5d468 100644 --- a/mozilla/layout/generic/nsFrame.cpp +++ b/mozilla/layout/generic/nsFrame.cpp @@ -2181,7 +2181,7 @@ nsFrame::GetSelectionController(nsIPresContext *aPresContext, nsISelectionContro nsIGfxTextControlFrame2 *tcf; if (NS_SUCCEEDED(tmp->QueryInterface(nsIGfxTextControlFrame2::GetIID(),(void**)&tcf))) { - return tcf->GetSelectionController(aSelCon); + return tcf->GetSelectionContr(aSelCon); } if (NS_FAILED(tmp->GetParent(&tmp))) break; diff --git a/mozilla/layout/html/base/src/nsFrame.cpp b/mozilla/layout/html/base/src/nsFrame.cpp index e29bda05e0d..0f43ce5d468 100644 --- a/mozilla/layout/html/base/src/nsFrame.cpp +++ b/mozilla/layout/html/base/src/nsFrame.cpp @@ -2181,7 +2181,7 @@ nsFrame::GetSelectionController(nsIPresContext *aPresContext, nsISelectionContro nsIGfxTextControlFrame2 *tcf; if (NS_SUCCEEDED(tmp->QueryInterface(nsIGfxTextControlFrame2::GetIID(),(void**)&tcf))) { - return tcf->GetSelectionController(aSelCon); + return tcf->GetSelectionContr(aSelCon); } if (NS_FAILED(tmp->GetParent(&tmp))) break; diff --git a/mozilla/layout/html/forms/public/nsIGfxTextControlFrame.h b/mozilla/layout/html/forms/public/nsIGfxTextControlFrame.h index 2075c125ad6..8e8506f0734 100644 --- a/mozilla/layout/html/forms/public/nsIGfxTextControlFrame.h +++ b/mozilla/layout/html/forms/public/nsIGfxTextControlFrame.h @@ -71,5 +71,5 @@ public: NS_IMETHOD SetSelectionRange(PRInt32 aSelectionStart, PRInt32 aSelectionEnd) = 0; NS_IMETHOD GetSelectionRange(PRInt32* aSelectionStart, PRInt32* aSelectionEnd) = 0; - NS_IMETHOD GetSelectionController(nsISelectionController **aSelCon) = 0; + NS_IMETHOD GetSelectionContr(nsISelectionController **aSelCon) = 0; }; diff --git a/mozilla/layout/html/forms/public/nsITextControlFrame.h b/mozilla/layout/html/forms/public/nsITextControlFrame.h index 2075c125ad6..8e8506f0734 100644 --- a/mozilla/layout/html/forms/public/nsITextControlFrame.h +++ b/mozilla/layout/html/forms/public/nsITextControlFrame.h @@ -71,5 +71,5 @@ public: NS_IMETHOD SetSelectionRange(PRInt32 aSelectionStart, PRInt32 aSelectionEnd) = 0; NS_IMETHOD GetSelectionRange(PRInt32* aSelectionStart, PRInt32* aSelectionEnd) = 0; - NS_IMETHOD GetSelectionController(nsISelectionController **aSelCon) = 0; + NS_IMETHOD GetSelectionContr(nsISelectionController **aSelCon) = 0; }; diff --git a/mozilla/layout/html/forms/src/nsGfxTextControlFrame2.cpp b/mozilla/layout/html/forms/src/nsGfxTextControlFrame2.cpp index dbc99a3dde0..f05e2cc6f54 100644 --- a/mozilla/layout/html/forms/src/nsGfxTextControlFrame2.cpp +++ b/mozilla/layout/html/forms/src/nsGfxTextControlFrame2.cpp @@ -100,15 +100,6 @@ static NS_DEFINE_CID(kHTMLEditorCID, NS_HTMLEDITOR_CID); static NS_DEFINE_CID(kFrameSelectionCID, NS_FRAMESELECTION_CID); -static void RemoveNewlines(nsString &aString); - -static void RemoveNewlines(nsString &aString) -{ - // strip CR/LF and null - static const char badChars[] = {10, 13, 0}; - aString.StripChars(badChars); -} - //listen for the return key. kinda lame. //listen for onchange notifications @@ -1703,8 +1694,6 @@ nsGfxTextControlFrame2::GetPrefSize(nsBoxLayoutState& aState, nsSize& aSize) aPresContext->GetCompatibilityMode(&mode); PRBool navQuirksMode = eCompatibility_NavQuirks == mode && nameSpaceID == kNameSpaceID_HTML; - nsSize desiredSize; - nsReflowStatus aStatus; nsMargin border; border.SizeTo(0, 0, 0, 0); @@ -2238,7 +2227,7 @@ nsGfxTextControlFrame2::GetSelectionRange(PRInt32* aSelectionStart, PRInt32* aSe NS_IMETHODIMP -nsGfxTextControlFrame2::GetSelectionController(nsISelectionController **aSelCon) +nsGfxTextControlFrame2::GetSelectionContr(nsISelectionController **aSelCon) { NS_ENSURE_ARG_POINTER(aSelCon); NS_IF_ADDREF(*aSelCon = mSelCon); @@ -2553,7 +2542,7 @@ void nsGfxTextControlFrame2::GetTextControlFrameState(nsString& aValue) if (mEditor) { nsString format; format.AssignWithConversion("text/plain"); - PRUint32 flags = 0; + PRUint32 flags = nsIDocumentEncoder::OutputLFLineBreak;; if (PR_TRUE==IsPlainTextControl()) { flags |= nsIDocumentEncoder::OutputBodyOnly; // OutputNoDoctype if head info needed diff --git a/mozilla/layout/html/forms/src/nsGfxTextControlFrame2.h b/mozilla/layout/html/forms/src/nsGfxTextControlFrame2.h index 54cf736c48e..7a52b849a74 100644 --- a/mozilla/layout/html/forms/src/nsGfxTextControlFrame2.h +++ b/mozilla/layout/html/forms/src/nsGfxTextControlFrame2.h @@ -122,7 +122,7 @@ public: NS_IMETHOD SetSelectionEnd(PRInt32 aSelectionEnd); NS_IMETHOD SetSelectionRange(PRInt32 aSelectionStart, PRInt32 aSelectionEnd); NS_IMETHOD GetSelectionRange(PRInt32* aSelectionStart, PRInt32* aSelectionEnd); - NS_IMETHOD GetSelectionController(nsISelectionController **aSelCon); + NS_IMETHOD GetSelectionContr(nsISelectionController **aSelCon); //==== END NSIGFXTEXTCONTROLFRAME2 //==== OVERLOAD of nsIFrame diff --git a/mozilla/parser/htmlparser/src/nsHTMLContentSinkStream.cpp b/mozilla/parser/htmlparser/src/nsHTMLContentSinkStream.cpp index 15b63854fa0..7708677c828 100644 --- a/mozilla/parser/htmlparser/src/nsHTMLContentSinkStream.cpp +++ b/mozilla/parser/htmlparser/src/nsHTMLContentSinkStream.cpp @@ -64,7 +64,6 @@ static PRInt32 BreakBeforeClose(eHTMLTags aTag); static PRInt32 BreakAfterClose(eHTMLTags aTag); static PRBool IndentChildren(eHTMLTags aTag); - /** * This method gets called as part of our COM-like interfaces. * Its purpose is to create an interface to parser object @@ -144,6 +143,17 @@ nsHTMLContentSinkStream::Initialize(nsIOutputStream* aOutStream, mMaxColumn = 72; mFlags = aFlags; + // Set the line break character: + if ((mFlags & nsIDocumentEncoder::OutputCRLineBreak) + && (mFlags & nsIDocumentEncoder::OutputLFLineBreak)) // Windows/mail + mLineBreak.AssignWithConversion("\r\n"); + else if (mFlags & nsIDocumentEncoder::OutputCRLineBreak) // Mac + mLineBreak.AssignWithConversion("\r"); + else if (mFlags & nsIDocumentEncoder::OutputLFLineBreak) // Unix/DOM + mLineBreak.AssignWithConversion("\n"); + else + mLineBreak.AssignWithConversion(NS_LINEBREAK); // Platform/default + mStream = aOutStream; mString = aOutString; if (aCharsetOverride != nsnull) @@ -638,7 +648,7 @@ void nsHTMLContentSinkStream::AddStartTag(const nsIParserNode& aNode) // If this turns out to be a problem, we could do this only if gMozDirty. else if (tag == eHTMLTag_br && mPreLevel > 0) { - Write(NS_LINEBREAK); + Write(mLineBreak); return; } @@ -660,7 +670,7 @@ void nsHTMLContentSinkStream::AddStartTag(const nsIParserNode& aNode) if ((mDoFormat || isDirty) && mPreLevel == 0 && mColPos != 0 && BreakBeforeOpen(tag)) { - Write(NS_LINEBREAK); + Write(mLineBreak); mColPos = 0; } if ((mDoFormat || isDirty) && mPreLevel == 0 && mColPos == 0) @@ -677,7 +687,7 @@ void nsHTMLContentSinkStream::AddStartTag(const nsIParserNode& aNode) if ((mDoFormat || isDirty) && mPreLevel == 0 && tag == eHTMLTag_style) { Write(kGreaterThan); - Write(NS_LINEBREAK); + Write(mLineBreak); const nsString& data = aNode.GetSkippedContent(); PRInt32 size = data.Length(); char* buffer = new char[size+1]; @@ -699,7 +709,7 @@ void nsHTMLContentSinkStream::AddStartTag(const nsIParserNode& aNode) if (((mDoFormat || isDirty) && mPreLevel == 0 && BreakAfterOpen(tag))) { - Write(NS_LINEBREAK); + Write(mLineBreak); mColPos = 0; } @@ -711,9 +721,9 @@ void nsHTMLContentSinkStream::AddStartTag(const nsIParserNode& aNode) if(mDoHeader) { Write(gHeaderComment); - Write(NS_LINEBREAK); + Write(mLineBreak); Write(gDocTypeHeader); - Write(NS_LINEBREAK); + Write(mLineBreak); } } } @@ -752,7 +762,7 @@ void nsHTMLContentSinkStream::AddEndTag(const nsIParserNode& aNode) if (!(mFlags & nsIDocumentEncoder::OutputSelectionOnly)) { Write(kGreaterThan); - Write(NS_LINEBREAK); + Write(mLineBreak); } if ( mHTMLTagStack[mHTMLStackPos-1] == eHTMLTag_markupDecl) { @@ -781,7 +791,7 @@ void nsHTMLContentSinkStream::AddEndTag(const nsIParserNode& aNode) { if (mColPos != 0) { - Write(NS_LINEBREAK); + Write(mLineBreak); mColPos = 0; } } @@ -809,7 +819,7 @@ void nsHTMLContentSinkStream::AddEndTag(const nsIParserNode& aNode) if (((mDoFormat || isDirty) && mPreLevel == 0 && BreakAfterClose(tag)) || tag == eHTMLTag_body || tag == eHTMLTag_html) { - Write(NS_LINEBREAK); + Write(mLineBreak); mColPos = 0; } mHTMLTagStack[--mHTMLStackPos] = eHTMLTag_unknown; @@ -898,7 +908,7 @@ nsHTMLContentSinkStream::AddLeaf(const nsIParserNode& aNode) { if (!mDoFormat || mPreLevel > 0) { - Write(NS_LINEBREAK); + Write(mLineBreak); mColPos = 0; } } @@ -970,7 +980,7 @@ void nsHTMLContentSinkStream::WriteWrapped(const nsString& text) first.Truncate(indx); Write(first); - Write(NS_LINEBREAK); + Write(mLineBreak); mColPos = 0; // cut the string from the beginning to the index @@ -1344,5 +1354,3 @@ static PRBool IndentChildren(eHTMLTags aTag) return result; } - - diff --git a/mozilla/parser/htmlparser/src/nsHTMLContentSinkStream.h b/mozilla/parser/htmlparser/src/nsHTMLContentSinkStream.h index cec9fdb8c05..a6fd3d91d57 100644 --- a/mozilla/parser/htmlparser/src/nsHTMLContentSinkStream.h +++ b/mozilla/parser/htmlparser/src/nsHTMLContentSinkStream.h @@ -18,7 +18,6 @@ * Rights Reserved. * * Contributor(s): - * Pierre Phaneuf */ /** @@ -142,10 +141,8 @@ class nsHTMLContentSinkStream : public nsIHTMLContentSinkStream NS_IMETHOD BeginContext(PRInt32 aPosition); NS_IMETHOD EndContext(PRInt32 aPosition); - public: void SetLowerCaseTags(PRBool aDoLowerCase) { mLowerCaseTags = aDoLowerCase; } - protected: @@ -196,6 +193,8 @@ protected: PRInt32 mMaxColumn; + nsString mLineBreak; + nsCOMPtr mCharsetEncoder; nsCOMPtr mEntityConverter; nsCAutoString mCharsetOverride; diff --git a/mozilla/parser/htmlparser/src/nsHTMLToTXTSinkStream.cpp b/mozilla/parser/htmlparser/src/nsHTMLToTXTSinkStream.cpp index bb3e0e4e4a5..17d1187af0b 100644 --- a/mozilla/parser/htmlparser/src/nsHTMLToTXTSinkStream.cpp +++ b/mozilla/parser/htmlparser/src/nsHTMLToTXTSinkStream.cpp @@ -262,15 +262,20 @@ nsHTMLToTXTSinkStream::Initialize(nsIOutputStream* aOutStream, mCacheLine = PR_TRUE; } + // Set the line break character: + if ((mFlags & nsIDocumentEncoder::OutputCRLineBreak) + && (mFlags & nsIDocumentEncoder::OutputLFLineBreak)) // Windows/mail + mLineBreak.AssignWithConversion("\r\n"); + else if (mFlags & nsIDocumentEncoder::OutputCRLineBreak) // Mac + mLineBreak.AssignWithConversion("\r"); + else if (mFlags & nsIDocumentEncoder::OutputLFLineBreak) // Unix/DOM + mLineBreak.AssignWithConversion("\n"); + else + mLineBreak.AssignWithConversion(NS_LINEBREAK); // Platform/default + return result; } -/** - * - * @update gpk04/30/99 - * @param - * @return - */ NS_IMETHODIMP nsHTMLToTXTSinkStream::SetCharsetOverride(const nsString* aCharset) { @@ -1179,7 +1184,7 @@ nsHTMLToTXTSinkStream::EndLine(PRBool softlinebreak) // Add the soft part of the soft linebreak (RFC 2646 4.1) mCurrentLine.AppendWithConversion(' '); } - mCurrentLine.AppendWithConversion(NS_LINEBREAK); + mCurrentLine.Append(mLineBreak); WriteSimple(mCurrentLine); mCurrentLine.Truncate(); mCurrentLineWidth = 0; @@ -1207,7 +1212,7 @@ nsHTMLToTXTSinkStream::EndLine(PRBool softlinebreak) (sig_delimiter != mCurrentLine)) mCurrentLine.SetLength(--currentlinelength); - mCurrentLine.AppendWithConversion(NS_LINEBREAK); + mCurrentLine.Append(mLineBreak); WriteSimple(mCurrentLine); mCurrentLine.Truncate(); mCurrentLineWidth = 0; diff --git a/mozilla/parser/htmlparser/src/nsHTMLToTXTSinkStream.h b/mozilla/parser/htmlparser/src/nsHTMLToTXTSinkStream.h index 3feb13da726..c544b0e5a93 100644 --- a/mozilla/parser/htmlparser/src/nsHTMLToTXTSinkStream.h +++ b/mozilla/parser/htmlparser/src/nsHTMLToTXTSinkStream.h @@ -18,7 +18,6 @@ * Rights Reserved. * * Contributor(s): - * Pierre Phaneuf */ /** @@ -91,7 +90,6 @@ class nsHTMLToTXTSinkStream : public nsIHTMLToTXTSinkStream NS_IMETHOD SetCharsetOverride(const nsString* aCharset); - // nsISupports NS_DECL_ISUPPORTS @@ -206,6 +204,7 @@ protected: nsIUnicodeEncoder* mUnicodeEncoder; nsString mCharsetOverride; + nsString mLineBreak; nsILineBreaker* mLineBreaker; };