76442 sr= scc r= anthonyd. last minute fixes to editor to not do stupid copies and instead to use new case insensitive string compares.

This commit is contained in:
mjudge%netscape.com 2001-04-18 06:17:05 +00:00
Родитель 2e8fbd1253
Коммит d5b4c5e196
10 изменённых файлов: 98 добавлений и 116 удалений

Просмотреть файл

@ -24,6 +24,7 @@
#include "nsAOLCiter.h"
#include "nsWrapUtils.h"
#include "nsReadableUtils.h"
/** Mail citations using the AOL style >> This is a citation <<
*/
@ -86,17 +87,19 @@ NS_IMETHODIMP
nsAOLCiter::StripCites(const nsAReadableString& aInString, nsAWritableString& aOutString)
{
// Remove the beginning cites, if any:
nsAutoString tInputString(aInString);//MJUDGE SCC NEED HELP
nsAutoString tOutputString;
if (tInputString.EqualsWithConversion(">>", PR_FALSE, 2))
nsReadingIterator <PRUnichar> iter,enditer;
aInString.BeginReading(iter);
aInString.EndReading(enditer);
if (!Compare(Substring(aInString,0,2),NS_LITERAL_STRING(">>")))
{
PRInt32 i = 3;
while (nsCRT::IsAsciiSpace(tInputString[i]))
++i;
tOutputString.Append(tInputString.GetUnicode(), i);
iter.advance(2);
while (nsCRT::IsAsciiSpace(*iter))
++iter;
AppendUnicodeTo(iter,enditer,tOutputString);
}
else
tOutputString = tInputString;
CopyUnicodeTo(iter,enditer,tOutputString);
// Remove the end cites, if any:
tOutputString.Trim("<", PR_FALSE, PR_TRUE, PR_FALSE);

Просмотреть файл

@ -1931,10 +1931,9 @@ nsHTMLEditRules::WillMakeList(nsISelection *aSelection,
// deduce what tag to use for list items
nsAutoString itemType;
nsString tString(*aListType);//MJUDGE SCC NEED HELP
if (aItemType)
itemType = *aItemType;
else if (tString.EqualsWithConversion("dl"))
else if (!Compare(*aListType,NS_LITERAL_STRING("dl"),nsCaseInsensitiveStringComparator()))
itemType.AssignWithConversion("dd");
else
itemType.AssignWithConversion("li");
@ -4598,7 +4597,9 @@ nsHTMLEditRules::ApplyBlockStyle(nsISupportsArray *arrayOfNodes, const nsAReadab
// we special case an empty tag name to mean "remove block parents".
// This is used for the "normal" paragraph style in mail-compose
nsString tString(*aBlockTag);////MJUDGE SCC NEED HELP
if (tString.IsEmpty() || tString.EqualsWithConversion("normal")) bNoParent = PR_TRUE;
if (tString.IsEmpty() ||
!Compare(tString,NS_LITERAL_STRING("normal"),nsCaseInsensitiveStringComparator()))
bNoParent = PR_TRUE;
arrayOfNodes->Count(&listCount);
@ -4690,8 +4691,8 @@ nsHTMLEditRules::ApplyBlockStyle(nsISupportsArray *arrayOfNodes, const nsAReadab
else if (IsInlineNode(curNode) && !bNoParent)
{
// if curNode is a non editable, drop it if we are going to <pre>
nsString tString(*aBlockTag); ////MJUDGE SCC NEED HELP
if ((tString.EqualsWithConversion("pre")) && (!mHTMLEditor->IsEditable(curNode)))
if (!Compare(tString,NS_LITERAL_STRING("pre"),nsCaseInsensitiveStringComparator())
&& (!mHTMLEditor->IsEditable(curNode)))
continue; // do nothing to this block
// if no curBlock, make one
@ -5490,14 +5491,15 @@ nsresult
nsHTMLEditRules::ConvertWhitespace(const nsAReadableString & inString, nsAWritableString & outString)
{
PRUint32 j,len = inString.Length();
nsString tString(inString);////MJUDGE SCC NEED HELP
nsReadingIterator <PRUnichar> iter;
inString.BeginReading(iter);
switch (len)
{
case 0:
outString.SetLength(0);
return NS_OK;
case 1:
if (tString.EqualsWithConversion("\n")) // a bit of a hack: don't convert single newlines that
if (*iter == '\n') // a bit of a hack: don't convert single newlines that
outString.Assign(NS_LITERAL_STRING("\n")); // dont have whitespace adjacent. This is to preserve
else // html source formatting to some degree.
outString.Assign(NS_LITERAL_STRING(" "));

Просмотреть файл

@ -2226,8 +2226,8 @@ nsHTMLEditor::RemoveList(const nsAReadableString& aListType)
if (!selection) return NS_ERROR_NULL_POINTER;
nsTextRulesInfo ruleInfo(nsTextEditRules::kRemoveList);
nsString tString(aListType);//MJUDGE SCC NEED HELP
if (tString.EqualsWithConversion("ol")) ruleInfo.bOrdered = PR_TRUE;
if (!Compare(aListType,NS_LITERAL_STRING("ol"),nsCaseInsensitiveStringComparator()))
ruleInfo.bOrdered = PR_TRUE;
else ruleInfo.bOrdered = PR_FALSE;
res = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
if (cancel || (NS_FAILED(res))) return res;
@ -2349,8 +2349,7 @@ nsHTMLEditor::Indent(const nsAReadableString& aIndent)
PRBool cancel, handled;
PRInt32 theAction = nsTextEditRules::kIndent;
PRInt32 opID = kOpIndent;
nsString tString(aIndent);//MJUDGE SCC NEED HELP
if (tString.EqualsWithConversion("outdent"))
if (!Compare(aIndent,NS_LITERAL_STRING("outdent"),nsCaseInsensitiveStringComparator()))
{
theAction = nsTextEditRules::kOutdent;
opID = kOpOutdent;
@ -3536,26 +3535,20 @@ PRBool
nsHTMLEditor::TagCanContainTag(const nsAReadableString& aParentTag, const nsAReadableString& aChildTag)
{
// COtherDTD gives some unwanted results. We override them here.
nsAutoString olStr, ulStr, liStr;
olStr = NS_LITERAL_STRING("ol");
ulStr = NS_LITERAL_STRING("ul");
liStr = NS_LITERAL_STRING("li");
nsString tParent(aParentTag);//MJUDGE SCC NEED HELP
nsString tChild(aChildTag);//MJUDGE SCC NEED HELP
if ( tParent.EqualsIgnoreCase(olStr) ||
tParent.EqualsIgnoreCase(ulStr) )
if (!Compare(aParentTag,NS_LITERAL_STRING("ol"),nsCaseInsensitiveStringComparator()) ||
!Compare(aParentTag,NS_LITERAL_STRING("ul"),nsCaseInsensitiveStringComparator()))
{
// if parent is a list and tag is also a list, say "yes".
// This is because the editor does sublists illegally for now.
if (tChild.EqualsIgnoreCase(olStr) ||
tChild.EqualsIgnoreCase(ulStr) )
if (!Compare(aChildTag,NS_LITERAL_STRING("ol"),nsCaseInsensitiveStringComparator()) ||
!Compare(aChildTag,NS_LITERAL_STRING("ul"),nsCaseInsensitiveStringComparator()))
return PR_TRUE;
}
if ( tParent.EqualsIgnoreCase(liStr) )
if (!Compare(aParentTag,NS_LITERAL_STRING("li"),nsCaseInsensitiveStringComparator()))
{
// list items cant contain list items
if (tChild.EqualsIgnoreCase(liStr) )
if (!Compare(aChildTag,NS_LITERAL_STRING("li"),nsCaseInsensitiveStringComparator()))
return PR_FALSE;
}

Просмотреть файл

@ -582,7 +582,6 @@ PRBool nsHTMLEditor::IsOnlyAttribute(nsIDOMNode *aNode,
nsCOMPtr<nsIAtom> attrName, prefix;
content->GetAttributeCount(attrCount);
nsString tString(*aAttribute);//MJUDGE SCC NEED HELP
for (i=0; i<attrCount; i++)
{
content->GetAttributeNameAt(i, nameSpaceID, *getter_AddRefs(attrName),
@ -591,10 +590,10 @@ PRBool nsHTMLEditor::IsOnlyAttribute(nsIDOMNode *aNode,
if (!attrName) continue; // ooops
attrName->ToString(attrString);
// if it's the attribute we know about, keep looking
if (attrString.EqualsIgnoreCase(tString)) continue;
if (!Compare(attrString,*aAttribute,nsCaseInsensitiveStringComparator())) continue;
// if it's a special _moz... attribute, keep looking
attrString.Left(tmp,4);
if (tmp.EqualsWithConversion("_moz")) continue;
if (!Compare(attrString,NS_LITERAL_STRING("_moz"),nsCaseInsensitiveStringComparator())) continue;
// otherwise, it's another attribute, so return false
return PR_FALSE;
}
@ -702,8 +701,7 @@ PRBool nsHTMLEditor::HasAttrVal(nsIDOMNode *aNode,
attNode->GetValue(attrVal);
// do values match?
nsString tString(*aValue);//MJUDGE SCC NEED HELP
if (attrVal.EqualsIgnoreCase(tString)) return PR_TRUE;
if (!Compare(attrVal,*aValue,nsCaseInsensitiveStringComparator())) return PR_TRUE;
return PR_FALSE;
}

Просмотреть файл

@ -126,39 +126,34 @@ nsInternetCiter::StripCitesAndLinebreaks(const nsAReadableString& aInString,
*aCiteLevel = 0;
aOutString.SetLength(0);
nsString tString(aInString);//CRAPCRAP
PRInt32 length = tString.Length();
nsReadingIterator <PRUnichar> beginIter,endIter;
aInString.BeginReading(beginIter);
aInString.EndReading(endIter);
PRInt32 length = aInString.Length();
PRInt32 i = 0;
while (i < length) // loop over lines
while (beginIter!= endIter) // loop over lines
{
// Clear out cites first, at the beginning of the line:
PRInt32 thisLineCiteLevel = 0;
while (tString[i] == gt || nsCRT::IsAsciiSpace(tString[i]))
while (beginIter!= endIter && (*beginIter == gt || nsCRT::IsAsciiSpace(*beginIter)))
{
if (tString[i] == gt) ++thisLineCiteLevel;
++i;
if (*beginIter == gt) ++thisLineCiteLevel;
++beginIter;
}
// Now copy characters until line end:
PRInt32 nextNewline = tString.FindCharInSet("\r\n", i);
if (nextNewline > i)
while (beginIter != endIter && (*beginIter != '\r' && *beginIter != '\n'))
{
while (i < nextNewline)
aOutString.Append(tString[i++]);
aOutString.Append(*beginIter);
++beginIter;
}
if (aLinebreaksToo)
aOutString.Append(PRUnichar(' '));
else
aOutString.Append(PRUnichar('\n')); // DOM linebreaks, not NS_LINEBREAK
// Skip over any more consecutive linebreak-like characters:
while (i < length && (tString[i] == '\r' || tString[i] == '\n'))
++i;
}
else // no more newlines
{
while (i < length)
aOutString.Append(tString[i++]);
}
while (beginIter != endIter && (*beginIter == '\r' || *beginIter == '\n'))
++beginIter;
// Done with this line -- update cite level
if (aCiteLevel && (thisLineCiteLevel > *aCiteLevel))

Просмотреть файл

@ -1931,10 +1931,9 @@ nsHTMLEditRules::WillMakeList(nsISelection *aSelection,
// deduce what tag to use for list items
nsAutoString itemType;
nsString tString(*aListType);//MJUDGE SCC NEED HELP
if (aItemType)
itemType = *aItemType;
else if (tString.EqualsWithConversion("dl"))
else if (!Compare(*aListType,NS_LITERAL_STRING("dl"),nsCaseInsensitiveStringComparator()))
itemType.AssignWithConversion("dd");
else
itemType.AssignWithConversion("li");
@ -4598,7 +4597,9 @@ nsHTMLEditRules::ApplyBlockStyle(nsISupportsArray *arrayOfNodes, const nsAReadab
// we special case an empty tag name to mean "remove block parents".
// This is used for the "normal" paragraph style in mail-compose
nsString tString(*aBlockTag);////MJUDGE SCC NEED HELP
if (tString.IsEmpty() || tString.EqualsWithConversion("normal")) bNoParent = PR_TRUE;
if (tString.IsEmpty() ||
!Compare(tString,NS_LITERAL_STRING("normal"),nsCaseInsensitiveStringComparator()))
bNoParent = PR_TRUE;
arrayOfNodes->Count(&listCount);
@ -4690,8 +4691,8 @@ nsHTMLEditRules::ApplyBlockStyle(nsISupportsArray *arrayOfNodes, const nsAReadab
else if (IsInlineNode(curNode) && !bNoParent)
{
// if curNode is a non editable, drop it if we are going to <pre>
nsString tString(*aBlockTag); ////MJUDGE SCC NEED HELP
if ((tString.EqualsWithConversion("pre")) && (!mHTMLEditor->IsEditable(curNode)))
if (!Compare(tString,NS_LITERAL_STRING("pre"),nsCaseInsensitiveStringComparator())
&& (!mHTMLEditor->IsEditable(curNode)))
continue; // do nothing to this block
// if no curBlock, make one
@ -5490,14 +5491,15 @@ nsresult
nsHTMLEditRules::ConvertWhitespace(const nsAReadableString & inString, nsAWritableString & outString)
{
PRUint32 j,len = inString.Length();
nsString tString(inString);////MJUDGE SCC NEED HELP
nsReadingIterator <PRUnichar> iter;
inString.BeginReading(iter);
switch (len)
{
case 0:
outString.SetLength(0);
return NS_OK;
case 1:
if (tString.EqualsWithConversion("\n")) // a bit of a hack: don't convert single newlines that
if (*iter == '\n') // a bit of a hack: don't convert single newlines that
outString.Assign(NS_LITERAL_STRING("\n")); // dont have whitespace adjacent. This is to preserve
else // html source formatting to some degree.
outString.Assign(NS_LITERAL_STRING(" "));

Просмотреть файл

@ -2226,8 +2226,8 @@ nsHTMLEditor::RemoveList(const nsAReadableString& aListType)
if (!selection) return NS_ERROR_NULL_POINTER;
nsTextRulesInfo ruleInfo(nsTextEditRules::kRemoveList);
nsString tString(aListType);//MJUDGE SCC NEED HELP
if (tString.EqualsWithConversion("ol")) ruleInfo.bOrdered = PR_TRUE;
if (!Compare(aListType,NS_LITERAL_STRING("ol"),nsCaseInsensitiveStringComparator()))
ruleInfo.bOrdered = PR_TRUE;
else ruleInfo.bOrdered = PR_FALSE;
res = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
if (cancel || (NS_FAILED(res))) return res;
@ -2349,8 +2349,7 @@ nsHTMLEditor::Indent(const nsAReadableString& aIndent)
PRBool cancel, handled;
PRInt32 theAction = nsTextEditRules::kIndent;
PRInt32 opID = kOpIndent;
nsString tString(aIndent);//MJUDGE SCC NEED HELP
if (tString.EqualsWithConversion("outdent"))
if (!Compare(aIndent,NS_LITERAL_STRING("outdent"),nsCaseInsensitiveStringComparator()))
{
theAction = nsTextEditRules::kOutdent;
opID = kOpOutdent;
@ -3536,26 +3535,20 @@ PRBool
nsHTMLEditor::TagCanContainTag(const nsAReadableString& aParentTag, const nsAReadableString& aChildTag)
{
// COtherDTD gives some unwanted results. We override them here.
nsAutoString olStr, ulStr, liStr;
olStr = NS_LITERAL_STRING("ol");
ulStr = NS_LITERAL_STRING("ul");
liStr = NS_LITERAL_STRING("li");
nsString tParent(aParentTag);//MJUDGE SCC NEED HELP
nsString tChild(aChildTag);//MJUDGE SCC NEED HELP
if ( tParent.EqualsIgnoreCase(olStr) ||
tParent.EqualsIgnoreCase(ulStr) )
if (!Compare(aParentTag,NS_LITERAL_STRING("ol"),nsCaseInsensitiveStringComparator()) ||
!Compare(aParentTag,NS_LITERAL_STRING("ul"),nsCaseInsensitiveStringComparator()))
{
// if parent is a list and tag is also a list, say "yes".
// This is because the editor does sublists illegally for now.
if (tChild.EqualsIgnoreCase(olStr) ||
tChild.EqualsIgnoreCase(ulStr) )
if (!Compare(aChildTag,NS_LITERAL_STRING("ol"),nsCaseInsensitiveStringComparator()) ||
!Compare(aChildTag,NS_LITERAL_STRING("ul"),nsCaseInsensitiveStringComparator()))
return PR_TRUE;
}
if ( tParent.EqualsIgnoreCase(liStr) )
if (!Compare(aParentTag,NS_LITERAL_STRING("li"),nsCaseInsensitiveStringComparator()))
{
// list items cant contain list items
if (tChild.EqualsIgnoreCase(liStr) )
if (!Compare(aChildTag,NS_LITERAL_STRING("li"),nsCaseInsensitiveStringComparator()))
return PR_FALSE;
}

Просмотреть файл

@ -582,7 +582,6 @@ PRBool nsHTMLEditor::IsOnlyAttribute(nsIDOMNode *aNode,
nsCOMPtr<nsIAtom> attrName, prefix;
content->GetAttributeCount(attrCount);
nsString tString(*aAttribute);//MJUDGE SCC NEED HELP
for (i=0; i<attrCount; i++)
{
content->GetAttributeNameAt(i, nameSpaceID, *getter_AddRefs(attrName),
@ -591,10 +590,10 @@ PRBool nsHTMLEditor::IsOnlyAttribute(nsIDOMNode *aNode,
if (!attrName) continue; // ooops
attrName->ToString(attrString);
// if it's the attribute we know about, keep looking
if (attrString.EqualsIgnoreCase(tString)) continue;
if (!Compare(attrString,*aAttribute,nsCaseInsensitiveStringComparator())) continue;
// if it's a special _moz... attribute, keep looking
attrString.Left(tmp,4);
if (tmp.EqualsWithConversion("_moz")) continue;
if (!Compare(attrString,NS_LITERAL_STRING("_moz"),nsCaseInsensitiveStringComparator())) continue;
// otherwise, it's another attribute, so return false
return PR_FALSE;
}
@ -702,8 +701,7 @@ PRBool nsHTMLEditor::HasAttrVal(nsIDOMNode *aNode,
attNode->GetValue(attrVal);
// do values match?
nsString tString(*aValue);//MJUDGE SCC NEED HELP
if (attrVal.EqualsIgnoreCase(tString)) return PR_TRUE;
if (!Compare(attrVal,*aValue,nsCaseInsensitiveStringComparator())) return PR_TRUE;
return PR_FALSE;
}

Просмотреть файл

@ -24,6 +24,7 @@
#include "nsAOLCiter.h"
#include "nsWrapUtils.h"
#include "nsReadableUtils.h"
/** Mail citations using the AOL style >> This is a citation <<
*/
@ -86,17 +87,19 @@ NS_IMETHODIMP
nsAOLCiter::StripCites(const nsAReadableString& aInString, nsAWritableString& aOutString)
{
// Remove the beginning cites, if any:
nsAutoString tInputString(aInString);//MJUDGE SCC NEED HELP
nsAutoString tOutputString;
if (tInputString.EqualsWithConversion(">>", PR_FALSE, 2))
nsReadingIterator <PRUnichar> iter,enditer;
aInString.BeginReading(iter);
aInString.EndReading(enditer);
if (!Compare(Substring(aInString,0,2),NS_LITERAL_STRING(">>")))
{
PRInt32 i = 3;
while (nsCRT::IsAsciiSpace(tInputString[i]))
++i;
tOutputString.Append(tInputString.GetUnicode(), i);
iter.advance(2);
while (nsCRT::IsAsciiSpace(*iter))
++iter;
AppendUnicodeTo(iter,enditer,tOutputString);
}
else
tOutputString = tInputString;
CopyUnicodeTo(iter,enditer,tOutputString);
// Remove the end cites, if any:
tOutputString.Trim("<", PR_FALSE, PR_TRUE, PR_FALSE);

Просмотреть файл

@ -126,39 +126,34 @@ nsInternetCiter::StripCitesAndLinebreaks(const nsAReadableString& aInString,
*aCiteLevel = 0;
aOutString.SetLength(0);
nsString tString(aInString);//CRAPCRAP
PRInt32 length = tString.Length();
nsReadingIterator <PRUnichar> beginIter,endIter;
aInString.BeginReading(beginIter);
aInString.EndReading(endIter);
PRInt32 length = aInString.Length();
PRInt32 i = 0;
while (i < length) // loop over lines
while (beginIter!= endIter) // loop over lines
{
// Clear out cites first, at the beginning of the line:
PRInt32 thisLineCiteLevel = 0;
while (tString[i] == gt || nsCRT::IsAsciiSpace(tString[i]))
while (beginIter!= endIter && (*beginIter == gt || nsCRT::IsAsciiSpace(*beginIter)))
{
if (tString[i] == gt) ++thisLineCiteLevel;
++i;
if (*beginIter == gt) ++thisLineCiteLevel;
++beginIter;
}
// Now copy characters until line end:
PRInt32 nextNewline = tString.FindCharInSet("\r\n", i);
if (nextNewline > i)
while (beginIter != endIter && (*beginIter != '\r' && *beginIter != '\n'))
{
while (i < nextNewline)
aOutString.Append(tString[i++]);
aOutString.Append(*beginIter);
++beginIter;
}
if (aLinebreaksToo)
aOutString.Append(PRUnichar(' '));
else
aOutString.Append(PRUnichar('\n')); // DOM linebreaks, not NS_LINEBREAK
// Skip over any more consecutive linebreak-like characters:
while (i < length && (tString[i] == '\r' || tString[i] == '\n'))
++i;
}
else // no more newlines
{
while (i < length)
aOutString.Append(tString[i++]);
}
while (beginIter != endIter && (*beginIter == '\r' || *beginIter == '\n'))
++beginIter;
// Done with this line -- update cite level
if (aCiteLevel && (thisLineCiteLevel > *aCiteLevel))