mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 215068 - "leading spaces are lost (HTML compose, plain-text send)" [p=andrit@ukr.net (Andriy Tkachuk) r+sr=mscott a1.9=schrep]
This commit is contained in:
parent
e74e505f00
commit
ca485a1067
@ -1252,6 +1252,16 @@ nsPlainTextSerializer::Output(nsString& aString)
|
||||
mOutputString->Append(aString);
|
||||
}
|
||||
|
||||
static PRBool
|
||||
IsSpaceStuffable(const PRUnichar *s)
|
||||
{
|
||||
if (s[0] == '>' || s[0] == ' ' || s[0] == kNBSP ||
|
||||
nsCRT::strncmp(s, NS_LITERAL_STRING("From ").get(), 5) == 0)
|
||||
return PR_TRUE;
|
||||
else
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function adds a piece of text to the current stored line. If we are
|
||||
* wrapping text and the stored line will become too long, a suitable
|
||||
@ -1275,13 +1285,7 @@ nsPlainTextSerializer::AddToLine(const PRUnichar * aLineFragment,
|
||||
}
|
||||
|
||||
if(mFlags & nsIDocumentEncoder::OutputFormatFlowed) {
|
||||
if(
|
||||
(
|
||||
'>' == aLineFragment[0] ||
|
||||
' ' == aLineFragment[0] ||
|
||||
kNBSP == aLineFragment[0] || // bug 215068
|
||||
!nsCRT::strncmp(aLineFragment, NS_LITERAL_STRING("From ").get(), 5)
|
||||
)
|
||||
if(IsSpaceStuffable(aLineFragment)
|
||||
&& mCiteQuoteLevel == 0 // We space-stuff quoted lines anyway
|
||||
)
|
||||
{
|
||||
@ -1398,14 +1402,7 @@ nsPlainTextSerializer::AddToLine(const PRUnichar * aLineFragment,
|
||||
mCurrentLine.Truncate();
|
||||
// Space stuff new line?
|
||||
if(mFlags & nsIDocumentEncoder::OutputFormatFlowed) {
|
||||
if(
|
||||
!restOfLine.IsEmpty()
|
||||
&&
|
||||
(
|
||||
restOfLine[0] == '>' ||
|
||||
restOfLine[0] == ' ' ||
|
||||
StringBeginsWith(restOfLine, NS_LITERAL_STRING("From "))
|
||||
)
|
||||
if(!restOfLine.IsEmpty() && IsSpaceStuffable(restOfLine.get())
|
||||
&& mCiteQuoteLevel == 0 // We space-stuff quoted lines anyway
|
||||
)
|
||||
{
|
||||
@ -1581,7 +1578,7 @@ nsPlainTextSerializer::Write(const nsAString& aStr)
|
||||
|
||||
#ifdef DEBUG_wrapping
|
||||
printf("Write(%s): wrap col = %d\n",
|
||||
NS_ConvertUTF16toUTF8(aString).get(), mWrapColumn);
|
||||
NS_ConvertUTF16toUTF8(str).get(), mWrapColumn);
|
||||
#endif
|
||||
|
||||
PRInt32 bol = 0;
|
||||
@ -1595,12 +1592,11 @@ nsPlainTextSerializer::Write(const nsAString& aStr)
|
||||
// For Flowed text change nbsp-ses to spaces at end of lines to allow them
|
||||
// to be cut off along with usual spaces if required. (bug #125928)
|
||||
if (mFlags & nsIDocumentEncoder::OutputFormatFlowed) {
|
||||
PRUnichar nbsp = 160;
|
||||
for (PRInt32 i = totLen-1; i >= 0; i--) {
|
||||
PRUnichar c = str[i];
|
||||
if ('\n' == c || '\r' == c || ' ' == c || '\t' == c)
|
||||
continue;
|
||||
if (nbsp == c)
|
||||
if (kNBSP == c)
|
||||
str.Replace(i, 1, ' ');
|
||||
else
|
||||
break;
|
||||
@ -1629,6 +1625,7 @@ nsPlainTextSerializer::Write(const nsAString& aStr)
|
||||
PRBool outputQuotes = mAtFirstColumn;
|
||||
PRBool atFirstColumn = mAtFirstColumn;
|
||||
PRBool outputLineBreak = PR_FALSE;
|
||||
PRBool spacesOnly = PR_TRUE;
|
||||
|
||||
// Find one of '\n' or '\r' using iterators since nsAString
|
||||
// doesn't have the old FindCharInSet function.
|
||||
@ -1642,14 +1639,17 @@ nsPlainTextSerializer::Write(const nsAString& aStr)
|
||||
newline = new_newline;
|
||||
break;
|
||||
}
|
||||
if(' ' != *iter)
|
||||
spacesOnly = PR_FALSE;
|
||||
++new_newline;
|
||||
++iter;
|
||||
}
|
||||
|
||||
// Done searching
|
||||
nsAutoString stringpart;
|
||||
if(newline == kNotFound) {
|
||||
// No new lines.
|
||||
nsAutoString stringpart(Substring(str, bol, totLen - bol));
|
||||
stringpart.Assign(Substring(str, bol, totLen - bol));
|
||||
if(!stringpart.IsEmpty()) {
|
||||
PRUnichar lastchar = stringpart[stringpart.Length()-1];
|
||||
if((lastchar == '\t') || (lastchar == ' ') ||
|
||||
@ -1660,18 +1660,14 @@ nsPlainTextSerializer::Write(const nsAString& aStr)
|
||||
mInWhitespace = PR_FALSE;
|
||||
}
|
||||
}
|
||||
mCurrentLine.Assign(stringpart);
|
||||
mEmptyLines=-1;
|
||||
atFirstColumn = mAtFirstColumn && (totLen-bol)==0;
|
||||
bol = totLen;
|
||||
}
|
||||
else {
|
||||
// There is a newline
|
||||
nsAutoString stringpart(Substring(str, bol, newline-bol));
|
||||
if (mFlags & nsIDocumentEncoder::OutputFormatFlowed)
|
||||
stringpart.Trim(" ", PR_FALSE, PR_TRUE, PR_TRUE);
|
||||
stringpart.Assign(Substring(str, bol, newline-bol));
|
||||
mInWhitespace = PR_TRUE;
|
||||
mCurrentLine.Assign(stringpart);
|
||||
outputLineBreak = PR_TRUE;
|
||||
mEmptyLines=0;
|
||||
atFirstColumn = PR_TRUE;
|
||||
@ -1684,6 +1680,17 @@ nsPlainTextSerializer::Write(const nsAString& aStr)
|
||||
}
|
||||
}
|
||||
|
||||
mCurrentLine.AssignLiteral("");
|
||||
if (mFlags & nsIDocumentEncoder::OutputFormatFlowed) {
|
||||
if ((outputLineBreak || !spacesOnly) && // bugs 261467,125928
|
||||
!stringpart.EqualsLiteral("-- ") &&
|
||||
!stringpart.EqualsLiteral("- -- "))
|
||||
stringpart.Trim(" ", PR_FALSE, PR_TRUE, PR_TRUE);
|
||||
if (IsSpaceStuffable(stringpart.get()) && stringpart[0] != '>')
|
||||
mCurrentLine.Append(PRUnichar(' '));
|
||||
}
|
||||
mCurrentLine.Append(stringpart);
|
||||
|
||||
if(outputQuotes) {
|
||||
// Note: this call messes with mAtFirstColumn
|
||||
OutputQuotesAndIndent();
|
||||
|
Loading…
Reference in New Issue
Block a user