Use nsAutoStrings where appropriate

This commit is contained in:
sfraser%netscape.com 1999-09-14 23:40:16 +00:00
parent 462a172866
commit e435677c81
9 changed files with 53 additions and 53 deletions

View File

@ -101,7 +101,7 @@ nsHTMLEditor::InsertTableColumn(PRInt32 aNumber, PRBool aAfter)
{
// We have a cell spanning this location
// Simply increase its rowspan to keep table rectangular
nsString newColSpan;
nsAutoString newColSpan;
newColSpan.Append(colSpan+aNumber, 10);
SetAttribute(curCell, "colspan", newColSpan);
} else {

View File

@ -55,7 +55,7 @@ NS_IMETHODIMP InsertTextTxn::Init(nsIDOMCharacterData *aElement,
nsWeakPtr aPresShellWeak)
{
#if 0 //def DEBUG_cmanske
nsString text;
nsAutoString text;
aElement->GetData(text);
printf("InsertTextTxn: Offset to insert at = %d. Text of the node to insert into:\n", aOffset);
wprintf(text.GetUnicode());

View File

@ -374,9 +374,9 @@ nsTextEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aPr
else if (PR_TRUE==altKey)
{
aProcessed=PR_TRUE;
nsString output;
nsAutoString output;
nsresult res = NS_ERROR_FAILURE;
nsString format;
nsAutoString format;
if (isShift)
format = "text/plain";
else
@ -563,7 +563,7 @@ nsTextEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aPr
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
if (htmlEditor)
{
nsString nsstr ("This is <b>bold <em>and emphasized</em></b> text");
nsAutoString nsstr ("This is <b>bold <em>and emphasized</em></b> text");
htmlEditor->InsertHTML(nsstr);
}
}
@ -1256,7 +1256,7 @@ nsTextEditorTextListener::HandleEvent(nsIDOMEvent* aEvent)
nsresult
nsTextEditorTextListener::HandleText(nsIDOMEvent* aTextEvent)
{
nsString composedText;
nsAutoString composedText;
nsresult result = NS_OK;
nsCOMPtr<nsIPrivateTextEvent> textEvent;
nsIPrivateTextRangeList *textRangeList;

View File

@ -359,7 +359,7 @@ nsEditorShell::InstantiateEditor(nsIDOMDocument *aDoc, nsIPresShell *aPresShell)
{
err = NS_ERROR_INVALID_ARG; // this is not an editor we know about
#if DEBUG
nsString errorMsg = "Failed to init editor. Unknown editor type \"";
nsAutoString errorMsg = "Failed to init editor. Unknown editor type \"";
errorMsg += mEditorTypeString;
errorMsg += "\"\n";
char *errorMsgCString = errorMsg.ToNewCString();
@ -1022,8 +1022,8 @@ nsEditorShell::CheckAndSaveDocument(PRBool *_retval)
if (modCount > 0)
{
// Ask user if they want to save current changes
nsString tmp1 = GetString("Save");
nsString tmp2 = GetString("DontSave");
nsAutoString tmp1 = GetString("Save");
nsAutoString tmp2 = GetString("DontSave");
EConfirmResult result = ConfirmWithCancel(GetString("SaveDocument"), GetString("SaveFilePrompt"),
&tmp1, &tmp2);
if (result == eCancel)
@ -1076,7 +1076,7 @@ nsEditorShell::SaveDocument(PRBool saveAs, PRBool saveCopy, PRBool *_retval)
nsCOMPtr<nsIDocument> document = do_QueryInterface(doc);
if (document)
{
nsString const *title = document->GetDocumentTitle();
const nsString* title = document->GetDocumentTitle(); // don't delete
if (title)
{
if (title->Length() == 0)
@ -1742,7 +1742,7 @@ nsEditorShell::GetString(const PRUnichar *name, PRUnichar **_retval)
return NS_ERROR_NULL_POINTER;
// Don't fail, just return an empty string
nsString empty("");
nsAutoString empty("");
if (mStringBundle)
{
@ -1795,12 +1795,12 @@ nsEditorShell::ConfirmWithCancel(const nsString& aTitle, const nsString& aQuesti
// Stuff in Parameters
block->SetInt( nsICommonDialogs::eNumberButtons,3 );
block->SetString( nsICommonDialogs::eMsg, aQuestion.GetUnicode());
nsString url( "chrome://global/skin/question-icon.gif" );
nsAutoString url( "chrome://global/skin/question-icon.gif" );
block->SetString( nsICommonDialogs::eIconURL, url.GetUnicode());
nsString yes = aYesString ? *aYesString : GetString("Yes");
nsString no = aNoString ? *aNoString : GetString("No");
nsString cancel = GetString("Cancel");
nsAutoString yes = aYesString ? *aYesString : GetString("Yes");
nsAutoString no = aNoString ? *aNoString : GetString("No");
nsAutoString cancel = GetString("Cancel");
block->SetString( nsICommonDialogs::eButton0Text, yes.GetUnicode() );
// This is currently not good -- 2nd button is linked to Cancel
block->SetString( nsICommonDialogs::eButton1Text, cancel.GetUnicode() );
@ -1876,7 +1876,7 @@ nsEditorShell::GetContentsAs(const PRUnichar *format, PRUint32 flags,
{
nsresult err = NS_NOINTERFACE;
nsString aFormat (format);
nsAutoString aFormat (format);
nsString aContentsAs;
nsCOMPtr<nsIEditor> editor = do_QueryInterface(mEditor);
@ -2835,7 +2835,7 @@ NS_IMETHODIMP
nsEditorShell::AddWordToDictionary(const PRUnichar *aWord)
{
nsresult result = NS_NOINTERFACE;
nsString word(aWord);
nsAutoString word(aWord);
if (mEditor && mSpellChecker)
{
result = mSpellChecker->AddWordToPersonalDictionary(&word);
@ -2847,7 +2847,7 @@ NS_IMETHODIMP
nsEditorShell::RemoveWordFromDictionary(const PRUnichar *aWord)
{
nsresult result = NS_NOINTERFACE;
nsString word(aWord);
nsAutoString word(aWord);
if (mEditor && mSpellChecker)
{
result = mSpellChecker->RemoveWordFromPersonalDictionary(&word);

View File

@ -121,7 +121,7 @@ static PRBool IsLinkNode(nsIDOMNode *aNode)
nsCOMPtr<nsIDOMHTMLAnchorElement> anchor = do_QueryInterface(aNode);
if (anchor)
{
nsString tmpText;
nsAutoString tmpText;
if (NS_SUCCEEDED(anchor->GetHref(tmpText)) && tmpText.GetUnicode() && tmpText.Length() != 0)
return PR_TRUE;
}
@ -136,7 +136,7 @@ static PRBool IsNamedAnchorNode(nsIDOMNode *aNode)
nsCOMPtr<nsIDOMHTMLAnchorElement> anchor = do_QueryInterface(aNode);
if (anchor)
{
nsString tmpText;
nsAutoString tmpText;
if (NS_SUCCEEDED(anchor->GetName(tmpText)) && tmpText.GetUnicode() && tmpText.Length() != 0)
return PR_TRUE;
}
@ -1030,7 +1030,7 @@ NS_IMETHODIMP nsHTMLEditor::InsertText(const nsString& aStringToInsert)
nsresult result = GetSelection(getter_AddRefs(selection));
if (NS_FAILED(result)) return result;
if (!selection) return NS_ERROR_NULL_POINTER;
nsString resultString;
nsAutoString resultString;
PlaceholderTxn *placeholderTxn=nsnull;
nsTextRulesInfo ruleInfo(nsTextEditRules::kInsertText);
ruleInfo.placeTxn = &placeholderTxn;
@ -1444,8 +1444,8 @@ nsHTMLEditor::SetCaretAfterElement(nsIDOMElement* aElement)
printf("SetCaretAfterElement: Parent node: ");
wprintf(name.GetUnicode());
printf(" Offset: %d\n\nHTML:\n", offsetInParent+1);
nsString Format("text/html");
nsString ContentsAs;
nsAutoString Format("text/html");
nsAutoString ContentsAs;
OutputToString(ContentsAs, Format, 2);
wprintf(ContentsAs.GetUnicode());
}
@ -2345,7 +2345,7 @@ nsHTMLEditor::CreateElementWithDefaults(const nsString& aTagName, nsIDOMElement*
// TODO: This should probably be in the RULES code or
// preference based for "should we add the nbsp"
nsCOMPtr<nsIDOMText>newTextNode;
nsString space;
nsAutoString space;
// Set contents to the &nbsp character by concatanating the char code
space += nbsp;
// If we fail here, we return NS_OK anyway, since we have an OK cell node
@ -2792,7 +2792,7 @@ NS_IMETHODIMP nsHTMLEditor::SetBodyWrapWidth(PRInt32 aWrapColumn)
// Get the current style for this body element:
nsAutoString styleName ("style");
nsString styleValue;
nsAutoString styleValue;
res = bodyElement->GetAttribute(styleName, styleValue);
if (NS_FAILED(res)) return res;
@ -3573,7 +3573,7 @@ void nsHTMLEditor::IsTextPropertySetByContent(nsIDOMNode *aNode,
element = do_QueryInterface(parent);
if (element)
{
nsString tag;
nsAutoString tag;
element->GetTagName(tag);
if (propName.EqualsIgnoreCase(tag))
{
@ -4491,7 +4491,7 @@ nsHTMLEditor::SetCaretInTableCell(nsIDOMElement* aElement)
{
// Check if node is text and has more than just a &nbsp
nsCOMPtr<nsIDOMCharacterData>textNode = do_QueryInterface(node);
nsString text;
nsAutoString text;
char nbspStr[2] = {nbsp, 0};
if (textNode && textNode->GetData(text))
{

View File

@ -359,7 +359,7 @@ nsEditorShell::InstantiateEditor(nsIDOMDocument *aDoc, nsIPresShell *aPresShell)
{
err = NS_ERROR_INVALID_ARG; // this is not an editor we know about
#if DEBUG
nsString errorMsg = "Failed to init editor. Unknown editor type \"";
nsAutoString errorMsg = "Failed to init editor. Unknown editor type \"";
errorMsg += mEditorTypeString;
errorMsg += "\"\n";
char *errorMsgCString = errorMsg.ToNewCString();
@ -1022,8 +1022,8 @@ nsEditorShell::CheckAndSaveDocument(PRBool *_retval)
if (modCount > 0)
{
// Ask user if they want to save current changes
nsString tmp1 = GetString("Save");
nsString tmp2 = GetString("DontSave");
nsAutoString tmp1 = GetString("Save");
nsAutoString tmp2 = GetString("DontSave");
EConfirmResult result = ConfirmWithCancel(GetString("SaveDocument"), GetString("SaveFilePrompt"),
&tmp1, &tmp2);
if (result == eCancel)
@ -1076,7 +1076,7 @@ nsEditorShell::SaveDocument(PRBool saveAs, PRBool saveCopy, PRBool *_retval)
nsCOMPtr<nsIDocument> document = do_QueryInterface(doc);
if (document)
{
nsString const *title = document->GetDocumentTitle();
const nsString* title = document->GetDocumentTitle(); // don't delete
if (title)
{
if (title->Length() == 0)
@ -1742,7 +1742,7 @@ nsEditorShell::GetString(const PRUnichar *name, PRUnichar **_retval)
return NS_ERROR_NULL_POINTER;
// Don't fail, just return an empty string
nsString empty("");
nsAutoString empty("");
if (mStringBundle)
{
@ -1795,12 +1795,12 @@ nsEditorShell::ConfirmWithCancel(const nsString& aTitle, const nsString& aQuesti
// Stuff in Parameters
block->SetInt( nsICommonDialogs::eNumberButtons,3 );
block->SetString( nsICommonDialogs::eMsg, aQuestion.GetUnicode());
nsString url( "chrome://global/skin/question-icon.gif" );
nsAutoString url( "chrome://global/skin/question-icon.gif" );
block->SetString( nsICommonDialogs::eIconURL, url.GetUnicode());
nsString yes = aYesString ? *aYesString : GetString("Yes");
nsString no = aNoString ? *aNoString : GetString("No");
nsString cancel = GetString("Cancel");
nsAutoString yes = aYesString ? *aYesString : GetString("Yes");
nsAutoString no = aNoString ? *aNoString : GetString("No");
nsAutoString cancel = GetString("Cancel");
block->SetString( nsICommonDialogs::eButton0Text, yes.GetUnicode() );
// This is currently not good -- 2nd button is linked to Cancel
block->SetString( nsICommonDialogs::eButton1Text, cancel.GetUnicode() );
@ -1876,7 +1876,7 @@ nsEditorShell::GetContentsAs(const PRUnichar *format, PRUint32 flags,
{
nsresult err = NS_NOINTERFACE;
nsString aFormat (format);
nsAutoString aFormat (format);
nsString aContentsAs;
nsCOMPtr<nsIEditor> editor = do_QueryInterface(mEditor);
@ -2835,7 +2835,7 @@ NS_IMETHODIMP
nsEditorShell::AddWordToDictionary(const PRUnichar *aWord)
{
nsresult result = NS_NOINTERFACE;
nsString word(aWord);
nsAutoString word(aWord);
if (mEditor && mSpellChecker)
{
result = mSpellChecker->AddWordToPersonalDictionary(&word);
@ -2847,7 +2847,7 @@ NS_IMETHODIMP
nsEditorShell::RemoveWordFromDictionary(const PRUnichar *aWord)
{
nsresult result = NS_NOINTERFACE;
nsString word(aWord);
nsAutoString word(aWord);
if (mEditor && mSpellChecker)
{
result = mSpellChecker->RemoveWordFromPersonalDictionary(&word);

View File

@ -55,7 +55,7 @@ NS_IMETHODIMP InsertTextTxn::Init(nsIDOMCharacterData *aElement,
nsWeakPtr aPresShellWeak)
{
#if 0 //def DEBUG_cmanske
nsString text;
nsAutoString text;
aElement->GetData(text);
printf("InsertTextTxn: Offset to insert at = %d. Text of the node to insert into:\n", aOffset);
wprintf(text.GetUnicode());

View File

@ -121,7 +121,7 @@ static PRBool IsLinkNode(nsIDOMNode *aNode)
nsCOMPtr<nsIDOMHTMLAnchorElement> anchor = do_QueryInterface(aNode);
if (anchor)
{
nsString tmpText;
nsAutoString tmpText;
if (NS_SUCCEEDED(anchor->GetHref(tmpText)) && tmpText.GetUnicode() && tmpText.Length() != 0)
return PR_TRUE;
}
@ -136,7 +136,7 @@ static PRBool IsNamedAnchorNode(nsIDOMNode *aNode)
nsCOMPtr<nsIDOMHTMLAnchorElement> anchor = do_QueryInterface(aNode);
if (anchor)
{
nsString tmpText;
nsAutoString tmpText;
if (NS_SUCCEEDED(anchor->GetName(tmpText)) && tmpText.GetUnicode() && tmpText.Length() != 0)
return PR_TRUE;
}
@ -1030,7 +1030,7 @@ NS_IMETHODIMP nsHTMLEditor::InsertText(const nsString& aStringToInsert)
nsresult result = GetSelection(getter_AddRefs(selection));
if (NS_FAILED(result)) return result;
if (!selection) return NS_ERROR_NULL_POINTER;
nsString resultString;
nsAutoString resultString;
PlaceholderTxn *placeholderTxn=nsnull;
nsTextRulesInfo ruleInfo(nsTextEditRules::kInsertText);
ruleInfo.placeTxn = &placeholderTxn;
@ -1444,8 +1444,8 @@ nsHTMLEditor::SetCaretAfterElement(nsIDOMElement* aElement)
printf("SetCaretAfterElement: Parent node: ");
wprintf(name.GetUnicode());
printf(" Offset: %d\n\nHTML:\n", offsetInParent+1);
nsString Format("text/html");
nsString ContentsAs;
nsAutoString Format("text/html");
nsAutoString ContentsAs;
OutputToString(ContentsAs, Format, 2);
wprintf(ContentsAs.GetUnicode());
}
@ -2345,7 +2345,7 @@ nsHTMLEditor::CreateElementWithDefaults(const nsString& aTagName, nsIDOMElement*
// TODO: This should probably be in the RULES code or
// preference based for "should we add the nbsp"
nsCOMPtr<nsIDOMText>newTextNode;
nsString space;
nsAutoString space;
// Set contents to the &nbsp character by concatanating the char code
space += nbsp;
// If we fail here, we return NS_OK anyway, since we have an OK cell node
@ -2792,7 +2792,7 @@ NS_IMETHODIMP nsHTMLEditor::SetBodyWrapWidth(PRInt32 aWrapColumn)
// Get the current style for this body element:
nsAutoString styleName ("style");
nsString styleValue;
nsAutoString styleValue;
res = bodyElement->GetAttribute(styleName, styleValue);
if (NS_FAILED(res)) return res;
@ -3573,7 +3573,7 @@ void nsHTMLEditor::IsTextPropertySetByContent(nsIDOMNode *aNode,
element = do_QueryInterface(parent);
if (element)
{
nsString tag;
nsAutoString tag;
element->GetTagName(tag);
if (propName.EqualsIgnoreCase(tag))
{
@ -4491,7 +4491,7 @@ nsHTMLEditor::SetCaretInTableCell(nsIDOMElement* aElement)
{
// Check if node is text and has more than just a &nbsp
nsCOMPtr<nsIDOMCharacterData>textNode = do_QueryInterface(node);
nsString text;
nsAutoString text;
char nbspStr[2] = {nbsp, 0};
if (textNode && textNode->GetData(text))
{

View File

@ -374,9 +374,9 @@ nsTextEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aPr
else if (PR_TRUE==altKey)
{
aProcessed=PR_TRUE;
nsString output;
nsAutoString output;
nsresult res = NS_ERROR_FAILURE;
nsString format;
nsAutoString format;
if (isShift)
format = "text/plain";
else
@ -563,7 +563,7 @@ nsTextEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aPr
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
if (htmlEditor)
{
nsString nsstr ("This is <b>bold <em>and emphasized</em></b> text");
nsAutoString nsstr ("This is <b>bold <em>and emphasized</em></b> text");
htmlEditor->InsertHTML(nsstr);
}
}
@ -1256,7 +1256,7 @@ nsTextEditorTextListener::HandleEvent(nsIDOMEvent* aEvent)
nsresult
nsTextEditorTextListener::HandleText(nsIDOMEvent* aTextEvent)
{
nsString composedText;
nsAutoString composedText;
nsresult result = NS_OK;
nsCOMPtr<nsIPrivateTextEvent> textEvent;
nsIPrivateTextRangeList *textRangeList;