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
This commit is contained in:
akkana%netscape.com
2000-07-10 19:46:59 +00:00
parent 2d15d02c8f
commit 84c9d71b9a
17 changed files with 98 additions and 75 deletions

View File

@@ -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;
}

View File

@@ -18,7 +18,6 @@
* Rights Reserved.
*
* Contributor(s):
* Pierre Phaneuf <pp@ludusdesign.com>
*/
/**
@@ -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<nsISaveAsCharset> mCharsetEncoder;
nsCOMPtr<nsIEntityConverter> mEntityConverter;
nsCAutoString mCharsetOverride;

View File

@@ -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;

View File

@@ -18,7 +18,6 @@
* Rights Reserved.
*
* Contributor(s):
* Pierre Phaneuf <pp@ludusdesign.com>
*/
/**
@@ -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;
};