diff --git a/content/base/src/nsCommentNode.cpp b/content/base/src/nsCommentNode.cpp index e309a7ec4b22..63e8b64422a0 100644 --- a/content/base/src/nsCommentNode.cpp +++ b/content/base/src/nsCommentNode.cpp @@ -369,7 +369,7 @@ nsCommentNode::List(FILE* out, PRInt32 aIndent) const nsAutoString tmp; mInner.ToCString(tmp, 0, mInner.mText.GetLength()); - fputs(tmp, out); + fputs(NS_LossyConvertUCS2toASCII(tmp).get(), out); fputs("-->\n", out); return NS_OK; diff --git a/content/base/src/nsDocumentViewer.cpp b/content/base/src/nsDocumentViewer.cpp index 05b6612e0adf..11dc255adcd6 100644 --- a/content/base/src/nsDocumentViewer.cpp +++ b/content/base/src/nsDocumentViewer.cpp @@ -1554,7 +1554,7 @@ static void DumpFrames(FILE* out, if (NS_SUCCEEDED(CallQueryInterface(child, &frameDebug))) { frameDebug->GetFrameName(tmp); } - fputs(tmp, out); + fputs(NS_LossyConvertUCS2toASCII(tmp).get(), out); nsFrameState state; child->GetFrameState(&state); PRBool isSelected; diff --git a/content/base/src/nsGenericElement.cpp b/content/base/src/nsGenericElement.cpp index 6bf39ca7c4c3..b7a84b6cff8d 100644 --- a/content/base/src/nsGenericElement.cpp +++ b/content/base/src/nsGenericElement.cpp @@ -3410,7 +3410,7 @@ nsGenericContainerElement::ListAttributes(FILE* out) const buffer.Append(attr->mValue); fputs(" ", out); - fputs(buffer, out); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out); } } @@ -3424,7 +3424,7 @@ nsGenericContainerElement::List(FILE* out, PRInt32 aIndent) const nsAutoString buf; mNodeInfo->GetQualifiedName(buf); - fputs(buf, out); + fputs(NS_LossyConvertUCS2toASCII(buf).get(), out); fprintf(out, "@%p", this); diff --git a/content/base/src/nsStyleContext.cpp b/content/base/src/nsStyleContext.cpp index dd3183473eae..142520b60984 100644 --- a/content/base/src/nsStyleContext.cpp +++ b/content/base/src/nsStyleContext.cpp @@ -841,7 +841,7 @@ void nsStyleContext::List(FILE* out, PRInt32 aIndent) if (nsnull != mPseudoTag) { nsAutoString buffer; mPseudoTag->ToString(buffer); - fputs(buffer, out); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out); fputs(" ", out); } diff --git a/content/base/src/nsTextNode.cpp b/content/base/src/nsTextNode.cpp index 11b1006de96a..0cefb40b38e2 100644 --- a/content/base/src/nsTextNode.cpp +++ b/content/base/src/nsTextNode.cpp @@ -219,7 +219,7 @@ nsTextNode::List(FILE* out, PRInt32 aIndent) const nsAutoString tmp; mInner.ToCString(tmp, 0, mInner.mText.GetLength()); - fputs(tmp, out); + fputs(NS_LossyConvertUCS2toASCII(tmp).get(), out); fputs(">\n", out); return NS_OK; @@ -238,7 +238,7 @@ nsTextNode::DumpContent(FILE* out, PRInt32 aIndent,PRBool aDumpAll) const mInner.ToCString(tmp, 0, mInner.mText.GetLength()); if(!tmp.EqualsWithConversion("\\n")) { - fputs(tmp, out); + fputs(NS_LossyConvertUCS2toASCII(tmp).get(), out); if(aIndent) fputs("\n", out); } } diff --git a/content/build/nsContentDLF.cpp b/content/build/nsContentDLF.cpp index 5fda108622ac..7677bc397be8 100644 --- a/content/build/nsContentDLF.cpp +++ b/content/build/nsContentDLF.cpp @@ -305,7 +305,7 @@ nsContentDLF::CreateDocument(const char* aCommand, if (nsnull != aURL) { nsAutoString tmp; aURL->ToString(tmp); - fputs(tmp, stdout); + fputs(NS_LossyConvertUCS2toASCII(tmp).get(), stdout); printf(": creating document\n"); } #endif diff --git a/content/html/content/src/nsGenericHTMLElement.cpp b/content/html/content/src/nsGenericHTMLElement.cpp index 0258ba109e95..99a50516eeb3 100644 --- a/content/html/content/src/nsGenericHTMLElement.cpp +++ b/content/html/content/src/nsGenericHTMLElement.cpp @@ -2226,7 +2226,7 @@ nsGenericHTMLElement::ListAttributes(FILE* out) const buffer.Append(value); fputs(" ", out); - fputs(buffer, out); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out); NS_RELEASE(attr); } } @@ -2244,7 +2244,7 @@ nsGenericHTMLElement::List(FILE* out, PRInt32 aIndent) const if (tag != nsnull) { nsAutoString buf; tag->ToString(buf); - fputs(buf, out); + fputs(NS_LossyConvertUCS2toASCII(buf).get(), out); NS_RELEASE(tag); } fprintf(out, "@%p", this); @@ -2285,7 +2285,7 @@ nsGenericHTMLElement::DumpContent(FILE* out, PRInt32 aIndent,PRBool aDumpAll) co if (tag != nsnull) { tag->ToString(buf); fputs("<",out); - fputs(buf, out); + fputs(NS_LossyConvertUCS2toASCII(buf).get(), out); if(aDumpAll) ListAttributes(out); @@ -2308,7 +2308,7 @@ nsGenericHTMLElement::DumpContent(FILE* out, PRInt32 aIndent,PRBool aDumpAll) co } for (index = aIndent; --index >= 0; ) fputs(" ", out); fputs("",out); if(aIndent) fputs("\n", out); diff --git a/content/html/document/src/nsHTMLContentSink.cpp b/content/html/document/src/nsHTMLContentSink.cpp index f560c84be249..eba23989762e 100644 --- a/content/html/document/src/nsHTMLContentSink.cpp +++ b/content/html/document/src/nsHTMLContentSink.cpp @@ -1420,17 +1420,15 @@ SinkContext::DidAddContent(nsIContent* aContent, PRBool aDidNotify) #ifdef NS_DEBUG // Tracing code - char cbuf[40]; - const char* cp; nsAutoString str; nsCOMPtr dtd; mSink->mParser->GetDTD(getter_AddRefs(dtd)); dtd->IntTagToStringTag(nsHTMLTag(mStack[mStackPos-1].mType), str); - cp = str.ToCString(cbuf, sizeof(cbuf)); SINK_TRACE(SINK_TRACE_REFLOW, ("SinkContext::DidAddContent: Insertion notification for parent=%s at position=%d and stackPos=%d", - cp, mStack[mStackPos-1].mInsertionPoint-1, mStackPos-1)); + NS_LossyConvertUCS2toASCII(str).get(), + mStack[mStackPos-1].mInsertionPoint-1, mStackPos-1)); #endif mSink->NotifyInsert(parent, @@ -1603,16 +1601,15 @@ SinkContext::CloseContainer(const nsIParserNode& aNode) if (mStack[mStackPos].mNumFlushed < childCount) { #ifdef NS_DEBUG // Tracing code - char cbuf[40]; - const char* cp; nsAutoString str; nsCOMPtr dtd; mSink->mParser->GetDTD(getter_AddRefs(dtd)); dtd->IntTagToStringTag(nsHTMLTag(nodeType), str); - cp = str.ToCString(cbuf, sizeof(cbuf)); SINK_TRACE(SINK_TRACE_REFLOW, - ("SinkContext::CloseContainer: reflow on notifyImmediate tag=%s newIndex=%d stackPos=%d", cp, mStack[mStackPos].mNumFlushed, mStackPos)); + ("SinkContext::CloseContainer: reflow on notifyImmediate tag=%s newIndex=%d stackPos=%d", + NS_LossyConvertUCS2toASCII(str).get(), + mStack[mStackPos].mNumFlushed, mStackPos)); #endif mSink->NotifyAppend(content, mStack[mStackPos].mNumFlushed); } @@ -2175,17 +2172,15 @@ SinkContext::FlushTags(PRBool aNotify) if (!flushed && (mStack[stackPos].mNumFlushed < childCount)) { #ifdef NS_DEBUG // Tracing code - char cbuf[40]; - const char* cp; nsAutoString str; nsCOMPtr dtd; mSink->mParser->GetDTD(getter_AddRefs(dtd)); dtd->IntTagToStringTag(nsHTMLTag(mStack[stackPos].mType), str); - cp = str.ToCString(cbuf, sizeof(cbuf)); SINK_TRACE(SINK_TRACE_REFLOW, ("SinkContext::FlushTags: tag=%s from newindex=%d at stackPos=%d", - cp, mStack[stackPos].mNumFlushed, stackPos)); + NS_LossyConvertUCS2toASCII(str).get(), + mStack[stackPos].mNumFlushed, stackPos)); #endif if ((mStack[stackPos].mInsertionPoint != -1) && (mStackPos > (stackPos+1))) { diff --git a/content/html/style/src/nsCSSDeclaration.cpp b/content/html/style/src/nsCSSDeclaration.cpp index 3768ae80823f..8f58ac93b919 100644 --- a/content/html/style/src/nsCSSDeclaration.cpp +++ b/content/html/style/src/nsCSSDeclaration.cpp @@ -117,7 +117,7 @@ void nsCSSFont::List(FILE* out, PRInt32 aIndent) const mSize.AppendToString(buffer, eCSSProperty_font_size); mSizeAdjust.AppendToString(buffer, eCSSProperty_font_size_adjust); mStretch.AppendToString(buffer, eCSSProperty_font_stretch); - fputs(buffer, out); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out); } // --- support ----------------- @@ -188,7 +188,7 @@ void nsCSSColor::List(FILE* out, PRInt32 aIndent) const mBackAttachment.AppendToString(buffer, eCSSProperty_background_attachment); mBackPositionX.AppendToString(buffer, eCSSProperty_background_x_position); mBackPositionY.AppendToString(buffer, eCSSProperty_background_y_position); - fputs(buffer, out); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out); } // --- nsCSSText support ----------------- @@ -282,7 +282,7 @@ void nsCSSText::List(FILE* out, PRInt32 aIndent) const mUnicodeBidi.AppendToString(buffer, eCSSProperty_unicode_bidi); mLineHeight.AppendToString(buffer, eCSSProperty_line_height); mWhiteSpace.AppendToString(buffer, eCSSProperty_white_space); - fputs(buffer, out); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out); } // --- nsCSSRect ----------------- @@ -322,7 +322,7 @@ void nsCSSRect::List(FILE* out, nsCSSProperty aPropID, PRInt32 aIndent) const mRight.AppendToString(buffer); mBottom.AppendToString(buffer); mLeft.AppendToString(buffer); - fputs(buffer, out); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out); } void nsCSSRect::List(FILE* out, PRInt32 aIndent, const nsCSSProperty aTRBL[]) const @@ -352,7 +352,7 @@ void nsCSSRect::List(FILE* out, PRInt32 aIndent, const nsCSSProperty aTRBL[]) co mLeft.AppendToString(buffer); } - fputs(buffer, out); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out); } // --- nsCSSDisplay ----------------- @@ -405,13 +405,13 @@ void nsCSSDisplay::List(FILE* out, PRInt32 aIndent) const mVisibility.AppendToString(buffer, eCSSProperty_visibility); mOpacity.AppendToString(buffer, eCSSProperty_opacity); - fputs(buffer, out); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out); if (nsnull != mClip) { mClip->List(out, eCSSProperty_clip); } buffer.SetLength(0); mOverflow.AppendToString(buffer, eCSSProperty_overflow); - fputs(buffer, out); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out); } // --- nsCSSMargin ----------------- @@ -520,7 +520,7 @@ void nsCSSMargin::List(FILE* out, PRInt32 aIndent) const mOutlineRadius->List(out, aIndent, trbl); } mFloatEdge.AppendToString(buffer, eCSSProperty_float_edge); - fputs(buffer, out); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out); } // --- nsCSSPosition ----------------- @@ -571,7 +571,7 @@ void nsCSSPosition::List(FILE* out, PRInt32 aIndent) const mMaxHeight.AppendToString(buffer, eCSSProperty_max_height); mBoxSizing.AppendToString(buffer, eCSSProperty_box_sizing); mZIndex.AppendToString(buffer, eCSSProperty_z_index); - fputs(buffer, out); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out); if (nsnull != mOffset) { static const nsCSSProperty trbl[] = { @@ -618,7 +618,7 @@ void nsCSSList::List(FILE* out, PRInt32 aIndent) const mType.AppendToString(buffer, eCSSProperty_list_style_type); mImage.AppendToString(buffer, eCSSProperty_list_style_image); mPosition.AppendToString(buffer, eCSSProperty_list_style_position); - fputs(buffer, out); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out); } // --- nsCSSTable ----------------- @@ -662,7 +662,7 @@ void nsCSSTable::List(FILE* out, PRInt32 aIndent) const mEmptyCells.AppendToString(buffer, eCSSProperty_empty_cells); mLayout.AppendToString(buffer, eCSSProperty_table_layout); - fputs(buffer, out); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out); } // --- nsCSSBreaks ----------------- @@ -706,7 +706,7 @@ void nsCSSBreaks::List(FILE* out, PRInt32 aIndent) const mPageBreakBefore.AppendToString(buffer, eCSSProperty_page_break_before); mPageBreakInside.AppendToString(buffer, eCSSProperty_page_break_inside); - fputs(buffer, out); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out); } // --- nsCSSPage ----------------- @@ -744,7 +744,7 @@ void nsCSSPage::List(FILE* out, PRInt32 aIndent) const mSizeWidth.AppendToString(buffer, eCSSProperty_size_width); mSizeHeight.AppendToString(buffer, eCSSProperty_size_height); - fputs(buffer, out); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out); } // --- nsCSSContent support ----------------- @@ -861,7 +861,7 @@ void nsCSSContent::List(FILE* out, PRInt32 aIndent) const quotes = quotes->mNext; } - fputs(buffer, out); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out); } // --- nsCSSUserInterface ----------------- @@ -921,7 +921,7 @@ void nsCSSUserInterface::List(FILE* out, PRInt32 aIndent) const cursor = cursor->mNext; } - fputs(buffer, out); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out); } // --- nsCSSAural ----------------- @@ -991,7 +991,7 @@ void nsCSSAural::List(FILE* out, PRInt32 aIndent) const mVoiceFamily.AppendToString(buffer, eCSSProperty_voice_family); mVolume.AppendToString(buffer, eCSSProperty_volume); - fputs(buffer, out); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out); } #ifdef INCLUDE_XUL @@ -1032,7 +1032,7 @@ void nsCSSXUL::List(FILE* out, PRInt32 aIndent) const mBoxOrient.AppendToString(buffer, eCSSProperty_box_orient); mBoxPack.AppendToString(buffer, eCSSProperty_box_pack); mBoxOrdinal.AppendToString(buffer, eCSSProperty_box_ordinal_group); - fputs(buffer, out); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out); } #endif // INCLUDE_XUL diff --git a/content/html/style/src/nsCSSRules.cpp b/content/html/style/src/nsCSSRules.cpp index 4a5e5c1290f2..56ae56ce07b6 100644 --- a/content/html/style/src/nsCSSRules.cpp +++ b/content/html/style/src/nsCSSRules.cpp @@ -249,7 +249,7 @@ CSSCharsetRuleImpl::List(FILE* out, PRInt32 aIndent) const for (PRInt32 indent = aIndent; --indent >= 0; ) fputs(" ", out); fputs("@charset \"", out); - fputs(mEncoding, out); + fputs(NS_LossyConvertUCS2toASCII(mEncoding).get(), out); fputs("\"\n", out); return NS_OK; @@ -477,12 +477,12 @@ CSSImportRuleImpl::List(FILE* out, PRInt32 aIndent) const for (PRInt32 indent = aIndent; --indent >= 0; ) fputs(" ", out); fputs("@import \"", out); - fputs(mURLSpec, out); + fputs(NS_LossyConvertUCS2toASCII(mURLSpec).get(), out); fputs("\" ", out); nsAutoString mediaText; mMedia->GetText(mediaText); - fputs(mediaText, out); + fputs(NS_LossyConvertUCS2toASCII(mediaText).get(), out); fputs("\n", out); return NS_OK; @@ -876,7 +876,7 @@ CSSMediaRuleImpl::List(FILE* out, PRInt32 aIndent) const while (index < count) { nsCOMPtr medium = dont_AddRef((nsIAtom*)mMedia->ElementAt(index++)); medium->ToString(buffer); - fputs(buffer, out); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out); if (index < count) { fputs(", ", out); } @@ -1326,12 +1326,12 @@ CSSNameSpaceRuleImpl::List(FILE* out, PRInt32 aIndent) const if (mPrefix) { mPrefix->ToString(buffer); - fputs(buffer, out); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out); fputs(" ", out); } fputs("url(", out); - fputs(mURLSpec, out); + fputs(NS_LossyConvertUCS2toASCII(mURLSpec).get(), out); fputs(")\n", out); return NS_OK; } diff --git a/content/html/style/src/nsCSSStruct.cpp b/content/html/style/src/nsCSSStruct.cpp index 3768ae80823f..8f58ac93b919 100644 --- a/content/html/style/src/nsCSSStruct.cpp +++ b/content/html/style/src/nsCSSStruct.cpp @@ -117,7 +117,7 @@ void nsCSSFont::List(FILE* out, PRInt32 aIndent) const mSize.AppendToString(buffer, eCSSProperty_font_size); mSizeAdjust.AppendToString(buffer, eCSSProperty_font_size_adjust); mStretch.AppendToString(buffer, eCSSProperty_font_stretch); - fputs(buffer, out); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out); } // --- support ----------------- @@ -188,7 +188,7 @@ void nsCSSColor::List(FILE* out, PRInt32 aIndent) const mBackAttachment.AppendToString(buffer, eCSSProperty_background_attachment); mBackPositionX.AppendToString(buffer, eCSSProperty_background_x_position); mBackPositionY.AppendToString(buffer, eCSSProperty_background_y_position); - fputs(buffer, out); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out); } // --- nsCSSText support ----------------- @@ -282,7 +282,7 @@ void nsCSSText::List(FILE* out, PRInt32 aIndent) const mUnicodeBidi.AppendToString(buffer, eCSSProperty_unicode_bidi); mLineHeight.AppendToString(buffer, eCSSProperty_line_height); mWhiteSpace.AppendToString(buffer, eCSSProperty_white_space); - fputs(buffer, out); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out); } // --- nsCSSRect ----------------- @@ -322,7 +322,7 @@ void nsCSSRect::List(FILE* out, nsCSSProperty aPropID, PRInt32 aIndent) const mRight.AppendToString(buffer); mBottom.AppendToString(buffer); mLeft.AppendToString(buffer); - fputs(buffer, out); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out); } void nsCSSRect::List(FILE* out, PRInt32 aIndent, const nsCSSProperty aTRBL[]) const @@ -352,7 +352,7 @@ void nsCSSRect::List(FILE* out, PRInt32 aIndent, const nsCSSProperty aTRBL[]) co mLeft.AppendToString(buffer); } - fputs(buffer, out); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out); } // --- nsCSSDisplay ----------------- @@ -405,13 +405,13 @@ void nsCSSDisplay::List(FILE* out, PRInt32 aIndent) const mVisibility.AppendToString(buffer, eCSSProperty_visibility); mOpacity.AppendToString(buffer, eCSSProperty_opacity); - fputs(buffer, out); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out); if (nsnull != mClip) { mClip->List(out, eCSSProperty_clip); } buffer.SetLength(0); mOverflow.AppendToString(buffer, eCSSProperty_overflow); - fputs(buffer, out); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out); } // --- nsCSSMargin ----------------- @@ -520,7 +520,7 @@ void nsCSSMargin::List(FILE* out, PRInt32 aIndent) const mOutlineRadius->List(out, aIndent, trbl); } mFloatEdge.AppendToString(buffer, eCSSProperty_float_edge); - fputs(buffer, out); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out); } // --- nsCSSPosition ----------------- @@ -571,7 +571,7 @@ void nsCSSPosition::List(FILE* out, PRInt32 aIndent) const mMaxHeight.AppendToString(buffer, eCSSProperty_max_height); mBoxSizing.AppendToString(buffer, eCSSProperty_box_sizing); mZIndex.AppendToString(buffer, eCSSProperty_z_index); - fputs(buffer, out); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out); if (nsnull != mOffset) { static const nsCSSProperty trbl[] = { @@ -618,7 +618,7 @@ void nsCSSList::List(FILE* out, PRInt32 aIndent) const mType.AppendToString(buffer, eCSSProperty_list_style_type); mImage.AppendToString(buffer, eCSSProperty_list_style_image); mPosition.AppendToString(buffer, eCSSProperty_list_style_position); - fputs(buffer, out); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out); } // --- nsCSSTable ----------------- @@ -662,7 +662,7 @@ void nsCSSTable::List(FILE* out, PRInt32 aIndent) const mEmptyCells.AppendToString(buffer, eCSSProperty_empty_cells); mLayout.AppendToString(buffer, eCSSProperty_table_layout); - fputs(buffer, out); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out); } // --- nsCSSBreaks ----------------- @@ -706,7 +706,7 @@ void nsCSSBreaks::List(FILE* out, PRInt32 aIndent) const mPageBreakBefore.AppendToString(buffer, eCSSProperty_page_break_before); mPageBreakInside.AppendToString(buffer, eCSSProperty_page_break_inside); - fputs(buffer, out); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out); } // --- nsCSSPage ----------------- @@ -744,7 +744,7 @@ void nsCSSPage::List(FILE* out, PRInt32 aIndent) const mSizeWidth.AppendToString(buffer, eCSSProperty_size_width); mSizeHeight.AppendToString(buffer, eCSSProperty_size_height); - fputs(buffer, out); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out); } // --- nsCSSContent support ----------------- @@ -861,7 +861,7 @@ void nsCSSContent::List(FILE* out, PRInt32 aIndent) const quotes = quotes->mNext; } - fputs(buffer, out); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out); } // --- nsCSSUserInterface ----------------- @@ -921,7 +921,7 @@ void nsCSSUserInterface::List(FILE* out, PRInt32 aIndent) const cursor = cursor->mNext; } - fputs(buffer, out); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out); } // --- nsCSSAural ----------------- @@ -991,7 +991,7 @@ void nsCSSAural::List(FILE* out, PRInt32 aIndent) const mVoiceFamily.AppendToString(buffer, eCSSProperty_voice_family); mVolume.AppendToString(buffer, eCSSProperty_volume); - fputs(buffer, out); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out); } #ifdef INCLUDE_XUL @@ -1032,7 +1032,7 @@ void nsCSSXUL::List(FILE* out, PRInt32 aIndent) const mBoxOrient.AppendToString(buffer, eCSSProperty_box_orient); mBoxPack.AppendToString(buffer, eCSSProperty_box_pack); mBoxOrdinal.AppendToString(buffer, eCSSProperty_box_ordinal_group); - fputs(buffer, out); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out); } #endif // INCLUDE_XUL diff --git a/content/html/style/src/nsCSSStyleRule.cpp b/content/html/style/src/nsCSSStyleRule.cpp index 766633063900..0a612b384ea6 100644 --- a/content/html/style/src/nsCSSStyleRule.cpp +++ b/content/html/style/src/nsCSSStyleRule.cpp @@ -2275,7 +2275,7 @@ CSSStyleRuleImpl::List(FILE* out, PRInt32 aIndent) const buffer.AppendWithConversion(" weight: "); buffer.AppendInt(mWeight, 10); buffer.AppendWithConversion(" "); - fputs(buffer, out); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out); if (nsnull != mDeclaration) { mDeclaration->List(out); } diff --git a/content/html/style/src/nsCSSStyleSheet.cpp b/content/html/style/src/nsCSSStyleSheet.cpp index e8e42d133c5d..2daca219abd1 100644 --- a/content/html/style/src/nsCSSStyleSheet.cpp +++ b/content/html/style/src/nsCSSStyleSheet.cpp @@ -2464,7 +2464,7 @@ static PRBool ListCascade(nsHashKey* aKey, void* aValue, void* aClosure) fputs("\nRules in cascade order for medium: \"", data->mOut); nsAutoString buffer; key->mAtom->ToString(buffer); - fputs(buffer, data->mOut); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), data->mOut); fputs("\"\n", data->mOut); ListRules(cascade->mWeightedRules, data->mOut, data->mIndent); @@ -2503,7 +2503,7 @@ void CSSStyleSheetImpl::List(FILE* out, PRInt32 aIndent) const while (index < PRInt32(count)) { nsCOMPtr medium = dont_AddRef((nsIAtom*)mMedia->ElementAt(index++)); medium->ToString(buffer); - fputs(buffer, out); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out); if (index < PRInt32(count)) { fputs(", ", out); } diff --git a/content/html/style/src/nsHTMLAttributes.cpp b/content/html/style/src/nsHTMLAttributes.cpp index 8270b86889ad..84e1ff75a94b 100644 --- a/content/html/style/src/nsHTMLAttributes.cpp +++ b/content/html/style/src/nsHTMLAttributes.cpp @@ -765,7 +765,7 @@ nsHTMLMappedAttributes::List(FILE* out, PRInt32 aIndent) const PRInt32 index; for (index = aIndent; --index >= 0; ) fputs(" ", out); attr->ToString(buffer); - fputs(buffer, out); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out); fputs("\n", out); attr = attr->mNext; } @@ -1518,7 +1518,7 @@ HTMLAttributesImpl::List(FILE* out, PRInt32 aIndent) const buffer.AppendWithConversion(" = "); value.AppendToString(buffer); } - fputs(buffer, out); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out); } return NS_OK; } diff --git a/content/xml/content/src/nsXMLCDATASection.cpp b/content/xml/content/src/nsXMLCDATASection.cpp index d12523e63fa1..76ca1fa36182 100644 --- a/content/xml/content/src/nsXMLCDATASection.cpp +++ b/content/xml/content/src/nsXMLCDATASection.cpp @@ -221,7 +221,7 @@ nsXMLCDATASection::List(FILE* out, PRInt32 aIndent) const nsAutoString tmp; mInner.ToCString(tmp, 0, mInner.mText.GetLength()); - fputs(tmp, out); + fputs(NS_LossyConvertUCS2toASCII(tmp).get(), out); fputs(">\n", out); return NS_OK; diff --git a/content/xml/content/src/nsXMLEntity.cpp b/content/xml/content/src/nsXMLEntity.cpp index 17ad9a5ae1a9..4cf233dd2f93 100644 --- a/content/xml/content/src/nsXMLEntity.cpp +++ b/content/xml/content/src/nsXMLEntity.cpp @@ -227,7 +227,7 @@ nsXMLEntity::List(FILE* out, PRInt32 aIndent) const tmp.Append(mNotationName); } - fputs(tmp, out); + fputs(NS_LossyConvertUCS2toASCII(tmp).get(), out); fputs(">\n", out); return NS_OK; diff --git a/content/xml/content/src/nsXMLNotation.cpp b/content/xml/content/src/nsXMLNotation.cpp index 46bcac297e11..1505592fa417 100644 --- a/content/xml/content/src/nsXMLNotation.cpp +++ b/content/xml/content/src/nsXMLNotation.cpp @@ -208,7 +208,7 @@ nsXMLNotation::List(FILE* out, PRInt32 aIndent) const tmp.AppendWithConversion("\""); } - fputs(tmp, out); + fputs(NS_LossyConvertUCS2toASCII(tmp).get(), out); fputs(">\n", out); return NS_OK; diff --git a/content/xml/content/src/nsXMLProcessingInstruction.cpp b/content/xml/content/src/nsXMLProcessingInstruction.cpp index 41ec23f09cb9..f78ea6525d77 100644 --- a/content/xml/content/src/nsXMLProcessingInstruction.cpp +++ b/content/xml/content/src/nsXMLProcessingInstruction.cpp @@ -466,7 +466,7 @@ nsXMLProcessingInstruction::List(FILE* out, PRInt32 aIndent) const nsAutoString tmp; mInner.ToCString(tmp, 0, mInner.mText.GetLength()); tmp.Insert(mTarget.get(), 0); - fputs(tmp, out); + fputs(NS_LossyConvertUCS2toASCII(tmp).get(), out); fputs(">\n", out); return NS_OK; diff --git a/content/xul/content/src/nsXULElement.cpp b/content/xul/content/src/nsXULElement.cpp index 66a7c4cf1b55..2f9e9e0df8ce 100644 --- a/content/xul/content/src/nsXULElement.cpp +++ b/content/xul/content/src/nsXULElement.cpp @@ -3431,7 +3431,7 @@ nsXULElement::List(FILE* out, PRInt32 aIndent) const nsAutoString as; NodeInfo()->GetQualifiedName(as); - fputs(NS_ConvertUCS2toUTF8(as).get(), out); + fputs(NS_LossyConvertUCS2toASCII(as).get(), out); fprintf(out, "@%p", this); @@ -3454,15 +3454,15 @@ nsXULElement::List(FILE* out, PRInt32 aIndent) const if (prefix) { prefix->ToString(s); - fputs(NS_ConvertUCS2toUTF8(s).get(), out); + fputs(NS_LossyConvertUCS2toASCII(s).get(), out); fputs(":", out); } attr->ToString(s); - fputs(NS_ConvertUCS2toUTF8(s).get(), out); + fputs(NS_LossyConvertUCS2toASCII(s).get(), out); fputs("=", out); - fputs(NS_ConvertUCS2toUTF8(v).get(), out); + fputs(NS_LossyConvertUCS2toASCII(v).get(), out); } PRInt32 nchildren; diff --git a/editor/base/nsEditorShell.cpp b/editor/base/nsEditorShell.cpp index 64bf80615970..d82040ddca45 100644 --- a/editor/base/nsEditorShell.cpp +++ b/editor/base/nsEditorShell.cpp @@ -5325,9 +5325,8 @@ nsEditorShell::HandleMouseClickOnElement(nsIDOMElement *aElement, PRInt32 aClick nsAutoString TagName; aElement->GetTagName(TagName); TagName.ToLowerCase(); - char szTagName[64]; - TagName.ToCString(szTagName, 64); - printf("***** Element clicked on: %s, x=%d, y=%d\n", szTagName, x, y); + printf("***** Element clicked on: %s, x=%d, y=%d\n", + NS_LossyConvertUCS2toASCII(TagName).get(), x, y); #endif */ if (mDisplayMode == eDisplayModeAllTags) diff --git a/editor/base/nsEditorTxnLog.cpp b/editor/base/nsEditorTxnLog.cpp index a91645bbae48..cc58bca3537f 100644 --- a/editor/base/nsEditorTxnLog.cpp +++ b/editor/base/nsEditorTxnLog.cpp @@ -44,7 +44,6 @@ #define LOCK_LOG(doc) #define UNLOCK_LOG(doc) -#define MAX_BUF_LENGTH 256 static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); @@ -111,11 +110,9 @@ nsEditorTxnLog::WillDo(nsITransactionManager *aTxMgr, nsITransaction *aTransacti { LOCK_LOG(this); - char buf[MAX_BUF_LENGTH]; - PrintIndent(mIndentLevel++); Write("WillDo: "); - Write(GetString(aTransaction, buf, MAX_BUF_LENGTH)); + WriteTransaction(aTransaction); Write("\n"); Flush(); @@ -129,11 +126,9 @@ nsEditorTxnLog::DidDo(nsITransactionManager *aTxMgr, nsITransaction *aTransactio { LOCK_LOG(this); - char buf[MAX_BUF_LENGTH]; - PrintIndent(--mIndentLevel); Write("DidDo: "); - Write(GetString(aTransaction, buf, MAX_BUF_LENGTH)); + WriteTransaction(aTransaction); Write("("); WriteInt("%d", aDoResult); Write(")\n"); @@ -153,10 +148,8 @@ nsEditorTxnLog::WillUndo(nsITransactionManager *aTxMgr, nsITransaction *aTransac if (aTransaction) { - char buf[MAX_BUF_LENGTH]; - Write("WillUndo: "); - Write(GetString(aTransaction, buf, MAX_BUF_LENGTH)); + WriteTransaction(aTransaction); Write("\n"); } else @@ -178,10 +171,8 @@ nsEditorTxnLog::DidUndo(nsITransactionManager *aTxMgr, nsITransaction *aTransact if (aTransaction) { - char buf[MAX_BUF_LENGTH]; - Write("DidUndo: "); - Write(GetString(aTransaction, buf, MAX_BUF_LENGTH)); + WriteTransaction(aTransaction); Write("("); WriteInt("%d", aUndoResult); Write(")\n"); @@ -209,10 +200,8 @@ nsEditorTxnLog::WillRedo(nsITransactionManager *aTxMgr, nsITransaction *aTransac if (aTransaction) { - char buf[MAX_BUF_LENGTH]; - Write("WillRedo: "); - Write(GetString(aTransaction, buf, MAX_BUF_LENGTH)); + WriteTransaction(aTransaction); Write("\n"); } else @@ -234,10 +223,8 @@ nsEditorTxnLog::DidRedo(nsITransactionManager *aTxMgr, nsITransaction *aTransact if (aTransaction) { - char buf[MAX_BUF_LENGTH]; - Write("DidRedo: "); - Write(GetString(aTransaction, buf, MAX_BUF_LENGTH)); + WriteTransaction(aTransaction); Write(" ("); WriteInt("%d", aRedoResult); Write(")\n"); @@ -329,13 +316,11 @@ nsEditorTxnLog::WillMerge(nsITransactionManager *aTxMgr, nsITransaction *aTopTra { LOCK_LOG(this); - char buf[MAX_BUF_LENGTH]; - PrintIndent(mIndentLevel); Write("WillMerge: "); - Write(GetString(aTopTransaction, buf, MAX_BUF_LENGTH)); + WriteTransaction(aTopTransaction); Write(" <-- "); - Write(GetString(aTransaction, buf, MAX_BUF_LENGTH)); + WriteTransaction(aTransaction); Write("\n"); Flush(); @@ -349,13 +334,11 @@ nsEditorTxnLog::DidMerge(nsITransactionManager *aTxMgr, nsITransaction *aTopTran { LOCK_LOG(this); - char buf[MAX_BUF_LENGTH]; - PrintIndent(mIndentLevel); Write("DidMerge: "); - Write(GetString(aTopTransaction, buf, MAX_BUF_LENGTH)); + WriteTransaction(aTopTransaction); Write(" <-- "); - Write(GetString(aTransaction, buf, MAX_BUF_LENGTH)); + WriteTransaction(aTransaction); Write(" ("); Write(aDidMerge ? "TRUE" : "FALSE"); Write(", "); @@ -368,30 +351,19 @@ nsEditorTxnLog::DidMerge(nsITransactionManager *aTxMgr, nsITransaction *aTopTran return NS_OK; } -const char * -nsEditorTxnLog::GetString(nsITransaction *aTransaction, char *aBuffer, PRInt32 aBufferLength) +nsresult +nsEditorTxnLog::WriteTransaction(nsITransaction *aTransaction) { - if (!aBuffer || aBufferLength < 1) - return 0; - - aBuffer[0] = '\0'; - nsString str; nsCOMPtr txn = do_QueryInterface(aTransaction); + if (txn) { + txn->GetTxnDescription(str); + if (str.IsEmpty()) + str.Assign(NS_LITERAL_STRING("")); + } - if (!txn) - return aBuffer; - - txn->GetTxnDescription(str); - - if (str.Length() == 0) - str.AssignWithConversion(""); - - str.ToCString(aBuffer, aBufferLength); - aBuffer[aBufferLength - 1] = '\0'; - - return aBuffer; + return Write(NS_LossyConvertUCS2toASCII(str).get()); } nsresult diff --git a/editor/base/nsEditorTxnLog.h b/editor/base/nsEditorTxnLog.h index 5ac846d56b17..7d41a5dd0d5f 100644 --- a/editor/base/nsEditorTxnLog.h +++ b/editor/base/nsEditorTxnLog.h @@ -87,10 +87,10 @@ public: private: /* nsEditorTxnLog private methods. */ - const char *GetString(nsITransaction *aTransaction, char *aBuffer, PRInt32 aBufLength); nsresult PrintIndent(PRInt32 aIndentLevel); nsresult Write(const char *aBuffer); nsresult WriteInt(const char *aFormat, PRInt32 aInt); + nsresult WriteTransaction(nsITransaction *aTransaction); nsresult Flush(); }; diff --git a/editor/composer/src/nsEditorShell.cpp b/editor/composer/src/nsEditorShell.cpp index 64bf80615970..d82040ddca45 100644 --- a/editor/composer/src/nsEditorShell.cpp +++ b/editor/composer/src/nsEditorShell.cpp @@ -5325,9 +5325,8 @@ nsEditorShell::HandleMouseClickOnElement(nsIDOMElement *aElement, PRInt32 aClick nsAutoString TagName; aElement->GetTagName(TagName); TagName.ToLowerCase(); - char szTagName[64]; - TagName.ToCString(szTagName, 64); - printf("***** Element clicked on: %s, x=%d, y=%d\n", szTagName, x, y); + printf("***** Element clicked on: %s, x=%d, y=%d\n", + NS_LossyConvertUCS2toASCII(TagName).get(), x, y); #endif */ if (mDisplayMode == eDisplayModeAllTags) diff --git a/editor/libeditor/html/nsEditorTxnLog.cpp b/editor/libeditor/html/nsEditorTxnLog.cpp index a91645bbae48..cc58bca3537f 100644 --- a/editor/libeditor/html/nsEditorTxnLog.cpp +++ b/editor/libeditor/html/nsEditorTxnLog.cpp @@ -44,7 +44,6 @@ #define LOCK_LOG(doc) #define UNLOCK_LOG(doc) -#define MAX_BUF_LENGTH 256 static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); @@ -111,11 +110,9 @@ nsEditorTxnLog::WillDo(nsITransactionManager *aTxMgr, nsITransaction *aTransacti { LOCK_LOG(this); - char buf[MAX_BUF_LENGTH]; - PrintIndent(mIndentLevel++); Write("WillDo: "); - Write(GetString(aTransaction, buf, MAX_BUF_LENGTH)); + WriteTransaction(aTransaction); Write("\n"); Flush(); @@ -129,11 +126,9 @@ nsEditorTxnLog::DidDo(nsITransactionManager *aTxMgr, nsITransaction *aTransactio { LOCK_LOG(this); - char buf[MAX_BUF_LENGTH]; - PrintIndent(--mIndentLevel); Write("DidDo: "); - Write(GetString(aTransaction, buf, MAX_BUF_LENGTH)); + WriteTransaction(aTransaction); Write("("); WriteInt("%d", aDoResult); Write(")\n"); @@ -153,10 +148,8 @@ nsEditorTxnLog::WillUndo(nsITransactionManager *aTxMgr, nsITransaction *aTransac if (aTransaction) { - char buf[MAX_BUF_LENGTH]; - Write("WillUndo: "); - Write(GetString(aTransaction, buf, MAX_BUF_LENGTH)); + WriteTransaction(aTransaction); Write("\n"); } else @@ -178,10 +171,8 @@ nsEditorTxnLog::DidUndo(nsITransactionManager *aTxMgr, nsITransaction *aTransact if (aTransaction) { - char buf[MAX_BUF_LENGTH]; - Write("DidUndo: "); - Write(GetString(aTransaction, buf, MAX_BUF_LENGTH)); + WriteTransaction(aTransaction); Write("("); WriteInt("%d", aUndoResult); Write(")\n"); @@ -209,10 +200,8 @@ nsEditorTxnLog::WillRedo(nsITransactionManager *aTxMgr, nsITransaction *aTransac if (aTransaction) { - char buf[MAX_BUF_LENGTH]; - Write("WillRedo: "); - Write(GetString(aTransaction, buf, MAX_BUF_LENGTH)); + WriteTransaction(aTransaction); Write("\n"); } else @@ -234,10 +223,8 @@ nsEditorTxnLog::DidRedo(nsITransactionManager *aTxMgr, nsITransaction *aTransact if (aTransaction) { - char buf[MAX_BUF_LENGTH]; - Write("DidRedo: "); - Write(GetString(aTransaction, buf, MAX_BUF_LENGTH)); + WriteTransaction(aTransaction); Write(" ("); WriteInt("%d", aRedoResult); Write(")\n"); @@ -329,13 +316,11 @@ nsEditorTxnLog::WillMerge(nsITransactionManager *aTxMgr, nsITransaction *aTopTra { LOCK_LOG(this); - char buf[MAX_BUF_LENGTH]; - PrintIndent(mIndentLevel); Write("WillMerge: "); - Write(GetString(aTopTransaction, buf, MAX_BUF_LENGTH)); + WriteTransaction(aTopTransaction); Write(" <-- "); - Write(GetString(aTransaction, buf, MAX_BUF_LENGTH)); + WriteTransaction(aTransaction); Write("\n"); Flush(); @@ -349,13 +334,11 @@ nsEditorTxnLog::DidMerge(nsITransactionManager *aTxMgr, nsITransaction *aTopTran { LOCK_LOG(this); - char buf[MAX_BUF_LENGTH]; - PrintIndent(mIndentLevel); Write("DidMerge: "); - Write(GetString(aTopTransaction, buf, MAX_BUF_LENGTH)); + WriteTransaction(aTopTransaction); Write(" <-- "); - Write(GetString(aTransaction, buf, MAX_BUF_LENGTH)); + WriteTransaction(aTransaction); Write(" ("); Write(aDidMerge ? "TRUE" : "FALSE"); Write(", "); @@ -368,30 +351,19 @@ nsEditorTxnLog::DidMerge(nsITransactionManager *aTxMgr, nsITransaction *aTopTran return NS_OK; } -const char * -nsEditorTxnLog::GetString(nsITransaction *aTransaction, char *aBuffer, PRInt32 aBufferLength) +nsresult +nsEditorTxnLog::WriteTransaction(nsITransaction *aTransaction) { - if (!aBuffer || aBufferLength < 1) - return 0; - - aBuffer[0] = '\0'; - nsString str; nsCOMPtr txn = do_QueryInterface(aTransaction); + if (txn) { + txn->GetTxnDescription(str); + if (str.IsEmpty()) + str.Assign(NS_LITERAL_STRING("")); + } - if (!txn) - return aBuffer; - - txn->GetTxnDescription(str); - - if (str.Length() == 0) - str.AssignWithConversion(""); - - str.ToCString(aBuffer, aBufferLength); - aBuffer[aBufferLength - 1] = '\0'; - - return aBuffer; + return Write(NS_LossyConvertUCS2toASCII(str).get()); } nsresult diff --git a/editor/libeditor/html/nsEditorTxnLog.h b/editor/libeditor/html/nsEditorTxnLog.h index 5ac846d56b17..7d41a5dd0d5f 100644 --- a/editor/libeditor/html/nsEditorTxnLog.h +++ b/editor/libeditor/html/nsEditorTxnLog.h @@ -87,10 +87,10 @@ public: private: /* nsEditorTxnLog private methods. */ - const char *GetString(nsITransaction *aTransaction, char *aBuffer, PRInt32 aBufLength); nsresult PrintIndent(PRInt32 aIndentLevel); nsresult Write(const char *aBuffer); nsresult WriteInt(const char *aFormat, PRInt32 aInt); + nsresult WriteTransaction(nsITransaction *aTransaction); nsresult Flush(); }; diff --git a/editor/libeditor/txtsvc/nsTextServicesDocument.cpp b/editor/libeditor/txtsvc/nsTextServicesDocument.cpp index 6fed200e9cc1..11806e3a7c2c 100644 --- a/editor/libeditor/txtsvc/nsTextServicesDocument.cpp +++ b/editor/libeditor/txtsvc/nsTextServicesDocument.cpp @@ -4477,15 +4477,12 @@ void nsTextServicesDocument::PrintContentNode(nsIContent *aContent) { nsString tmpStr, str; - char tmpBuf[256]; - nsIAtom *atom = 0; + nsCOMPtr atom; nsresult result; - aContent->GetTag(atom); + aContent->GetTag(*getter_AddRefs(atom)); atom->ToString(tmpStr); - tmpStr.ToCString(tmpBuf, 256); - - printf("%s", tmpBuf); + printf("%s", NS_LossyConvertUCS2toASCII(tmpStr).get()); nsCOMPtr node = do_QueryInterface(aContent); @@ -4505,8 +4502,7 @@ nsTextServicesDocument::PrintContentNode(nsIContent *aContent) if (NS_FAILED(result)) return; - str.ToCString(tmpBuf, 256); - printf(": \"%s\"", tmpBuf); + printf(": \"%s\"", NS_LossyConvertUCS2toASCII(str).get()); } } diff --git a/editor/txtsvc/src/nsTextServicesDocument.cpp b/editor/txtsvc/src/nsTextServicesDocument.cpp index 6fed200e9cc1..11806e3a7c2c 100644 --- a/editor/txtsvc/src/nsTextServicesDocument.cpp +++ b/editor/txtsvc/src/nsTextServicesDocument.cpp @@ -4477,15 +4477,12 @@ void nsTextServicesDocument::PrintContentNode(nsIContent *aContent) { nsString tmpStr, str; - char tmpBuf[256]; - nsIAtom *atom = 0; + nsCOMPtr atom; nsresult result; - aContent->GetTag(atom); + aContent->GetTag(*getter_AddRefs(atom)); atom->ToString(tmpStr); - tmpStr.ToCString(tmpBuf, 256); - - printf("%s", tmpBuf); + printf("%s", NS_LossyConvertUCS2toASCII(tmpStr).get()); nsCOMPtr node = do_QueryInterface(aContent); @@ -4505,8 +4502,7 @@ nsTextServicesDocument::PrintContentNode(nsIContent *aContent) if (NS_FAILED(result)) return; - str.ToCString(tmpBuf, 256); - printf(": \"%s\"", tmpBuf); + printf(": \"%s\"", NS_LossyConvertUCS2toASCII(str).get()); } } diff --git a/extensions/xmlterm/base/mozXMLTermStream.cpp b/extensions/xmlterm/base/mozXMLTermStream.cpp index ef2f249203e2..5e6f588b508f 100644 --- a/extensions/xmlterm/base/mozXMLTermStream.cpp +++ b/extensions/xmlterm/base/mozXMLTermStream.cpp @@ -27,6 +27,7 @@ #include "nsCOMPtr.h" #include "nsString.h" #include "nsReadableUtils.h" +#include "plstr.h" #include "nsMemory.h" @@ -494,7 +495,7 @@ NS_IMETHODIMP mozXMLTermStream::Read(char* buf, PRUint32 count, } // Copy portion of string - mUTF8Buffer.ToCString(buf, *_retval, mUTF8Offset); + PL_strncpyz(buf, mUTF8Buffer.get() + mUTF8Offset, *_retval); mUTF8Offset += *_retval; diff --git a/gfx/src/gtk/nsFontMetricsGTK.cpp b/gfx/src/gtk/nsFontMetricsGTK.cpp index 6d7fdeca7520..cf845c5d53e4 100644 --- a/gfx/src/gtk/nsFontMetricsGTK.cpp +++ b/gfx/src/gtk/nsFontMetricsGTK.cpp @@ -1016,7 +1016,7 @@ FontEnumCallback(const nsString& aFamily, PRBool aGeneric, void *aData) { #ifdef REALLY_NOISY_FONTS printf("font = '"); - fputs(aFamily, stdout); + fputs(NS_LossyConvertUCS2toASCII(aFamily).get(), stdout); printf("'\n"); #endif @@ -1788,9 +1788,8 @@ DumpFamily(nsFontFamily* aFamily) static PRIntn DumpFamilyEnum(PLHashEntry* he, PRIntn i, void* arg) { - char buf[256]; - ((nsString*) he->key)->ToCString(buf, sizeof(buf)); - printf("family: %s\n", buf); + printf("family: %s\n", + NS_LossyConvertUCS2toASCII(*NS_STATIC_CAST(nsString*,he->key))); nsFontFamily* family = (nsFontFamily*) he->value; DumpFamily(family); diff --git a/gfx/src/nsColor.cpp b/gfx/src/nsColor.cpp index d4a214bf2d80..8a615d652d5a 100644 --- a/gfx/src/nsColor.cpp +++ b/gfx/src/nsColor.cpp @@ -66,10 +66,11 @@ static int ComponentValue(const char* aColorSpec, int aLen, int color, int dpc) extern "C" NS_GFX_(PRBool) NS_HexToRGB(const nsString& aColorSpec, nscolor* aResult) { - char buffer[10]; - aColorSpec.ToCString(buffer, sizeof(buffer)); + // XXXldb nsStackString<10> + NS_LossyConvertUCS2toASCII bufferStr(aColorSpec); + const char* buffer = bufferStr.get(); - int nameLen = PL_strlen(buffer); + int nameLen = bufferStr.Length(); if ((nameLen == 3) || (nameLen == 6)) { // Make sure the digits are legal for (int i = 0; i < nameLen; i++) { @@ -113,15 +114,16 @@ extern "C" NS_GFX_(PRBool) NS_HexToRGB(const nsString& aColorSpec, nscolor* aRes // compatible with legacy Nav behavior extern "C" NS_GFX_(PRBool) NS_LooseHexToRGB(const nsString& aColorSpec, nscolor* aResult) { - char buffer[30]; - char* colorSpec = &(buffer[0]); - aColorSpec.ToCString(buffer, sizeof(buffer)); + // XXXldb nsStackString<30> + NS_LossyConvertUCS2toASCII buffer(aColorSpec); - if ('#' == buffer[0]) { - colorSpec++; + int nameLen = buffer.Length(); + const char* colorSpec = buffer.get(); + if ('#' == colorSpec[0]) { + ++colorSpec; + --nameLen; } - int nameLen = PL_strlen(colorSpec); if (3 < nameLen) { // Convert the ascii to binary int dpc = (nameLen / 3) + (((nameLen % 3) != 0) ? 1 : 0); diff --git a/gfx/src/nsRect.cpp b/gfx/src/nsRect.cpp index f43ab2b6f265..12be0d08794e 100644 --- a/gfx/src/nsRect.cpp +++ b/gfx/src/nsRect.cpp @@ -220,6 +220,6 @@ FILE* operator<<(FILE* out, const nsRect& rect) tmp.AppendWithConversion(", "); tmp.AppendFloat(NSTwipsToFloatPoints(rect.height)); tmp.AppendWithConversion("}"); - fputs(tmp, out); + fputs(NS_LossyConvertUCS2toASCII(tmp).get(), out); return out; } diff --git a/gfx/src/os2/nsFontMetricsOS2.cpp b/gfx/src/os2/nsFontMetricsOS2.cpp index 285ce62438f1..b5a89eff8763 100644 --- a/gfx/src/os2/nsFontMetricsOS2.cpp +++ b/gfx/src/os2/nsFontMetricsOS2.cpp @@ -640,39 +640,33 @@ nsFontMetricsOS2::FindGenericFont(HDC aPS, BOOL bBold, BOOL bItalic) if (mTriedAllGenerics) { return nsnull; } - nsAutoString prefix; - prefix.AssignWithConversion("font.name."); - prefix.Append(*mGeneric); - char name[128]; + nsCAutoString prefix(NS_LITERAL_CSTRING("font.name.") + + NS_LossyConvertUCS2toASCII(*mGeneric)); if (mLangGroup) { - nsAutoString pref = prefix; - pref.AppendWithConversion('.'); + nsCAutoString pref(prefix + NS_LITERAL_CSTRING(".")); const PRUnichar* langGroup = nsnull; mLangGroup->GetUnicode(&langGroup); - pref.Append(langGroup); - pref.ToCString(name, sizeof(name)); + pref.Append(NS_LossyConvertUCS2toASCII(langGroup)); char* value = nsnull; - gPref->CopyCharPref(name, &value); + gPref->CopyCharPref(pref.get(), &value); FATTRS* font = LoadGenericFont(aPS, bBold, bItalic, &value); if (font) { return font; } - gPref->CopyDefaultCharPref(name, &value); + gPref->CopyDefaultCharPref(pref.get(), &value); font = LoadGenericFont(aPS, bBold, bItalic, &value); if (font) { return font; } } - prefix.ToCString(name, sizeof(name)); PrefEnumInfo info = { nsnull, aPS, nsnull, this }; - gPref->EnumerateChildren(name, PrefEnumCallback, &info); + gPref->EnumerateChildren(prefix.get(), PrefEnumCallback, &info); if (info.mFont) { return info.mFont; } #if 0 - prefix.ToCString(name, sizeof(name)); PrefEnumInfo info = { aChar, aPS, nsnull, this }; - gPref->EnumerateChildren(name, PrefEnumCallback, &info); + gPref->EnumerateChildren(prefix.get(), PrefEnumCallback, &info); if (info.mFont) { return info.mFont; } @@ -912,11 +906,9 @@ nsresult nsFontMetricsOS2::RealizeFont() // 6) Encoding // There doesn't seem to be any encoding stuff yet, so guess. // (XXX unicode hack; use same codepage as converter!) - char name[128]; const PRUnichar* langGroup = nsnull; mLangGroup->GetUnicode(&langGroup); - nsAutoString langName(langGroup); - langName.ToCString(name, sizeof(name)); + nsCAutoString name(NS_LossyConvertUCS2toASCII(langGroup).get()); for (int j=0; j < eCharSet_COUNT; j++ ) { if (name[0] == gCharSetInfo[j].mLangGroup[0]) diff --git a/gfx/src/qt/nsFontMetricsQT.cpp b/gfx/src/qt/nsFontMetricsQT.cpp index e855eae15269..53238e082cae 100644 --- a/gfx/src/qt/nsFontMetricsQT.cpp +++ b/gfx/src/qt/nsFontMetricsQT.cpp @@ -717,7 +717,7 @@ FontEnumCallback(const nsString &aFamily,PRBool aGeneric,void *aData) #ifdef REALLY_NOISY_FONTS #ifdef DEBUG printf("font = '"); - fputs(aFamily, stdout); + fputs(NS_LossyConvertUCS2toASCII(aFamily).get(), stdout); printf("'\n"); #endif #endif diff --git a/gfx/src/xlib/nsFontMetricsXlib.cpp b/gfx/src/xlib/nsFontMetricsXlib.cpp index 4c4d75174b6d..5f1e750a413c 100644 --- a/gfx/src/xlib/nsFontMetricsXlib.cpp +++ b/gfx/src/xlib/nsFontMetricsXlib.cpp @@ -1789,9 +1789,9 @@ DumpFamily(nsFontFamilyXlib* aFamily) static PRIntn DumpFamilyEnum(PLHashEntry* he, PRIntn i, void* arg) { - char buf[256]; - ((nsString*) he->key)->ToCString(buf, sizeof(buf)); - PR_LOG(FontMetricsXlibLM, PR_LOG_DEBUG, ("family: %s\n", buf)); + PR_LOG(FontMetricsXlibLM, PR_LOG_DEBUG, + ("family: %s\n", + NS_LossyConvertUCS2toASCII(*NS_STATIC_CAST(nsString*,he->key)))); nsFontFamilyXlib* family = (nsFontFamilyXlib*) he->value; DumpFamily(family); diff --git a/gfx/tests/DumpColors.cpp b/gfx/tests/DumpColors.cpp index c4e3585da876..332710302e4d 100644 --- a/gfx/tests/DumpColors.cpp +++ b/gfx/tests/DumpColors.cpp @@ -43,11 +43,10 @@ int main(int argc, char** argv) { - char buffer[1024]; for (int i = 0; i < eColorName_COUNT; i++) { nscolor rgba = nsColorNames::kColors[i]; - nsColorNames::GetStringValue(nsColorName(i)).ToCString(buffer, sizeof(buffer)); - printf("%s: NS_RGB(%d,%d,%d,%d)\n", buffer, + printf("%s: NS_RGB(%d,%d,%d,%d)\n", + nsColorNames::GetStringValue(nsColorName(i)).get(), NS_GET_R(rgba), NS_GET_G(rgba), NS_GET_B(rgba), NS_GET_A(rgba)); } return 0; diff --git a/gfx/tests/TestColorNames.cpp b/gfx/tests/TestColorNames.cpp index 106b2e956694..85975220ae96 100644 --- a/gfx/tests/TestColorNames.cpp +++ b/gfx/tests/TestColorNames.cpp @@ -66,41 +66,40 @@ int main(int argc, char** argv) index = eColorName_UNKNOWN; while (PRInt32(index) < (PRInt32 (eColorName_COUNT) - 1)) { // Lookup color by name and make sure it has the right id - char tagName[512]; index = nsColorName(PRInt32(index) + 1); - nsColorNames::GetStringValue(index).ToCString(tagName, sizeof(tagName)); + nsCString tagName(nsColorNames::GetStringValue(index)); id = nsColorNames::LookupName(NS_ConvertASCIItoUCS2(tagName)); if (id == eColorName_UNKNOWN) { - printf("bug: can't find '%s'\n", tagName); + printf("bug: can't find '%s'\n", tagName.get()); rv = -1; } if (id != index) { - printf("bug: name='%s' id=%d index=%d\n", tagName, id, index); + printf("bug: name='%s' id=%d index=%d\n", tagName.get(), id, index); rv = -1; } // fiddle with the case to make sure we can still find it - tagName[0] = tagName[0] - 32; + tagName.SetCharAt(tagName.CharAt(0) - 32, 0); id = nsColorNames::LookupName(NS_ConvertASCIItoUCS2(tagName)); if (id == eColorName_UNKNOWN) { - printf("bug: can't find '%s'\n", tagName); + printf("bug: can't find '%s'\n", tagName.get()); rv = -1; } if (id != index) { - printf("bug: name='%s' id=%d index=%d\n", tagName, id, index); + printf("bug: name='%s' id=%d index=%d\n", tagName.get(), id, index); rv = -1; } // Check that color lookup by name gets the right rgb value nscolor rgb; if (!NS_ColorNameToRGB(NS_ConvertASCIItoUCS2(tagName), &rgb)) { - printf("bug: name='%s' didn't NS_ColorNameToRGB\n", tagName); + printf("bug: name='%s' didn't NS_ColorNameToRGB\n", tagName.get()); rv = -1; } if (nsColorNames::kColors[index] != rgb) { printf("bug: name='%s' ColorNameToRGB=%x kColors[%d]=%x\n", - tagName, rgb, nsColorNames::kColors[index], + tagName.get(), rgb, nsColorNames::kColors[index], nsColorNames::kColors[index]); rv = -1; } diff --git a/htmlparser/robot/nsDebugRobot.cpp b/htmlparser/robot/nsDebugRobot.cpp index 43b3ab9ef424..7a6222ad0441 100644 --- a/htmlparser/robot/nsDebugRobot.cpp +++ b/htmlparser/robot/nsDebugRobot.cpp @@ -117,7 +117,7 @@ NS_IMETHODIMP RobotSinkObserver::ProcessLink(const nsString& aURLSpec) nsString * pstr = (nsString *)g_duplicateList->ElementAt(n); if (pstr->Equals(aURLSpec)) { fputs ("Robot: (duplicate '",stdout); - fputs (aURLSpec,stdout); + fputs (NS_LossyConvertUCS2toASCII(aURLSpec).get(),stdout); fputs ("')\n",stdout); return NS_OK; } @@ -134,7 +134,7 @@ NS_IMETHODIMP RobotSinkObserver::ProcessLink(const nsString& aURLSpec) } else { fputs ("Robot: (cannot process URL types '",stdout); - fputs (aURLSpec,stdout); + fputs (NS_LossyConvertUCS2toASCII(aURLSpec).get(),stdout); fputs ("')\n",stdout); } } @@ -273,7 +273,7 @@ extern "C" NS_EXPORT int DebugRobot( NS_RELEASE(uri); if (NS_OK != rv) { printf("invalid URL: '"); - fputs(*urlName, stdout); + fputs(NS_LossyConvertUCS2toASCII(*urlName).get(), stdout); printf("'\n"); NS_RELEASE(myObserver); return -1; @@ -284,7 +284,7 @@ extern "C" NS_EXPORT int DebugRobot( fputs ("Robot: parsing(",stdout); fputs (str_num,stdout); fputs (") ",stdout); - fputs (*urlName,stdout); + fputs (NS_LossyConvertUCS2toASCII(*urlName).get(),stdout); fputs ("...",stdout); delete urlName; diff --git a/htmlparser/src/nsHTMLTokens.cpp b/htmlparser/src/nsHTMLTokens.cpp index 4982ac32cd80..afc822a6dbaf 100644 --- a/htmlparser/src/nsHTMLTokens.cpp +++ b/htmlparser/src/nsHTMLTokens.cpp @@ -256,9 +256,7 @@ nsresult CStartToken::Consume(PRUnichar aChar, nsScanner& aScanner,PRInt32 aFlag * @return */ void CStartToken::DebugDumpSource(nsOutputStream& out) { - char buffer[1000]; - mTextValue.ToCString(buffer,sizeof(buffer)); - out << "<" << buffer; + out << "<" << NS_LossyConvertUCS2toASCII(mTextValue).get(); if(!mAttributed) out << ">"; } @@ -445,9 +443,7 @@ PRInt32 CEndToken::GetTokenType(void) { * @return */ void CEndToken::DebugDumpSource(nsOutputStream& out) { - char buffer[1000]; - mTextValue.ToCString(buffer,sizeof(buffer)); - out << ""; + out << ""; } const nsAReadableString& CEndToken::GetStringValue() @@ -1444,12 +1440,10 @@ void CAttributeToken::SanitizeKey() { * @return */ void CAttributeToken::DebugDumpToken(nsOutputStream& out) { - char buffer[200]; - nsCAutoString str; - CopyUCS2toASCII(mTextKey, str); - out << "[" << GetClassName() << "] " << str.get() << "="; - mTextValue.ToCString(buffer,sizeof(buffer)); - out << buffer << ": " << mTypeID << nsEndl; + out << "[" << GetClassName() << "] " + << NS_LossyConvertUCS2toASCII(mTextKey).get() << "=" + << NS_LossyConvertUCS2toASCII(mTextValue).get() << ": " << mTypeID + << nsEndl; } const nsAReadableString& CAttributeToken::GetStringValue(void) @@ -1782,16 +1776,12 @@ nsresult CAttributeToken::Consume(PRUnichar aChar, nsScanner& aScanner,PRInt32 a * @return */ void CAttributeToken::DebugDumpSource(nsOutputStream& out) { - static char buffer[1000]; - nsCAutoString str; - CopyUCS2toASCII(mTextKey, str); - out << " " << str.get(); - if(mTextValue.Length()){ - mTextValue.ToCString(buffer,sizeof(buffer)); - out << "=" << buffer; + out << " " << NS_LossyConvertUCS2toASCII(mTextKey).get(); + if (!mTextValue.IsEmpty()) { + out << "=" << NS_LossyConvertUCS2toASCII(mTextValue).get(); } if(mLastAttribute) - out<<">"; + out << ">"; } void CAttributeToken::SetKey(const nsAReadableString& aKey) diff --git a/intl/locale/src/unix/nsCollationUnix.cpp b/intl/locale/src/unix/nsCollationUnix.cpp index b7d1b54aea8b..f458e64ad9c2 100644 --- a/intl/locale/src/unix/nsCollationUnix.cpp +++ b/intl/locale/src/unix/nsCollationUnix.cpp @@ -55,16 +55,16 @@ inline void nsCollationUnix::DoSetLocale() char *locale = setlocale(LC_COLLATE, NULL); mSavedLocale.AssignWithConversion(locale ? locale : ""); if (!mSavedLocale.EqualsIgnoreCase(mLocale)) { - char newLocale[MAX_LOCALE_LEN+1]; - (void) setlocale(LC_COLLATE, mLocale.ToCString(newLocale, sizeof(newLocale))); + (void) setlocale(LC_COLLATE, + NS_LossyConvertUCS2toASCII(Substring(mLocale,0,MAX_LOCALE_LEN)).get()); } } inline void nsCollationUnix::DoRestoreLocale() { if (!mSavedLocale.EqualsIgnoreCase(mLocale)) { - char oldLocale[MAX_LOCALE_LEN+1]; - (void) setlocale(LC_COLLATE, mSavedLocale.ToCString(oldLocale, sizeof(oldLocale))); + (void) setlocale(LC_COLLATE, + NS_LossyConvertUCS2toASCII(Substring(mSavedLocale,0,MAX_LOCALE_LEN)).get()); } } diff --git a/intl/locale/tests/LocaleSelfTest.cpp b/intl/locale/tests/LocaleSelfTest.cpp index 89b21d92a6de..61778a545313 100644 --- a/intl/locale/tests/LocaleSelfTest.cpp +++ b/intl/locale/tests/LocaleSelfTest.cpp @@ -376,22 +376,23 @@ static void TestSortPrint1(nsString *string_array, int len) static void TestSortPrintToFile(nsString *string_array, int len) { - char cstr[512]; for (int i = 0; i < len; i++) { #ifdef WIN32 - int len = WideCharToMultiByte(GetACP(), 0, - (LPCWSTR ) string_array[i].get(), string_array[i].Length(), - cstr, 512, NULL, NULL); - cstr[len] = '\0'; -#else - string_array[i].ToCString(cstr, 512); -#endif + char cstr[512]; + int len = WideCharToMultiByte(GetACP(), 0, + (LPCWSTR ) string_array[i].get(), string_array[i].Length(), + cstr, 512, NULL, NULL); + cstr[len] = '\0'; fprintf(g_outfp, "%s\n", cstr); +#else + fprintf(g_outfp, "%s\n", + NS_LossyConvertUCS2ToASCII(string_array[i]).get()); +#endif } fprintf(g_outfp, "\n"); } -static void DebugPrintCompResult(nsString string1, nsString string2, int result) +static void DebugPrintCompResult(const nsString& string1, const nsString& string2, int result) { #ifdef WIN32 char s[512]; @@ -420,12 +421,8 @@ static void DebugPrintCompResult(nsString string1, nsString string2, int result) printf(" %s\n", s); #else // Warning: casting to char* - char *cstr = ToNewCString(string1); - - if (cstr) { - cout << cstr << ' '; - delete [] cstr; - } + cout << NS_LossyConvertUCS2toASCII(string1).get() << ' '; + switch ((int)result) { case 0: cout << "=="; @@ -437,11 +434,7 @@ static void DebugPrintCompResult(nsString string1, nsString string2, int result) cout << '<'; break; } - cstr = ToNewCString(string2); - if (cstr) { - cout << ' ' << cstr << '\n'; - delete [] cstr; - } + cout << ' ' << NS_LossyConvertUCS2toASCII(string2).get() << '\n'; #endif } @@ -906,7 +899,6 @@ static void Test_nsLocale() nsString localeName; nsIWin32Locale* win32Locale; LCID lcid; - char cstr[32]; nsresult res; if (NS_SUCCEEDED(res = nsComponentManager::CreateInstance( @@ -915,27 +907,27 @@ static void Test_nsLocale() localeName.SetString("en-US"); res = win32Locale->GetPlatformLocale(&localeName, &lcid); printf("LCID for en-US is 1033\n"); - printf("result: locale = %s LCID = 0x%0.4x %d\n", localeName.ToCString(cstr, 32), lcid, lcid); + printf("result: locale = %s LCID = 0x%0.4x %d\n", NS_LossyConvertUCS2toASCII(localeName).get(), lcid, lcid); localeName.SetString("en-GB"); res = win32Locale->GetPlatformLocale(&localeName, &lcid); printf("LCID for en-GB is 2057\n"); - printf("result: locale = %s LCID = 0x%0.4x %d\n", localeName.ToCString(cstr, 32), lcid, lcid); + printf("result: locale = %s LCID = 0x%0.4x %d\n", NS_LossyConvertUCS2toASCII(localeName).get(), lcid, lcid); localeName.SetString("fr-FR"); res = win32Locale->GetPlatformLocale(&localeName, &lcid); printf("LCID for fr-FR is 1036\n"); - printf("result: locale = %s LCID = 0x%0.4x %d\n", localeName.ToCString(cstr, 32), lcid, lcid); + printf("result: locale = %s LCID = 0x%0.4x %d\n", NS_LossyConvertUCS2toASCII(localeName).get(), lcid, lcid); localeName.SetString("de-DE"); res = win32Locale->GetPlatformLocale(&localeName, &lcid); printf("LCID for de-DE is 1031\n"); - printf("result: locale = %s LCID = 0x%0.4x %d\n", localeName.ToCString(cstr, 32), lcid, lcid); + printf("result: locale = %s LCID = 0x%0.4x %d\n", NS_LossyConvertUCS2toASCII(localeName).get(), lcid, lcid); localeName.SetString("ja-JP"); res = win32Locale->GetPlatformLocale(&localeName, &lcid); printf("LCID for ja-JP is 1041\n"); - printf("result: locale = %s LCID = 0x%0.4x %d\n", localeName.ToCString(cstr, 32), lcid, lcid); + printf("result: locale = %s LCID = 0x%0.4x %d\n", NS_LossyConvertUCS2toASCII(localeName).get(), lcid, lcid); win32Locale->Release(); } @@ -944,30 +936,29 @@ static void Test_nsLocale() char locale[32]; size_t length = 32; nsIPosixLocale* posixLocale; - char cstr[32]; nsresult res; if (NS_SUCCEEDED(res = nsComponentManager::CreateInstance( kPosixLocaleFactoryCID, NULL, kIPosixLocaleIID, (void**)&posixLocale))) { localeName.SetString("en-US"); res = posixLocale->GetPlatformLocale(&localeName, locale, length); - printf("result: locale = %s POSIX = %s\n", localeName.ToCString(cstr, 32), locale); + printf("result: locale = %s POSIX = %s\n", NS_LossyConvertUCS2toASCII(localeName).get(), locale); localeName.SetString("en-GB"); res = posixLocale->GetPlatformLocale(&localeName, locale, length); - printf("result: locale = %s POSIX = %s\n", localeName.ToCString(cstr, 32), locale); + printf("result: locale = %s POSIX = %s\n", NS_LossyConvertUCS2toASCII(localeName).get(), locale); localeName.SetString("fr-FR"); res = posixLocale->GetPlatformLocale(&localeName, locale, length); - printf("result: locale = %s POSIX = %s\n", localeName.ToCString(cstr, 32), locale); + printf("result: locale = %s POSIX = %s\n", NS_LossyConvertUCS2toASCII(localeName).get(), locale); localeName.SetString("de-DE"); res = posixLocale->GetPlatformLocale(&localeName, locale, length); - printf("result: locale = %s POSIX = %s\n", localeName.ToCString(cstr, 32), locale); + printf("result: locale = %s POSIX = %s\n", NS_LossyConvertUCS2toASCII(localeName).get(), locale); localeName.SetString("ja-JP"); res = posixLocale->GetPlatformLocale(&localeName, locale, length); - printf("result: locale = %s POSIX = %s\n", localeName.ToCString(cstr, 32), locale); + printf("result: locale = %s POSIX = %s\n", NS_LossyConvertUCS2toASCII(localeName).get(), locale); posixLocale->Release(); } diff --git a/intl/uconv/src/nsCharsetConverterManager.cpp b/intl/uconv/src/nsCharsetConverterManager.cpp index e14435677c8a..826b3051e014 100644 --- a/intl/uconv/src/nsCharsetConverterManager.cpp +++ b/intl/uconv/src/nsCharsetConverterManager.cpp @@ -501,16 +501,13 @@ NS_IMETHODIMP nsCharsetConverterManager::GetUnicodeEncoder( *aResult= nsnull; nsresult res = NS_OK; - static const char kUnicodeEncoderContractIDBase[] = NS_UNICODEENCODER_CONTRACTID_BASE; - static PRInt32 baselen = sizeof(kUnicodeEncoderContractIDBase) - 1; - - char contractid[256]; - PL_strncpy(contractid, kUnicodeEncoderContractIDBase, 256); - aDest->ToCString(contractid + baselen, 256 - baselen); + nsCAutoString contractid( + NS_LITERAL_CSTRING(NS_UNICODEENCODER_CONTRACTID_BASE) + + NS_LossyConvertUCS2toASCII(*aDest)); nsCOMPtr encoder; // Always create an instance since encoders hold state. - encoder = do_CreateInstance(contractid, &res); + encoder = do_CreateInstance(contractid.get(), &res); if (NS_FAILED(res)) res = NS_ERROR_UCONV_NOCONV; @@ -529,15 +526,16 @@ NS_IMETHODIMP nsCharsetConverterManager::GetUnicodeDecoder( *aResult= nsnull; nsresult res = NS_OK;; - static const char kUnicodeDecoderContractIDBase[] = NS_UNICODEDECODER_CONTRACTID_BASE; - static PRInt32 baselen = sizeof(kUnicodeDecoderContractIDBase) - 1; + NS_NAMED_LITERAL_CSTRING(kUnicodeDecoderContractIDBase, + NS_UNICODEDECODER_CONTRACTID_BASE); - char contractid[256]; - PL_strncpy(contractid, kUnicodeDecoderContractIDBase, 256); - aSrc->ToCString(contractid + baselen, 256 - baselen); + nsCAutoString contractid(kUnicodeDecoderContractIDBase + + NS_LossyConvertUCS2toASCII(*aSrc)); nsCOMPtr decoder; - if (!strncmp(contractid+baselen, NS_1BYTE_CODER_PATTERN, NS_1BYTE_CODER_PATTERN_LEN)) + if (!strncmp(contractid+kUnicodeDecoderContractIDBase.Length(), + NS_1BYTE_CODER_PATTERN, + NS_1BYTE_CODER_PATTERN_LEN)) { // Single byte decoders dont hold state. Optimize by using a service. decoder = do_GetService(contractid, &res); diff --git a/intl/uconv/tests/TestUConv.cpp b/intl/uconv/tests/TestUConv.cpp index 597c093b7270..47a137153eca 100644 --- a/intl/uconv/tests/TestUConv.cpp +++ b/intl/uconv/tests/TestUConv.cpp @@ -45,7 +45,6 @@ // Global functions and data [declaration] #define ARRAY_SIZE(_array) (sizeof(_array) / sizeof(_array[0])) -#define BUFFER_SIZE 256 #define SMALL_BUFFER_SIZE 512 #define MED_BUFFER_SIZE 1024 #define BIG_BUFFER_SIZE 2048 @@ -318,8 +317,6 @@ nsresult nsTestUConv::DisplayDetectors() for (PRUint32 i = 0; i < count; i++) { nsCOMPtr cs; nsAutoString str; - char buff[BUFFER_SIZE]; - char buff2[BUFFER_SIZE]; res = array->GetElementAt(i, getter_AddRefs(cs)); if (NS_FAILED(res)) { @@ -335,15 +332,13 @@ nsresult nsTestUConv::DisplayDetectors() } str.Assign(name); - str.ToCString(buff, BUFFER_SIZE); + NS_LossyConvertUCS2toASCII buff(str); + printf("%s", buff.get()); + PrintSpaces(36 - buff.Length()); // align to hard coded column number res = ccMan->GetCharsetTitle2(cs, &str); if (NS_FAILED(res)) str.SetLength(0); - str.ToCString(buff2, BUFFER_SIZE); - - printf("%s", buff); - PrintSpaces(36 - PL_strlen(buff)); // align to hard coded column number - printf("\"%s\"\n", buff2); + printf("\"%s\"\n", NS_LossyConvertUCS2toASCII(str).get()); } mLog.DelTrace(trace); @@ -394,8 +389,6 @@ nsresult nsTestUConv::DisplayCharsets() nsCOMPtr cs; nsAutoString str; nsAutoString prop; - char buff[BUFFER_SIZE]; - char buff2[BUFFER_SIZE]; res = array->GetElementAt(i, getter_AddRefs(cs)); if (NS_FAILED(res)) { @@ -411,14 +404,13 @@ nsresult nsTestUConv::DisplayCharsets() } str.Assign(name); - str.ToCString(buff, BUFFER_SIZE); + NS_LossyConvertUCS2toASCII buff(str); + printf("%s", buff.get()); + PrintSpaces(24 - buff.Length()); // align to hard coded column number res = ccMan->GetCharsetTitle2(cs, &str); if (NS_FAILED(res)) str.SetLength(0); - str.ToCString(buff2, BUFFER_SIZE); - - printf("%s", buff); - PrintSpaces(24 - PL_strlen(buff)); // align to hard coded column number + NS_LossyConvertUCS2toASCII buff2(str); nsCOMPtr dec = NULL; res = ccMan->GetUnicodeDecoder(cs, getter_AddRefs(dec)); diff --git a/layout/base/nsDocumentViewer.cpp b/layout/base/nsDocumentViewer.cpp index 05b6612e0adf..11dc255adcd6 100644 --- a/layout/base/nsDocumentViewer.cpp +++ b/layout/base/nsDocumentViewer.cpp @@ -1554,7 +1554,7 @@ static void DumpFrames(FILE* out, if (NS_SUCCEEDED(CallQueryInterface(child, &frameDebug))) { frameDebug->GetFrameName(tmp); } - fputs(tmp, out); + fputs(NS_LossyConvertUCS2toASCII(tmp).get(), out); nsFrameState state; child->GetFrameState(&state); PRBool isSelected; diff --git a/layout/base/nsFrameManager.cpp b/layout/base/nsFrameManager.cpp index 9973fd6f61f6..d78d31ab8356 100644 --- a/layout/base/nsFrameManager.cpp +++ b/layout/base/nsFrameManager.cpp @@ -1084,7 +1084,7 @@ DumpContext(nsIFrame* aFrame, nsIStyleContext* aContext) if (NS_SUCCEEDED(aFrame->QueryInterface(NS_GET_IID(nsIFrameDebug), (void**)&frameDebug))) { frameDebug->GetFrameName(name); - fputs(name, stdout); + fputs(NS_LossyConvertUCS2toASCII(name).get(), stdout); } fprintf(stdout, " (%p)", NS_STATIC_CAST(void*, aFrame)); } @@ -1096,7 +1096,7 @@ DumpContext(nsIFrame* aFrame, nsIStyleContext* aContext) if (pseudoTag) { nsAutoString buffer; pseudoTag->ToString(buffer); - fputs(buffer, stdout); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), stdout); fputs(" ", stdout); NS_RELEASE(pseudoTag); } diff --git a/layout/base/nsPresShell.cpp b/layout/base/nsPresShell.cpp index 39d37a3a8e05..8801f678896c 100644 --- a/layout/base/nsPresShell.cpp +++ b/layout/base/nsPresShell.cpp @@ -6311,7 +6311,7 @@ LogVerifyMessage(nsIFrame* k1, nsIFrame* k2, const char* aMsg) else { name.Assign(NS_LITERAL_STRING("(null)")); } - fputs(name, stdout); + fputs(NS_LossyConvertUCS2toASCII(name).get(), stdout); printf(" != "); @@ -6326,7 +6326,7 @@ LogVerifyMessage(nsIFrame* k1, nsIFrame* k2, const char* aMsg) else { name.Assign(NS_LITERAL_STRING("(null)")); } - fputs(name, stdout); + fputs(NS_LossyConvertUCS2toASCII(name).get(), stdout); printf(" %s", aMsg); } @@ -6343,7 +6343,7 @@ LogVerifyMessage(nsIFrame* k1, nsIFrame* k2, const char* aMsg, (void**)&frameDebug))) { fprintf(stdout, " "); frameDebug->GetFrameName(name); - fputs(name, stdout); + fputs(NS_LossyConvertUCS2toASCII(name).get(), stdout); fprintf(stdout, " %p ", (void*)k1); } printf("{%d, %d, %d, %d}", r1.x, r1.y, r1.width, r1.height); @@ -6354,7 +6354,7 @@ LogVerifyMessage(nsIFrame* k1, nsIFrame* k2, const char* aMsg, (void**)&frameDebug))) { fprintf(stdout, " "); frameDebug->GetFrameName(name); - fputs(name, stdout); + fputs(NS_LossyConvertUCS2toASCII(name).get(), stdout); fprintf(stdout, " %p ", (void*)k2); } printf("{%d, %d, %d, %d}\n", r2.x, r2.y, r2.width, r2.height); @@ -6585,14 +6585,14 @@ CompareTrees(nsIPresContext* aFirstPresContext, nsIFrame* aFirstFrame, nsAutoString tmp; if (nsnull != listName1) { listName1->ToString(tmp); - fputs(tmp, stdout); + fputs(NS_LossyConvertUCS2toASCII(tmp).get(), stdout); } else fputs("(null)", stdout); printf(" != "); if (nsnull != listName2) { listName2->ToString(tmp); - fputs(tmp, stdout); + fputs(NS_LossyConvertUCS2toASCII(tmp).get(), stdout); } else fputs("(null)", stdout); diff --git a/layout/base/src/nsSpaceManager.cpp b/layout/base/src/nsSpaceManager.cpp index 4c76c12121d3..0a5f464b23f3 100644 --- a/layout/base/src/nsSpaceManager.cpp +++ b/layout/base/src/nsSpaceManager.cpp @@ -1021,7 +1021,7 @@ nsSpaceManager::List(FILE* out) if (NS_SUCCEEDED(mFrame->QueryInterface(NS_GET_IID(nsIFrameDebug), (void**)&frameDebug))) { frameDebug->GetFrameName(tmp); fprintf(out, " frame="); - fputs(tmp, out); + fputs(NS_LossyConvertUCS2toASCII(tmp).get(), out); fprintf(out, "@%p", mFrame); } } @@ -1041,7 +1041,7 @@ nsSpaceManager::List(FILE* out) if (NS_SUCCEEDED(band->mFrame->QueryInterface(NS_GET_IID(nsIFrameDebug), (void**)&frameDebug))) { frameDebug->GetFrameName(tmp); fprintf(out, " frame="); - fputs(tmp, out); + fputs(NS_LossyConvertUCS2toASCII(tmp).get(), out); fprintf(out, "@%p", band->mFrame); } } @@ -1056,7 +1056,7 @@ nsSpaceManager::List(FILE* out) if (NS_SUCCEEDED(frame->QueryInterface(NS_GET_IID(nsIFrameDebug), (void**)&frameDebug))) { frameDebug->GetFrameName(tmp); - fputs(tmp, out); + fputs(NS_LossyConvertUCS2toASCII(tmp).get(), out); fprintf(out, "@%p ", frame); } } diff --git a/layout/build/nsContentDLF.cpp b/layout/build/nsContentDLF.cpp index 5fda108622ac..7677bc397be8 100644 --- a/layout/build/nsContentDLF.cpp +++ b/layout/build/nsContentDLF.cpp @@ -305,7 +305,7 @@ nsContentDLF::CreateDocument(const char* aCommand, if (nsnull != aURL) { nsAutoString tmp; aURL->ToString(tmp); - fputs(tmp, stdout); + fputs(NS_LossyConvertUCS2toASCII(tmp).get(), stdout); printf(": creating document\n"); } #endif diff --git a/layout/generic/nsBlockFrame.cpp b/layout/generic/nsBlockFrame.cpp index 29b92b9b7412..2c02c4ab7153 100644 --- a/layout/generic/nsBlockFrame.cpp +++ b/layout/generic/nsBlockFrame.cpp @@ -438,7 +438,7 @@ nsBlockFrame::List(nsIPresContext* aPresContext, FILE* out, PRInt32 aIndent) con nsAutoString tmp; if (nsnull != listName) { listName->ToString(tmp); - fputs(tmp, out); + fputs(NS_LossyConvertUCS2toASCII(tmp).get(), out); } fputs("<\n", out); while (nsnull != kid) { diff --git a/layout/generic/nsContainerFrame.cpp b/layout/generic/nsContainerFrame.cpp index a8e62423224d..dc3f064fed83 100644 --- a/layout/generic/nsContainerFrame.cpp +++ b/layout/generic/nsContainerFrame.cpp @@ -1107,7 +1107,7 @@ nsContainerFrame::List(nsIPresContext* aPresContext, FILE* out, PRInt32 aIndent) nsAutoString tmp; if (nsnull != listName) { listName->ToString(tmp); - fputs(tmp, out); + fputs(NS_LossyConvertUCS2toASCII(tmp).get(), out); } fputs("<\n", out); while (nsnull != kid) { diff --git a/layout/generic/nsFrame.cpp b/layout/generic/nsFrame.cpp index ce78279b9abb..fbe430b3aefe 100644 --- a/layout/generic/nsFrame.cpp +++ b/layout/generic/nsFrame.cpp @@ -2601,7 +2601,7 @@ nsFrame::DumpRegressionData(nsIPresContext* aPresContext, FILE* out, PRInt32 aIn nsAutoString name; GetFrameName(name); XMLQuote(name); - fputs(name, out); + fputs(NS_LossyConvertUCS2toASCII(name).get(), out); fprintf(out, "\" state=\"%d\" parent=\"%ld\">\n", mState, PRUptrdiff(mParent)); @@ -2665,7 +2665,7 @@ nsFrame::DumpBaseRegressionData(nsIPresContext* aPresContext, FILE* out, PRInt32 list->ToString(listName); fprintf(out, "\n"); } else { diff --git a/layout/generic/nsFrame.h b/layout/generic/nsFrame.h index 72fc2d819995..2386131b1b1c 100644 --- a/layout/generic/nsFrame.h +++ b/layout/generic/nsFrame.h @@ -430,7 +430,7 @@ public: if (NS_SUCCEEDED(aFrame->QueryInterface(NS_GET_IID(nsIFrameDebug), (void**)&frameDebug))) { frameDebug->GetFrameName(tmp); } - fputs(tmp, out); + fputs(NS_LossyConvertUCS2toASCII(tmp).get(), out); fprintf(out, "@%p", aFrame); } diff --git a/layout/generic/nsHTMLReflowCommand.cpp b/layout/generic/nsHTMLReflowCommand.cpp index 42527cb9d0e9..2b8177828af0 100644 --- a/layout/generic/nsHTMLReflowCommand.cpp +++ b/layout/generic/nsHTMLReflowCommand.cpp @@ -321,13 +321,13 @@ NS_IMETHODIMP nsHTMLReflowCommand::List(FILE* out) const fprintf(out, " attr="); nsAutoString attr; mAttribute->ToString(attr); - fputs(attr, out); + fputs(NS_LossyConvertUCS2toASCII(attr).get(), out); } if (mListName) { fprintf(out, " list="); nsAutoString attr; mListName->ToString(attr); - fputs(attr, out); + fputs(NS_LossyConvertUCS2toASCII(attr).get(), out); } fprintf(out, "\n"); diff --git a/layout/generic/nsLineBox.cpp b/layout/generic/nsLineBox.cpp index efcfa7e6fd51..c7c5779444b1 100644 --- a/layout/generic/nsLineBox.cpp +++ b/layout/generic/nsLineBox.cpp @@ -146,7 +146,7 @@ ListFloaters(FILE* out, PRInt32 aIndent, const nsFloaterCacheList& aFloaters) if (NS_SUCCEEDED(frame->QueryInterface(NS_GET_IID(nsIFrameDebug), (void**)&frameDebug))) { frameDebug->GetFrameName(frameName); - fputs(frameName, out); + fputs(NS_LossyConvertUCS2toASCII(frameName).get(), out); } } fprintf(out, " %s region={%d,%d,%d,%d} combinedArea={%d,%d,%d,%d}", diff --git a/layout/generic/nsSpaceManager.cpp b/layout/generic/nsSpaceManager.cpp index 4c76c12121d3..0a5f464b23f3 100644 --- a/layout/generic/nsSpaceManager.cpp +++ b/layout/generic/nsSpaceManager.cpp @@ -1021,7 +1021,7 @@ nsSpaceManager::List(FILE* out) if (NS_SUCCEEDED(mFrame->QueryInterface(NS_GET_IID(nsIFrameDebug), (void**)&frameDebug))) { frameDebug->GetFrameName(tmp); fprintf(out, " frame="); - fputs(tmp, out); + fputs(NS_LossyConvertUCS2toASCII(tmp).get(), out); fprintf(out, "@%p", mFrame); } } @@ -1041,7 +1041,7 @@ nsSpaceManager::List(FILE* out) if (NS_SUCCEEDED(band->mFrame->QueryInterface(NS_GET_IID(nsIFrameDebug), (void**)&frameDebug))) { frameDebug->GetFrameName(tmp); fprintf(out, " frame="); - fputs(tmp, out); + fputs(NS_LossyConvertUCS2toASCII(tmp).get(), out); fprintf(out, "@%p", band->mFrame); } } @@ -1056,7 +1056,7 @@ nsSpaceManager::List(FILE* out) if (NS_SUCCEEDED(frame->QueryInterface(NS_GET_IID(nsIFrameDebug), (void**)&frameDebug))) { frameDebug->GetFrameName(tmp); - fputs(tmp, out); + fputs(NS_LossyConvertUCS2toASCII(tmp).get(), out); fprintf(out, "@%p ", frame); } } diff --git a/layout/generic/nsTextFrame.cpp b/layout/generic/nsTextFrame.cpp index 869b9e127c4b..b8f69b4b0cf9 100644 --- a/layout/generic/nsTextFrame.cpp +++ b/layout/generic/nsTextFrame.cpp @@ -4826,7 +4826,7 @@ nsTextFrame::MeasureText(nsIPresContext* aPresContext, nsAutoString tmp(aTx.GetWordBuffer(), lastWordLen); ListTag(stdout); printf(": start='"); - fputs(tmp, stdout); + fputs(NS_LossyConvertUCS2toASCII(tmp).get(), stdout); printf("' lastWordLen=%d baseWidth=%d prevOffset=%d offset=%d next=", lastWordLen, lastWordDimensions.width, prevOffset, aTextData.mOffset); ListTag(stdout, next); @@ -5549,7 +5549,7 @@ nsTextFrame::ComputeWordFragmentDimensions(nsIPresContext* aPresContext, #ifdef DEBUG_WORD_WRAPPING nsAutoString tmp(bp, wordLen); printf(" fragment='"); - fputs(tmp, stdout); + fputs(NS_LossyConvertUCS2toASCII(tmp).get(), stdout); printf("' width=%d [wordLen=%d contentLen=%d ContentLength=%d]\n", dimensions.width, wordLen, contentLen, tx.GetContentLength()); #endif @@ -5683,7 +5683,7 @@ nsTextFrame::List(nsIPresContext* aPresContext, FILE* out, PRInt32 aIndent) cons IndentBy(out, aIndent); fputs("\"", out); - fputs(tmp, out); + fputs(NS_LossyConvertUCS2toASCII(tmp).get(), out); fputs("\"\n", out); aIndent--; diff --git a/layout/generic/nsTextTransformer.cpp b/layout/generic/nsTextTransformer.cpp index d9271577e91b..3aa357745bda 100644 --- a/layout/generic/nsTextTransformer.cpp +++ b/layout/generic/nsTextTransformer.cpp @@ -1424,7 +1424,7 @@ nsTextTransformer::SelfTest(nsILineBreaker* aLineBreaker, if (gNoisy) { nsAutoString uc2(st->text); printf("%s forwards test: '", isAsciiTest ? "ascii" : "unicode"); - fputs(uc2, stdout); + fputs(NS_LossyConvertUCS2toASCII(uc2).get(), stdout); printf("'\n"); } tx.Init2(&frag, 0, preModeValue[preMode], NS_STYLE_TEXT_TRANSFORM_NONE); @@ -1436,7 +1436,7 @@ nsTextTransformer::SelfTest(nsILineBreaker* aLineBreaker, if (gNoisy) { nsAutoString tmp(bp, wordLen); printf(" '"); - fputs(tmp, stdout); + fputs(NS_LossyConvertUCS2toASCII(tmp).get(), stdout); printf("': ws=%s wordLen=%d (%d) contentLen=%d (offset=%d)\n", ws ? "yes" : "no", wordLen, *expectedResults, contentLen, tx.mOffset); @@ -1457,7 +1457,7 @@ nsTextTransformer::SelfTest(nsILineBreaker* aLineBreaker, if (gNoisy) { nsAutoString uc2(st->text); printf("%s backwards test: '", isAsciiTest ? "ascii" : "unicode"); - fputs(uc2, stdout); + fputs(NS_LossyConvertUCS2toASCII(uc2).get(), stdout); printf("'\n"); } tx.Init2(&frag, frag.GetLength(), NS_STYLE_WHITESPACE_NORMAL, @@ -1468,7 +1468,7 @@ nsTextTransformer::SelfTest(nsILineBreaker* aLineBreaker, if (gNoisy) { nsAutoString tmp(bp, wordLen); printf(" '"); - fputs(tmp, stdout); + fputs(NS_LossyConvertUCS2toASCII(tmp).get(), stdout); printf("': ws=%s wordLen=%d contentLen=%d (offset=%d)\n", ws ? "yes" : "no", wordLen, contentLen, tx.mOffset); diff --git a/layout/html/base/src/nsBlockFrame.cpp b/layout/html/base/src/nsBlockFrame.cpp index 29b92b9b7412..2c02c4ab7153 100644 --- a/layout/html/base/src/nsBlockFrame.cpp +++ b/layout/html/base/src/nsBlockFrame.cpp @@ -438,7 +438,7 @@ nsBlockFrame::List(nsIPresContext* aPresContext, FILE* out, PRInt32 aIndent) con nsAutoString tmp; if (nsnull != listName) { listName->ToString(tmp); - fputs(tmp, out); + fputs(NS_LossyConvertUCS2toASCII(tmp).get(), out); } fputs("<\n", out); while (nsnull != kid) { diff --git a/layout/html/base/src/nsContainerFrame.cpp b/layout/html/base/src/nsContainerFrame.cpp index a8e62423224d..dc3f064fed83 100644 --- a/layout/html/base/src/nsContainerFrame.cpp +++ b/layout/html/base/src/nsContainerFrame.cpp @@ -1107,7 +1107,7 @@ nsContainerFrame::List(nsIPresContext* aPresContext, FILE* out, PRInt32 aIndent) nsAutoString tmp; if (nsnull != listName) { listName->ToString(tmp); - fputs(tmp, out); + fputs(NS_LossyConvertUCS2toASCII(tmp).get(), out); } fputs("<\n", out); while (nsnull != kid) { diff --git a/layout/html/base/src/nsFrame.cpp b/layout/html/base/src/nsFrame.cpp index ce78279b9abb..fbe430b3aefe 100644 --- a/layout/html/base/src/nsFrame.cpp +++ b/layout/html/base/src/nsFrame.cpp @@ -2601,7 +2601,7 @@ nsFrame::DumpRegressionData(nsIPresContext* aPresContext, FILE* out, PRInt32 aIn nsAutoString name; GetFrameName(name); XMLQuote(name); - fputs(name, out); + fputs(NS_LossyConvertUCS2toASCII(name).get(), out); fprintf(out, "\" state=\"%d\" parent=\"%ld\">\n", mState, PRUptrdiff(mParent)); @@ -2665,7 +2665,7 @@ nsFrame::DumpBaseRegressionData(nsIPresContext* aPresContext, FILE* out, PRInt32 list->ToString(listName); fprintf(out, "\n"); } else { diff --git a/layout/html/base/src/nsFrame.h b/layout/html/base/src/nsFrame.h index 72fc2d819995..2386131b1b1c 100644 --- a/layout/html/base/src/nsFrame.h +++ b/layout/html/base/src/nsFrame.h @@ -430,7 +430,7 @@ public: if (NS_SUCCEEDED(aFrame->QueryInterface(NS_GET_IID(nsIFrameDebug), (void**)&frameDebug))) { frameDebug->GetFrameName(tmp); } - fputs(tmp, out); + fputs(NS_LossyConvertUCS2toASCII(tmp).get(), out); fprintf(out, "@%p", aFrame); } diff --git a/layout/html/base/src/nsFrameManager.cpp b/layout/html/base/src/nsFrameManager.cpp index 9973fd6f61f6..d78d31ab8356 100644 --- a/layout/html/base/src/nsFrameManager.cpp +++ b/layout/html/base/src/nsFrameManager.cpp @@ -1084,7 +1084,7 @@ DumpContext(nsIFrame* aFrame, nsIStyleContext* aContext) if (NS_SUCCEEDED(aFrame->QueryInterface(NS_GET_IID(nsIFrameDebug), (void**)&frameDebug))) { frameDebug->GetFrameName(name); - fputs(name, stdout); + fputs(NS_LossyConvertUCS2toASCII(name).get(), stdout); } fprintf(stdout, " (%p)", NS_STATIC_CAST(void*, aFrame)); } @@ -1096,7 +1096,7 @@ DumpContext(nsIFrame* aFrame, nsIStyleContext* aContext) if (pseudoTag) { nsAutoString buffer; pseudoTag->ToString(buffer); - fputs(buffer, stdout); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), stdout); fputs(" ", stdout); NS_RELEASE(pseudoTag); } diff --git a/layout/html/base/src/nsHTMLImageLoader.cpp b/layout/html/base/src/nsHTMLImageLoader.cpp index ed034b94a781..06bf73dbed2b 100644 --- a/layout/html/base/src/nsHTMLImageLoader.cpp +++ b/layout/html/base/src/nsHTMLImageLoader.cpp @@ -239,7 +239,7 @@ nsHTMLImageLoader::StartLoadImage(nsIPresContext* aPresContext) #ifdef NOISY_IMAGE_LOADING nsFrame::ListTag(stdout, mFrame); printf(": loading image '"); - fputs(mURL, stdout); + fputs(NS_LossyConvertUCS2toASCII(mURL).get(), stdout); printf("' @ "); if (mFlags.mNeedIntrinsicImageSize) { printf("intrinsic size "); diff --git a/layout/html/base/src/nsHTMLReflowCommand.cpp b/layout/html/base/src/nsHTMLReflowCommand.cpp index 42527cb9d0e9..2b8177828af0 100644 --- a/layout/html/base/src/nsHTMLReflowCommand.cpp +++ b/layout/html/base/src/nsHTMLReflowCommand.cpp @@ -321,13 +321,13 @@ NS_IMETHODIMP nsHTMLReflowCommand::List(FILE* out) const fprintf(out, " attr="); nsAutoString attr; mAttribute->ToString(attr); - fputs(attr, out); + fputs(NS_LossyConvertUCS2toASCII(attr).get(), out); } if (mListName) { fprintf(out, " list="); nsAutoString attr; mListName->ToString(attr); - fputs(attr, out); + fputs(NS_LossyConvertUCS2toASCII(attr).get(), out); } fprintf(out, "\n"); diff --git a/layout/html/base/src/nsLineBox.cpp b/layout/html/base/src/nsLineBox.cpp index efcfa7e6fd51..c7c5779444b1 100644 --- a/layout/html/base/src/nsLineBox.cpp +++ b/layout/html/base/src/nsLineBox.cpp @@ -146,7 +146,7 @@ ListFloaters(FILE* out, PRInt32 aIndent, const nsFloaterCacheList& aFloaters) if (NS_SUCCEEDED(frame->QueryInterface(NS_GET_IID(nsIFrameDebug), (void**)&frameDebug))) { frameDebug->GetFrameName(frameName); - fputs(frameName, out); + fputs(NS_LossyConvertUCS2toASCII(frameName).get(), out); } } fprintf(out, " %s region={%d,%d,%d,%d} combinedArea={%d,%d,%d,%d}", diff --git a/layout/html/base/src/nsPresShell.cpp b/layout/html/base/src/nsPresShell.cpp index 39d37a3a8e05..8801f678896c 100644 --- a/layout/html/base/src/nsPresShell.cpp +++ b/layout/html/base/src/nsPresShell.cpp @@ -6311,7 +6311,7 @@ LogVerifyMessage(nsIFrame* k1, nsIFrame* k2, const char* aMsg) else { name.Assign(NS_LITERAL_STRING("(null)")); } - fputs(name, stdout); + fputs(NS_LossyConvertUCS2toASCII(name).get(), stdout); printf(" != "); @@ -6326,7 +6326,7 @@ LogVerifyMessage(nsIFrame* k1, nsIFrame* k2, const char* aMsg) else { name.Assign(NS_LITERAL_STRING("(null)")); } - fputs(name, stdout); + fputs(NS_LossyConvertUCS2toASCII(name).get(), stdout); printf(" %s", aMsg); } @@ -6343,7 +6343,7 @@ LogVerifyMessage(nsIFrame* k1, nsIFrame* k2, const char* aMsg, (void**)&frameDebug))) { fprintf(stdout, " "); frameDebug->GetFrameName(name); - fputs(name, stdout); + fputs(NS_LossyConvertUCS2toASCII(name).get(), stdout); fprintf(stdout, " %p ", (void*)k1); } printf("{%d, %d, %d, %d}", r1.x, r1.y, r1.width, r1.height); @@ -6354,7 +6354,7 @@ LogVerifyMessage(nsIFrame* k1, nsIFrame* k2, const char* aMsg, (void**)&frameDebug))) { fprintf(stdout, " "); frameDebug->GetFrameName(name); - fputs(name, stdout); + fputs(NS_LossyConvertUCS2toASCII(name).get(), stdout); fprintf(stdout, " %p ", (void*)k2); } printf("{%d, %d, %d, %d}\n", r2.x, r2.y, r2.width, r2.height); @@ -6585,14 +6585,14 @@ CompareTrees(nsIPresContext* aFirstPresContext, nsIFrame* aFirstFrame, nsAutoString tmp; if (nsnull != listName1) { listName1->ToString(tmp); - fputs(tmp, stdout); + fputs(NS_LossyConvertUCS2toASCII(tmp).get(), stdout); } else fputs("(null)", stdout); printf(" != "); if (nsnull != listName2) { listName2->ToString(tmp); - fputs(tmp, stdout); + fputs(NS_LossyConvertUCS2toASCII(tmp).get(), stdout); } else fputs("(null)", stdout); diff --git a/layout/html/base/src/nsTextFrame.cpp b/layout/html/base/src/nsTextFrame.cpp index 869b9e127c4b..b8f69b4b0cf9 100644 --- a/layout/html/base/src/nsTextFrame.cpp +++ b/layout/html/base/src/nsTextFrame.cpp @@ -4826,7 +4826,7 @@ nsTextFrame::MeasureText(nsIPresContext* aPresContext, nsAutoString tmp(aTx.GetWordBuffer(), lastWordLen); ListTag(stdout); printf(": start='"); - fputs(tmp, stdout); + fputs(NS_LossyConvertUCS2toASCII(tmp).get(), stdout); printf("' lastWordLen=%d baseWidth=%d prevOffset=%d offset=%d next=", lastWordLen, lastWordDimensions.width, prevOffset, aTextData.mOffset); ListTag(stdout, next); @@ -5549,7 +5549,7 @@ nsTextFrame::ComputeWordFragmentDimensions(nsIPresContext* aPresContext, #ifdef DEBUG_WORD_WRAPPING nsAutoString tmp(bp, wordLen); printf(" fragment='"); - fputs(tmp, stdout); + fputs(NS_LossyConvertUCS2toASCII(tmp).get(), stdout); printf("' width=%d [wordLen=%d contentLen=%d ContentLength=%d]\n", dimensions.width, wordLen, contentLen, tx.GetContentLength()); #endif @@ -5683,7 +5683,7 @@ nsTextFrame::List(nsIPresContext* aPresContext, FILE* out, PRInt32 aIndent) cons IndentBy(out, aIndent); fputs("\"", out); - fputs(tmp, out); + fputs(NS_LossyConvertUCS2toASCII(tmp).get(), out); fputs("\"\n", out); aIndent--; diff --git a/layout/html/base/src/nsTextTransformer.cpp b/layout/html/base/src/nsTextTransformer.cpp index d9271577e91b..3aa357745bda 100644 --- a/layout/html/base/src/nsTextTransformer.cpp +++ b/layout/html/base/src/nsTextTransformer.cpp @@ -1424,7 +1424,7 @@ nsTextTransformer::SelfTest(nsILineBreaker* aLineBreaker, if (gNoisy) { nsAutoString uc2(st->text); printf("%s forwards test: '", isAsciiTest ? "ascii" : "unicode"); - fputs(uc2, stdout); + fputs(NS_LossyConvertUCS2toASCII(uc2).get(), stdout); printf("'\n"); } tx.Init2(&frag, 0, preModeValue[preMode], NS_STYLE_TEXT_TRANSFORM_NONE); @@ -1436,7 +1436,7 @@ nsTextTransformer::SelfTest(nsILineBreaker* aLineBreaker, if (gNoisy) { nsAutoString tmp(bp, wordLen); printf(" '"); - fputs(tmp, stdout); + fputs(NS_LossyConvertUCS2toASCII(tmp).get(), stdout); printf("': ws=%s wordLen=%d (%d) contentLen=%d (offset=%d)\n", ws ? "yes" : "no", wordLen, *expectedResults, contentLen, tx.mOffset); @@ -1457,7 +1457,7 @@ nsTextTransformer::SelfTest(nsILineBreaker* aLineBreaker, if (gNoisy) { nsAutoString uc2(st->text); printf("%s backwards test: '", isAsciiTest ? "ascii" : "unicode"); - fputs(uc2, stdout); + fputs(NS_LossyConvertUCS2toASCII(uc2).get(), stdout); printf("'\n"); } tx.Init2(&frag, frag.GetLength(), NS_STYLE_WHITESPACE_NORMAL, @@ -1468,7 +1468,7 @@ nsTextTransformer::SelfTest(nsILineBreaker* aLineBreaker, if (gNoisy) { nsAutoString tmp(bp, wordLen); printf(" '"); - fputs(tmp, stdout); + fputs(NS_LossyConvertUCS2toASCII(tmp).get(), stdout); printf("': ws=%s wordLen=%d contentLen=%d (offset=%d)\n", ws ? "yes" : "no", wordLen, contentLen, tx.mOffset); diff --git a/layout/html/tests/TestCSSScanner.cpp b/layout/html/tests/TestCSSScanner.cpp index 24ce1d758349..cf27be3334b2 100644 --- a/layout/html/tests/TestCSSScanner.cpp +++ b/layout/html/tests/TestCSSScanner.cpp @@ -117,7 +117,7 @@ int main(int argc, char** argv) case eCSSToken_InvalidURL: case eCSSToken_ID: case eCSSToken_HTMLComment: - fputs(tok.mIdent, stdout); + fputs(NS_LossyConvertUCS2toASCII(tok.mIdent).get(), stdout); fputs("\n", stdout); break; diff --git a/layout/mathml/base/src/nsMathMLChar.cpp b/layout/mathml/base/src/nsMathMLChar.cpp index 2ac583966bb4..eb0d9d40bd2c 100644 --- a/layout/mathml/base/src/nsMathMLChar.cpp +++ b/layout/mathml/base/src/nsMathMLChar.cpp @@ -319,13 +319,14 @@ nsGlyphTable::ElementAt(nsIPresContext* aPresContext, nsMathMLChar* aChar, PRUin } nsresult rv = LoadProperties(*mFontName[0], mGlyphProperties); #ifdef NS_DEBUG - nsAutoString uriStr; - uriStr.Assign(NS_LITERAL_STRING("resource:/res/fonts/mathfont")); - uriStr.Append(*mFontName[0]); + nsCAutoString uriStr; + uriStr.Assign(NS_LITERAL_CSTRING("resource:/res/fonts/mathfont")); + uriStr.Append(NS_LossyConvertUCS2toASCII(*mFontName[0])); uriStr.StripWhitespace(); // that may come from mFontName - uriStr.Append(NS_LITERAL_STRING(".properties")); - char str[200]; uriStr.ToCString(str, sizeof(str)); - printf("Loading %s ... %s\n", str, (NS_FAILED(rv)) ? "Failed" : "Done"); + uriStr.Append(NS_LITERAL_CSTRING(".properties")); + printf("Loading %s ... %s\n", + uriStr.get(), + (NS_FAILED(rv)) ? "Failed" : "Done"); #endif if (NS_FAILED(rv)) { mState = NS_TABLE_STATE_ERROR; // never waste time with this table again diff --git a/layout/mathml/base/src/nsMathMLmpaddedFrame.cpp b/layout/mathml/base/src/nsMathMLmpaddedFrame.cpp index 5c6718aa6a7f..8130fb21b808 100644 --- a/layout/mathml/base/src/nsMathMLmpaddedFrame.cpp +++ b/layout/mathml/base/src/nsMathMLmpaddedFrame.cpp @@ -191,9 +191,8 @@ nsMathMLmpaddedFrame::ParseAttribute(nsString& aString, // convert to CSS units if (!ParseNumericValue(value, aCSSValue)) { #ifdef NS_DEBUG - char str[50]; - aString.ToCString(str, 50); - printf("mpadded: attribute with bad numeric value: %s\n", str); + printf("mpadded: attribute with bad numeric value: %s\n", + NS_LossyConvertUCS2toASCII(aString).get()); #endif aSign = NS_MATHML_SIGN_INVALID; return PR_FALSE; @@ -218,9 +217,8 @@ nsMathMLmpaddedFrame::ParseAttribute(nsString& aString, // it allows keeping the code simpler...) #ifdef NS_DEBUG - char str[50]; - aString.ToCString(str, 50); - printf("mpadded: attribute with bad numeric value: %s\n", str); + printf("mpadded: attribute with bad numeric value: %s\n", + NS_LossyConvertUCS2toASCII(aString).get()); #endif aCSSValue.Reset(); aSign = NS_MATHML_SIGN_INVALID; @@ -273,9 +271,8 @@ nsMathMLmpaddedFrame::ParseAttribute(nsString& aString, // if we enter here, it means we have both a CSS unit *and* a pseudo-unit, // e.g., width="100em height", this an error/ambiguity that the author should fix #ifdef NS_DEBUG - char str[50]; - aString.ToCString(str, 50); - printf("mpadded: attribute with bad numeric value: %s\n", str); + printf("mpadded: attribute with bad numeric value: %s\n", + NS_LossyConvertUCS2toASCII(aString).get()); #endif aCSSValue.Reset(); aSign = NS_MATHML_SIGN_INVALID; diff --git a/layout/mathml/content/src/nsMathMLOperators.cpp b/layout/mathml/content/src/nsMathMLOperators.cpp index b8689b7ea647..cb2392fed9a5 100644 --- a/layout/mathml/content/src/nsMathMLOperators.cpp +++ b/layout/mathml/content/src/nsMathMLOperators.cpp @@ -241,8 +241,7 @@ SetOperator(OperatorData* aOperatorData, gOperatorTable->Put(&key, aOperatorData); #ifdef NS_DEBUG - char str[200]; - aAttributes.ToCString(str, sizeof(str)); + NS_LossyConvertUCS2toASCII str(aAttributes); #endif // Loop over the space-delimited list of attributes to get the name:value pairs aAttributes.Append(kNullCh); // put an extra null at the end @@ -262,7 +261,7 @@ SetOperator(OperatorData* aOperatorData, } if ((kColonCh!=*end) && (kEqualCh!=*end)) { #ifdef NS_DEBUG - printf("Bad MathML operator: %s\n", str); + printf("Bad MathML operator: %s\n", str.get()); #endif return PR_TRUE; } diff --git a/layout/style/nsCSSDeclaration.cpp b/layout/style/nsCSSDeclaration.cpp index 3768ae80823f..8f58ac93b919 100644 --- a/layout/style/nsCSSDeclaration.cpp +++ b/layout/style/nsCSSDeclaration.cpp @@ -117,7 +117,7 @@ void nsCSSFont::List(FILE* out, PRInt32 aIndent) const mSize.AppendToString(buffer, eCSSProperty_font_size); mSizeAdjust.AppendToString(buffer, eCSSProperty_font_size_adjust); mStretch.AppendToString(buffer, eCSSProperty_font_stretch); - fputs(buffer, out); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out); } // --- support ----------------- @@ -188,7 +188,7 @@ void nsCSSColor::List(FILE* out, PRInt32 aIndent) const mBackAttachment.AppendToString(buffer, eCSSProperty_background_attachment); mBackPositionX.AppendToString(buffer, eCSSProperty_background_x_position); mBackPositionY.AppendToString(buffer, eCSSProperty_background_y_position); - fputs(buffer, out); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out); } // --- nsCSSText support ----------------- @@ -282,7 +282,7 @@ void nsCSSText::List(FILE* out, PRInt32 aIndent) const mUnicodeBidi.AppendToString(buffer, eCSSProperty_unicode_bidi); mLineHeight.AppendToString(buffer, eCSSProperty_line_height); mWhiteSpace.AppendToString(buffer, eCSSProperty_white_space); - fputs(buffer, out); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out); } // --- nsCSSRect ----------------- @@ -322,7 +322,7 @@ void nsCSSRect::List(FILE* out, nsCSSProperty aPropID, PRInt32 aIndent) const mRight.AppendToString(buffer); mBottom.AppendToString(buffer); mLeft.AppendToString(buffer); - fputs(buffer, out); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out); } void nsCSSRect::List(FILE* out, PRInt32 aIndent, const nsCSSProperty aTRBL[]) const @@ -352,7 +352,7 @@ void nsCSSRect::List(FILE* out, PRInt32 aIndent, const nsCSSProperty aTRBL[]) co mLeft.AppendToString(buffer); } - fputs(buffer, out); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out); } // --- nsCSSDisplay ----------------- @@ -405,13 +405,13 @@ void nsCSSDisplay::List(FILE* out, PRInt32 aIndent) const mVisibility.AppendToString(buffer, eCSSProperty_visibility); mOpacity.AppendToString(buffer, eCSSProperty_opacity); - fputs(buffer, out); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out); if (nsnull != mClip) { mClip->List(out, eCSSProperty_clip); } buffer.SetLength(0); mOverflow.AppendToString(buffer, eCSSProperty_overflow); - fputs(buffer, out); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out); } // --- nsCSSMargin ----------------- @@ -520,7 +520,7 @@ void nsCSSMargin::List(FILE* out, PRInt32 aIndent) const mOutlineRadius->List(out, aIndent, trbl); } mFloatEdge.AppendToString(buffer, eCSSProperty_float_edge); - fputs(buffer, out); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out); } // --- nsCSSPosition ----------------- @@ -571,7 +571,7 @@ void nsCSSPosition::List(FILE* out, PRInt32 aIndent) const mMaxHeight.AppendToString(buffer, eCSSProperty_max_height); mBoxSizing.AppendToString(buffer, eCSSProperty_box_sizing); mZIndex.AppendToString(buffer, eCSSProperty_z_index); - fputs(buffer, out); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out); if (nsnull != mOffset) { static const nsCSSProperty trbl[] = { @@ -618,7 +618,7 @@ void nsCSSList::List(FILE* out, PRInt32 aIndent) const mType.AppendToString(buffer, eCSSProperty_list_style_type); mImage.AppendToString(buffer, eCSSProperty_list_style_image); mPosition.AppendToString(buffer, eCSSProperty_list_style_position); - fputs(buffer, out); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out); } // --- nsCSSTable ----------------- @@ -662,7 +662,7 @@ void nsCSSTable::List(FILE* out, PRInt32 aIndent) const mEmptyCells.AppendToString(buffer, eCSSProperty_empty_cells); mLayout.AppendToString(buffer, eCSSProperty_table_layout); - fputs(buffer, out); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out); } // --- nsCSSBreaks ----------------- @@ -706,7 +706,7 @@ void nsCSSBreaks::List(FILE* out, PRInt32 aIndent) const mPageBreakBefore.AppendToString(buffer, eCSSProperty_page_break_before); mPageBreakInside.AppendToString(buffer, eCSSProperty_page_break_inside); - fputs(buffer, out); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out); } // --- nsCSSPage ----------------- @@ -744,7 +744,7 @@ void nsCSSPage::List(FILE* out, PRInt32 aIndent) const mSizeWidth.AppendToString(buffer, eCSSProperty_size_width); mSizeHeight.AppendToString(buffer, eCSSProperty_size_height); - fputs(buffer, out); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out); } // --- nsCSSContent support ----------------- @@ -861,7 +861,7 @@ void nsCSSContent::List(FILE* out, PRInt32 aIndent) const quotes = quotes->mNext; } - fputs(buffer, out); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out); } // --- nsCSSUserInterface ----------------- @@ -921,7 +921,7 @@ void nsCSSUserInterface::List(FILE* out, PRInt32 aIndent) const cursor = cursor->mNext; } - fputs(buffer, out); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out); } // --- nsCSSAural ----------------- @@ -991,7 +991,7 @@ void nsCSSAural::List(FILE* out, PRInt32 aIndent) const mVoiceFamily.AppendToString(buffer, eCSSProperty_voice_family); mVolume.AppendToString(buffer, eCSSProperty_volume); - fputs(buffer, out); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out); } #ifdef INCLUDE_XUL @@ -1032,7 +1032,7 @@ void nsCSSXUL::List(FILE* out, PRInt32 aIndent) const mBoxOrient.AppendToString(buffer, eCSSProperty_box_orient); mBoxPack.AppendToString(buffer, eCSSProperty_box_pack); mBoxOrdinal.AppendToString(buffer, eCSSProperty_box_ordinal_group); - fputs(buffer, out); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out); } #endif // INCLUDE_XUL diff --git a/layout/style/nsCSSRules.cpp b/layout/style/nsCSSRules.cpp index 4a5e5c1290f2..56ae56ce07b6 100644 --- a/layout/style/nsCSSRules.cpp +++ b/layout/style/nsCSSRules.cpp @@ -249,7 +249,7 @@ CSSCharsetRuleImpl::List(FILE* out, PRInt32 aIndent) const for (PRInt32 indent = aIndent; --indent >= 0; ) fputs(" ", out); fputs("@charset \"", out); - fputs(mEncoding, out); + fputs(NS_LossyConvertUCS2toASCII(mEncoding).get(), out); fputs("\"\n", out); return NS_OK; @@ -477,12 +477,12 @@ CSSImportRuleImpl::List(FILE* out, PRInt32 aIndent) const for (PRInt32 indent = aIndent; --indent >= 0; ) fputs(" ", out); fputs("@import \"", out); - fputs(mURLSpec, out); + fputs(NS_LossyConvertUCS2toASCII(mURLSpec).get(), out); fputs("\" ", out); nsAutoString mediaText; mMedia->GetText(mediaText); - fputs(mediaText, out); + fputs(NS_LossyConvertUCS2toASCII(mediaText).get(), out); fputs("\n", out); return NS_OK; @@ -876,7 +876,7 @@ CSSMediaRuleImpl::List(FILE* out, PRInt32 aIndent) const while (index < count) { nsCOMPtr medium = dont_AddRef((nsIAtom*)mMedia->ElementAt(index++)); medium->ToString(buffer); - fputs(buffer, out); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out); if (index < count) { fputs(", ", out); } @@ -1326,12 +1326,12 @@ CSSNameSpaceRuleImpl::List(FILE* out, PRInt32 aIndent) const if (mPrefix) { mPrefix->ToString(buffer); - fputs(buffer, out); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out); fputs(" ", out); } fputs("url(", out); - fputs(mURLSpec, out); + fputs(NS_LossyConvertUCS2toASCII(mURLSpec).get(), out); fputs(")\n", out); return NS_OK; } diff --git a/layout/style/nsCSSStruct.cpp b/layout/style/nsCSSStruct.cpp index 3768ae80823f..8f58ac93b919 100644 --- a/layout/style/nsCSSStruct.cpp +++ b/layout/style/nsCSSStruct.cpp @@ -117,7 +117,7 @@ void nsCSSFont::List(FILE* out, PRInt32 aIndent) const mSize.AppendToString(buffer, eCSSProperty_font_size); mSizeAdjust.AppendToString(buffer, eCSSProperty_font_size_adjust); mStretch.AppendToString(buffer, eCSSProperty_font_stretch); - fputs(buffer, out); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out); } // --- support ----------------- @@ -188,7 +188,7 @@ void nsCSSColor::List(FILE* out, PRInt32 aIndent) const mBackAttachment.AppendToString(buffer, eCSSProperty_background_attachment); mBackPositionX.AppendToString(buffer, eCSSProperty_background_x_position); mBackPositionY.AppendToString(buffer, eCSSProperty_background_y_position); - fputs(buffer, out); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out); } // --- nsCSSText support ----------------- @@ -282,7 +282,7 @@ void nsCSSText::List(FILE* out, PRInt32 aIndent) const mUnicodeBidi.AppendToString(buffer, eCSSProperty_unicode_bidi); mLineHeight.AppendToString(buffer, eCSSProperty_line_height); mWhiteSpace.AppendToString(buffer, eCSSProperty_white_space); - fputs(buffer, out); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out); } // --- nsCSSRect ----------------- @@ -322,7 +322,7 @@ void nsCSSRect::List(FILE* out, nsCSSProperty aPropID, PRInt32 aIndent) const mRight.AppendToString(buffer); mBottom.AppendToString(buffer); mLeft.AppendToString(buffer); - fputs(buffer, out); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out); } void nsCSSRect::List(FILE* out, PRInt32 aIndent, const nsCSSProperty aTRBL[]) const @@ -352,7 +352,7 @@ void nsCSSRect::List(FILE* out, PRInt32 aIndent, const nsCSSProperty aTRBL[]) co mLeft.AppendToString(buffer); } - fputs(buffer, out); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out); } // --- nsCSSDisplay ----------------- @@ -405,13 +405,13 @@ void nsCSSDisplay::List(FILE* out, PRInt32 aIndent) const mVisibility.AppendToString(buffer, eCSSProperty_visibility); mOpacity.AppendToString(buffer, eCSSProperty_opacity); - fputs(buffer, out); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out); if (nsnull != mClip) { mClip->List(out, eCSSProperty_clip); } buffer.SetLength(0); mOverflow.AppendToString(buffer, eCSSProperty_overflow); - fputs(buffer, out); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out); } // --- nsCSSMargin ----------------- @@ -520,7 +520,7 @@ void nsCSSMargin::List(FILE* out, PRInt32 aIndent) const mOutlineRadius->List(out, aIndent, trbl); } mFloatEdge.AppendToString(buffer, eCSSProperty_float_edge); - fputs(buffer, out); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out); } // --- nsCSSPosition ----------------- @@ -571,7 +571,7 @@ void nsCSSPosition::List(FILE* out, PRInt32 aIndent) const mMaxHeight.AppendToString(buffer, eCSSProperty_max_height); mBoxSizing.AppendToString(buffer, eCSSProperty_box_sizing); mZIndex.AppendToString(buffer, eCSSProperty_z_index); - fputs(buffer, out); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out); if (nsnull != mOffset) { static const nsCSSProperty trbl[] = { @@ -618,7 +618,7 @@ void nsCSSList::List(FILE* out, PRInt32 aIndent) const mType.AppendToString(buffer, eCSSProperty_list_style_type); mImage.AppendToString(buffer, eCSSProperty_list_style_image); mPosition.AppendToString(buffer, eCSSProperty_list_style_position); - fputs(buffer, out); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out); } // --- nsCSSTable ----------------- @@ -662,7 +662,7 @@ void nsCSSTable::List(FILE* out, PRInt32 aIndent) const mEmptyCells.AppendToString(buffer, eCSSProperty_empty_cells); mLayout.AppendToString(buffer, eCSSProperty_table_layout); - fputs(buffer, out); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out); } // --- nsCSSBreaks ----------------- @@ -706,7 +706,7 @@ void nsCSSBreaks::List(FILE* out, PRInt32 aIndent) const mPageBreakBefore.AppendToString(buffer, eCSSProperty_page_break_before); mPageBreakInside.AppendToString(buffer, eCSSProperty_page_break_inside); - fputs(buffer, out); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out); } // --- nsCSSPage ----------------- @@ -744,7 +744,7 @@ void nsCSSPage::List(FILE* out, PRInt32 aIndent) const mSizeWidth.AppendToString(buffer, eCSSProperty_size_width); mSizeHeight.AppendToString(buffer, eCSSProperty_size_height); - fputs(buffer, out); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out); } // --- nsCSSContent support ----------------- @@ -861,7 +861,7 @@ void nsCSSContent::List(FILE* out, PRInt32 aIndent) const quotes = quotes->mNext; } - fputs(buffer, out); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out); } // --- nsCSSUserInterface ----------------- @@ -921,7 +921,7 @@ void nsCSSUserInterface::List(FILE* out, PRInt32 aIndent) const cursor = cursor->mNext; } - fputs(buffer, out); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out); } // --- nsCSSAural ----------------- @@ -991,7 +991,7 @@ void nsCSSAural::List(FILE* out, PRInt32 aIndent) const mVoiceFamily.AppendToString(buffer, eCSSProperty_voice_family); mVolume.AppendToString(buffer, eCSSProperty_volume); - fputs(buffer, out); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out); } #ifdef INCLUDE_XUL @@ -1032,7 +1032,7 @@ void nsCSSXUL::List(FILE* out, PRInt32 aIndent) const mBoxOrient.AppendToString(buffer, eCSSProperty_box_orient); mBoxPack.AppendToString(buffer, eCSSProperty_box_pack); mBoxOrdinal.AppendToString(buffer, eCSSProperty_box_ordinal_group); - fputs(buffer, out); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out); } #endif // INCLUDE_XUL diff --git a/layout/style/nsCSSStyleRule.cpp b/layout/style/nsCSSStyleRule.cpp index 766633063900..0a612b384ea6 100644 --- a/layout/style/nsCSSStyleRule.cpp +++ b/layout/style/nsCSSStyleRule.cpp @@ -2275,7 +2275,7 @@ CSSStyleRuleImpl::List(FILE* out, PRInt32 aIndent) const buffer.AppendWithConversion(" weight: "); buffer.AppendInt(mWeight, 10); buffer.AppendWithConversion(" "); - fputs(buffer, out); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out); if (nsnull != mDeclaration) { mDeclaration->List(out); } diff --git a/layout/style/nsCSSStyleSheet.cpp b/layout/style/nsCSSStyleSheet.cpp index e8e42d133c5d..2daca219abd1 100644 --- a/layout/style/nsCSSStyleSheet.cpp +++ b/layout/style/nsCSSStyleSheet.cpp @@ -2464,7 +2464,7 @@ static PRBool ListCascade(nsHashKey* aKey, void* aValue, void* aClosure) fputs("\nRules in cascade order for medium: \"", data->mOut); nsAutoString buffer; key->mAtom->ToString(buffer); - fputs(buffer, data->mOut); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), data->mOut); fputs("\"\n", data->mOut); ListRules(cascade->mWeightedRules, data->mOut, data->mIndent); @@ -2503,7 +2503,7 @@ void CSSStyleSheetImpl::List(FILE* out, PRInt32 aIndent) const while (index < PRInt32(count)) { nsCOMPtr medium = dont_AddRef((nsIAtom*)mMedia->ElementAt(index++)); medium->ToString(buffer); - fputs(buffer, out); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out); if (index < PRInt32(count)) { fputs(", ", out); } diff --git a/layout/style/nsStyleContext.cpp b/layout/style/nsStyleContext.cpp index dd3183473eae..142520b60984 100644 --- a/layout/style/nsStyleContext.cpp +++ b/layout/style/nsStyleContext.cpp @@ -841,7 +841,7 @@ void nsStyleContext::List(FILE* out, PRInt32 aIndent) if (nsnull != mPseudoTag) { nsAutoString buffer; mPseudoTag->ToString(buffer); - fputs(buffer, out); + fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out); fputs(" ", out); } diff --git a/layout/xul/base/src/nsBox.cpp b/layout/xul/base/src/nsBox.cpp index 14ac7b82f575..aa6e6ac102f1 100644 --- a/layout/xul/base/src/nsBox.cpp +++ b/layout/xul/base/src/nsBox.cpp @@ -131,9 +131,7 @@ nsBox::DumpBox(FILE* aFile) { nsAutoString s; ListBox(s); - char ch[1000]; - s.ToCString(ch,1000); - fprintf(aFile, "%s", ch); + fprintf(aFile, "%s", NS_LossyConvertUCS2toASCII(s).get()); return NS_OK; } diff --git a/modules/plugin/base/src/nsPluginHostImpl.cpp b/modules/plugin/base/src/nsPluginHostImpl.cpp index 5fbc7de99905..574db12d929a 100644 --- a/modules/plugin/base/src/nsPluginHostImpl.cpp +++ b/modules/plugin/base/src/nsPluginHostImpl.cpp @@ -3505,8 +3505,6 @@ NS_IMETHODIMP nsPluginHostImpl::SetUpPluginInstance(const char *aMimeType, nsIPluginInstance* instance = NULL; nsCOMPtr plugin; const char* mimetype; - nsString strContractID; strContractID.AssignWithConversion (NS_INLINE_PLUGIN_CONTRACTID_PREFIX); - char buf[255]; // todo: need to use a const if(!aURL) return NS_ERROR_FAILURE; @@ -3534,15 +3532,13 @@ NS_IMETHODIMP nsPluginHostImpl::SetUpPluginInstance(const char *aMimeType, else mimetype = aMimeType; - strContractID.AppendWithConversion(mimetype); - strContractID.ToCString(buf, 255); // todo: need to use a const + nsCAutoString contractID( + NS_LITERAL_CSTRING(NS_INLINE_PLUGIN_CONTRACTID_PREFIX) + + nsDependentCString(mimetype)); - GetPluginFactory(mimetype, getter_AddRefs(plugin)); + GetPluginFactory(mimetype, getter_AddRefs(plugin)); - result = nsComponentManager::CreateInstance(buf, - nsnull, - nsIPluginInstance::GetIID(), - (void**)&instance); + result = CallCreateInstance(contractID.get(), &instance); #ifdef XP_WIN PRBool isJavaPlugin = PR_FALSE; @@ -3662,20 +3658,18 @@ nsresult nsPluginHostImpl::SetUpDefaultPluginInstance(const char *aMimeType, nsI nsIPluginInstance* instance = NULL; nsCOMPtr plugin = NULL; const char* mimetype; - nsString strContractID; strContractID.AssignWithConversion (NS_INLINE_PLUGIN_CONTRACTID_PREFIX); - char buf[255]; // todo: need to use a const if(!aURL) return NS_ERROR_FAILURE; mimetype = aMimeType; - strContractID.AppendWithConversion("*"); - strContractID.ToCString(buf, 255); // todo: need to use a const + nsCAutoString contractID( + NS_LITERAL_CSTRING(NS_INLINE_PLUGIN_CONTRACTID_PREFIX "*")); GetPluginFactory("*", getter_AddRefs(plugin)); - result = nsComponentManager::CreateInstance(buf, nsnull, nsIPluginInstance::GetIID(), (void**)&instance); + result = CallCreateInstance(contractID, &instance); // couldn't create an XPCOM plugin, try to create wrapper for a legacy plugin if (NS_FAILED(result)) @@ -4184,12 +4178,11 @@ NS_IMETHODIMP nsPluginHostImpl::GetPluginFactory(const char *aMimeType, nsIPlugi // nsIPlugin* of xpcom plugins can be found thru a call to // nsComponentManager::GetClassObject() nsCID clsid; - char buf[255]; - nsString strContractID; - strContractID.AssignWithConversion (NS_INLINE_PLUGIN_CONTRACTID_PREFIX); - strContractID.AppendWithConversion(aMimeType); - strContractID.ToCString(buf, 255); - nsresult rv = nsComponentManager::ContractIDToClassID(buf, &clsid); + nsCAutoString contractID( + NS_LITERAL_CSTRING(NS_INLINE_PLUGIN_CONTRACTID_PREFIX) + + nsDependentCString(aMimeType)); + nsresult rv = + nsComponentManager::ContractIDToClassID(contractID.get(), &clsid); if (NS_SUCCEEDED(rv)) { rv = nsComponentManager::GetClassObject(clsid, nsIPlugin::GetIID(), (void**)&plugin); diff --git a/netwerk/base/src/nsIOService.cpp b/netwerk/base/src/nsIOService.cpp index 01a14ea1e97b..30e396f6e578 100644 --- a/netwerk/base/src/nsIOService.cpp +++ b/netwerk/base/src/nsIOService.cpp @@ -292,10 +292,6 @@ NS_IMPL_THREADSAFE_ISUPPORTS3(nsIOService, //////////////////////////////////////////////////////////////////////////////// -#define MAX_SCHEME_LENGTH 64 // XXX big enough? - -#define MAX_NET_CONTRACTID_LENGTH (MAX_SCHEME_LENGTH + NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX_LENGTH + 1) - NS_IMETHODIMP nsIOService::CacheProtocolHandler(const char *scheme, nsIProtocolHandler *handler) { @@ -408,20 +404,19 @@ nsIOService::GetProtocolHandler(const char* scheme, nsIProtocolHandler* *result) rv = GetCachedProtocolHandler(scheme, result); if (NS_SUCCEEDED(rv)) return NS_OK; - char buf[MAX_NET_CONTRACTID_LENGTH]; nsCAutoString contractID(NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX); contractID += scheme; contractID.ToLowerCase(); - contractID.ToCString(buf, MAX_NET_CONTRACTID_LENGTH); - rv = nsServiceManager::GetService(buf, NS_GET_IID(nsIProtocolHandler), (nsISupports **)result); + rv = CallGetService(contractID.get(), result); if (NS_FAILED(rv)) { // okay we don't have a protocol handler to handle this url type, so use the default protocol handler. // this will cause urls to get dispatched out to the OS ('cause we can't do anything with them) when // we try to read from a channel created by the default protocol handler. - rv = nsServiceManager::GetService(NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX"default", NS_GET_IID(nsIProtocolHandler), (nsISupports **)result); + rv = CallGetService(NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX"default", + result); if (NS_FAILED(rv)) return NS_ERROR_UNKNOWN_PROTOCOL; } diff --git a/netwerk/socket/base/nsSocketProviderService.cpp b/netwerk/socket/base/nsSocketProviderService.cpp index 210fed9e08b3..a2e6d64274e3 100644 --- a/netwerk/socket/base/nsSocketProviderService.cpp +++ b/netwerk/socket/base/nsSocketProviderService.cpp @@ -89,25 +89,16 @@ NS_IMPL_THREADSAFE_ISUPPORTS1(nsSocketProviderService, nsISocketProviderService) //////////////////////////////////////////////////////////////////////////////// -#define MAX_TYPE_LENGTH 128 - -#define MAX_SOCKET_TYPE_CONTRACTID_LENGTH (MAX_TYPE_LENGTH + NS_NETWORK_SOCKET_CONTRACTID_PREFIX_LENGTH + 1) - NS_IMETHODIMP nsSocketProviderService::GetSocketProvider(const char *aSocketType, nsISocketProvider **_result) { nsresult rv; - char buf[MAX_SOCKET_TYPE_CONTRACTID_LENGTH]; + nsCAutoString contractID( + nsDependentCString(NS_NETWORK_SOCKET_CONTRACTID_PREFIX) + + nsDependentCString(aSocketType)); - // STRING USE WARNING: perhaps |contractID| should be an |nsCAutoString| -- scc - nsAutoString contractID; - contractID.AssignWithConversion(NS_NETWORK_SOCKET_CONTRACTID_PREFIX); - - contractID.AppendWithConversion(aSocketType); - contractID.ToCString(buf, MAX_SOCKET_TYPE_CONTRACTID_LENGTH); - - rv = nsServiceManager::GetService(buf, NS_GET_IID(nsISocketProvider), (nsISupports **)_result); + rv = CallGetService(contractID.get(), _result); if (NS_FAILED(rv)) return NS_ERROR_UNKNOWN_SOCKET_TYPE; diff --git a/parser/htmlparser/robot/nsDebugRobot.cpp b/parser/htmlparser/robot/nsDebugRobot.cpp index 43b3ab9ef424..7a6222ad0441 100644 --- a/parser/htmlparser/robot/nsDebugRobot.cpp +++ b/parser/htmlparser/robot/nsDebugRobot.cpp @@ -117,7 +117,7 @@ NS_IMETHODIMP RobotSinkObserver::ProcessLink(const nsString& aURLSpec) nsString * pstr = (nsString *)g_duplicateList->ElementAt(n); if (pstr->Equals(aURLSpec)) { fputs ("Robot: (duplicate '",stdout); - fputs (aURLSpec,stdout); + fputs (NS_LossyConvertUCS2toASCII(aURLSpec).get(),stdout); fputs ("')\n",stdout); return NS_OK; } @@ -134,7 +134,7 @@ NS_IMETHODIMP RobotSinkObserver::ProcessLink(const nsString& aURLSpec) } else { fputs ("Robot: (cannot process URL types '",stdout); - fputs (aURLSpec,stdout); + fputs (NS_LossyConvertUCS2toASCII(aURLSpec).get(),stdout); fputs ("')\n",stdout); } } @@ -273,7 +273,7 @@ extern "C" NS_EXPORT int DebugRobot( NS_RELEASE(uri); if (NS_OK != rv) { printf("invalid URL: '"); - fputs(*urlName, stdout); + fputs(NS_LossyConvertUCS2toASCII(*urlName).get(), stdout); printf("'\n"); NS_RELEASE(myObserver); return -1; @@ -284,7 +284,7 @@ extern "C" NS_EXPORT int DebugRobot( fputs ("Robot: parsing(",stdout); fputs (str_num,stdout); fputs (") ",stdout); - fputs (*urlName,stdout); + fputs (NS_LossyConvertUCS2toASCII(*urlName).get(),stdout); fputs ("...",stdout); delete urlName; diff --git a/parser/htmlparser/src/nsHTMLTokens.cpp b/parser/htmlparser/src/nsHTMLTokens.cpp index 4982ac32cd80..afc822a6dbaf 100644 --- a/parser/htmlparser/src/nsHTMLTokens.cpp +++ b/parser/htmlparser/src/nsHTMLTokens.cpp @@ -256,9 +256,7 @@ nsresult CStartToken::Consume(PRUnichar aChar, nsScanner& aScanner,PRInt32 aFlag * @return */ void CStartToken::DebugDumpSource(nsOutputStream& out) { - char buffer[1000]; - mTextValue.ToCString(buffer,sizeof(buffer)); - out << "<" << buffer; + out << "<" << NS_LossyConvertUCS2toASCII(mTextValue).get(); if(!mAttributed) out << ">"; } @@ -445,9 +443,7 @@ PRInt32 CEndToken::GetTokenType(void) { * @return */ void CEndToken::DebugDumpSource(nsOutputStream& out) { - char buffer[1000]; - mTextValue.ToCString(buffer,sizeof(buffer)); - out << ""; + out << ""; } const nsAReadableString& CEndToken::GetStringValue() @@ -1444,12 +1440,10 @@ void CAttributeToken::SanitizeKey() { * @return */ void CAttributeToken::DebugDumpToken(nsOutputStream& out) { - char buffer[200]; - nsCAutoString str; - CopyUCS2toASCII(mTextKey, str); - out << "[" << GetClassName() << "] " << str.get() << "="; - mTextValue.ToCString(buffer,sizeof(buffer)); - out << buffer << ": " << mTypeID << nsEndl; + out << "[" << GetClassName() << "] " + << NS_LossyConvertUCS2toASCII(mTextKey).get() << "=" + << NS_LossyConvertUCS2toASCII(mTextValue).get() << ": " << mTypeID + << nsEndl; } const nsAReadableString& CAttributeToken::GetStringValue(void) @@ -1782,16 +1776,12 @@ nsresult CAttributeToken::Consume(PRUnichar aChar, nsScanner& aScanner,PRInt32 a * @return */ void CAttributeToken::DebugDumpSource(nsOutputStream& out) { - static char buffer[1000]; - nsCAutoString str; - CopyUCS2toASCII(mTextKey, str); - out << " " << str.get(); - if(mTextValue.Length()){ - mTextValue.ToCString(buffer,sizeof(buffer)); - out << "=" << buffer; + out << " " << NS_LossyConvertUCS2toASCII(mTextKey).get(); + if (!mTextValue.IsEmpty()) { + out << "=" << NS_LossyConvertUCS2toASCII(mTextValue).get(); } if(mLastAttribute) - out<<">"; + out << ">"; } void CAttributeToken::SetKey(const nsAReadableString& aKey) diff --git a/rdf/base/src/nsRDFContentSink.cpp b/rdf/base/src/nsRDFContentSink.cpp index cf2a029c6c7b..50deaeece66f 100644 --- a/rdf/base/src/nsRDFContentSink.cpp +++ b/rdf/base/src/nsRDFContentSink.cpp @@ -706,13 +706,13 @@ RDFContentSinkImpl::AddDocTypeDecl(const nsIParserNode& aNode, PRInt32 aMode) NS_IMETHODIMP RDFContentSinkImpl::AddCharacterData(const nsIParserNode& aNode) { - nsAutoString text(aNode.GetText()); + nsAutoString text; if (aNode.GetTokenType() == eToken_entity) { - char buf[12]; - text.ToCString(buf, sizeof(buf)); - text.Truncate(); - text.Append(rdf_EntityToUnicode(buf)); + text = rdf_EntityToUnicode( + NS_LossyConvertUCS2toASCII(aNode.GetText()).get()); + } else { + text = aNode.GetText(); } PRInt32 addLen = text.Length(); diff --git a/rdf/base/src/nsRDFService.cpp b/rdf/base/src/nsRDFService.cpp index e932e5f1ec5a..3140d9d697a2 100644 --- a/rdf/base/src/nsRDFService.cpp +++ b/rdf/base/src/nsRDFService.cpp @@ -1183,30 +1183,19 @@ RDFServiceImpl::GetDataSource(const char* aURI, nsIRDFDataSource** aDataSource) nsAutoString dataSourceName; rdfName.Right(dataSourceName, rdfName.Length() - (pos + sizeof(kRDFPrefix) - 1)); - nsAutoString contractIDStr; contractIDStr.AssignWithConversion(NS_RDF_DATASOURCE_CONTRACTID_PREFIX); - contractIDStr.Append(dataSourceName); - // Safely convert it to a C-string for the XPCOM APIs - char buf[64]; - char* contractID = buf, *p; - if (contractIDStr.Length() >= PRInt32(sizeof buf)) - contractID = (char *)nsMemory::Alloc(contractIDStr.Length() + 1); - - if (contractID == nsnull) - return NS_ERROR_OUT_OF_MEMORY; - - contractIDStr.ToCString(contractID, contractIDStr.Length() + 1); + nsCAutoString contractID( + NS_LITERAL_CSTRING(NS_RDF_DATASOURCE_CONTRACTID_PREFIX) + + NS_LossyConvertUCS2toASCII(dataSourceName)); /* strip params to get ``base'' contractID for data source */ - p = PL_strchr(contractID, '&'); - if (p) - *p = '\0'; + PRInt32 p = contractID.FindChar(PRUnichar('&')); + if (p != kNotFound) + contractID.Truncate(p); nsCOMPtr isupports; - rv = nsServiceManager::GetService(contractID, kISupportsIID, getter_AddRefs(isupports), nsnull); - - if (contractID != buf) - nsCRT::free(contractID); + rv = nsServiceManager::GetService(contractID.get(), kISupportsIID, + getter_AddRefs(isupports), nsnull); if (NS_FAILED(rv)) return rv; diff --git a/webshell/tests/viewer/nsBrowserWindow.cpp b/webshell/tests/viewer/nsBrowserWindow.cpp index 1485cd90629b..cd445e5a8317 100644 --- a/webshell/tests/viewer/nsBrowserWindow.cpp +++ b/webshell/tests/viewer/nsBrowserWindow.cpp @@ -2520,7 +2520,7 @@ static void DumpAWebShell(nsIDocShellTreeItem* aShellItem, FILE* out, PRInt32 aI aShellItem->GetName(getter_Copies(name)); aShellItem->GetSameTypeParent(getter_AddRefs(parent)); str.Assign(name); - fputs(str, out); + fputs(NS_LossyConvertUCS2toASCII(str).get(), out); fprintf(out, "' parent=%p <\n", parent.get()); aIndent++; @@ -2745,11 +2745,10 @@ static void ShowReport(FILE* out, nsISizeOfHandler* aHandler) for (; entry < end; entry++) { nsAutoString type; entry->mKey->ToString(type); - char cbuf[20]; - type.ToCString(cbuf, sizeof(cbuf)); fprintf(out, "%-20s %5d %9d %7d %7d %7d\n", - cbuf, entry->mCount, entry->mTotalSize, + NS_LossyConvertUCS2toASCII(type).get(), + entry->mCount, entry->mTotalSize, entry->mMinSize, entry->mMaxSize, entry->mCount ? entry->mTotalSize / entry->mCount : 0); } @@ -3430,7 +3429,7 @@ nsBrowserWindow::DispatchStyleMenu(PRInt32 aID) fprintf(stdout, "%d: \"", index + 1); nsAutoString title; titles.StringAt(index, title); - fputs(title, stdout); + fputs(NS_LossyConvertUCS2toASCII(title).get(), stdout); fprintf(stdout, "\" %s%s\n", ((title.EqualsIgnoreCase(current)) ? "<< current " : ""), ((title.EqualsIgnoreCase(defaultStyle)) ? "** default" : "")); @@ -3453,7 +3452,7 @@ nsBrowserWindow::DispatchStyleMenu(PRInt32 aID) doc->GetHeaderData(defStyleAtom, defaultStyle); NS_RELEASE(defStyleAtom); fputs("Selecting default style sheet \"", stdout); - fputs(defaultStyle, stdout); + fputs(NS_LossyConvertUCS2toASCII(defaultStyle).get(), stdout); fputs("\"\n", stdout); shell->SelectAlternateStyleSheet(defaultStyle); } @@ -3475,7 +3474,7 @@ nsBrowserWindow::DispatchStyleMenu(PRInt32 aID) nsAutoString title; titles.StringAt(aID - VIEWER_SELECT_STYLE_ONE, title); fputs("Selecting alternate style sheet \"", stdout); - fputs(title, stdout); + fputs(NS_LossyConvertUCS2toASCII(title).get(), stdout); fputs("\"\n", stdout); shell->SelectAlternateStyleSheet(title); NS_RELEASE(shell); diff --git a/webshell/tests/viewer/nsViewerApp.cpp b/webshell/tests/viewer/nsViewerApp.cpp index 5de25c5cebe4..40354066a232 100644 --- a/webshell/tests/viewer/nsViewerApp.cpp +++ b/webshell/tests/viewer/nsViewerApp.cpp @@ -394,17 +394,16 @@ PrintHelpInfo(char **argv) static void AddTestDocsFromFile(nsWebCrawler* aCrawler, const nsString& aFileName) { - char cfn[1000]; - aFileName.ToCString(cfn, sizeof(cfn)); + NS_LossyConvertUCS2toASCII cfn(aFileName); #ifdef XP_PC - FILE* fp = fopen(cfn, "rb"); + FILE* fp = fopen(cfn.get(), "rb"); #else - FILE* fp = fopen(cfn, "r"); + FILE* fp = fopen(cfn.get(), "r"); #endif if (nsnull==fp) { - fprintf(stderr, "Input file not found: %s\n", cfn); + fprintf(stderr, "Input file not found: %s\n", cfn.get()); exit (-1); } nsAutoString line; diff --git a/webshell/tests/viewer/nsWebBrowserChrome.cpp b/webshell/tests/viewer/nsWebBrowserChrome.cpp index b64ae702560e..18c94bfade46 100644 --- a/webshell/tests/viewer/nsWebBrowserChrome.cpp +++ b/webshell/tests/viewer/nsWebBrowserChrome.cpp @@ -602,7 +602,7 @@ void nsWebBrowserChrome::OnLoadFinished(nsIRequest* aRequest, if(mBrowserWindow->mShowLoadTimes) { printf("Loading "); - fputs(msg, stdout); + fputs(NS_LossyConvertUCS2toASCII(msg).get(), stdout); PRTime delta; LL_SUB(delta, endLoadTime, mBrowserWindow->mLoadStartTime); double usecs; diff --git a/webshell/tests/viewer/nsWebCrawler.cpp b/webshell/tests/viewer/nsWebCrawler.cpp index d704881b6581..f2bd4fc83d8c 100644 --- a/webshell/tests/viewer/nsWebCrawler.cpp +++ b/webshell/tests/viewer/nsWebCrawler.cpp @@ -282,7 +282,8 @@ nsWebCrawler::DumpRegressionData() PerformRegressionTest(regressionFileName); } else { - fputs(regressionFileName, stdout); + fputs(NS_LossyConvertUCS2toASCII(regressionFileName).get(), + stdout); printf(" - being written\n"); } } @@ -561,7 +562,7 @@ nsWebCrawler::AddURL(const nsString& aURL) mPendingURLs.AppendElement(url); if (mVerbose) { printf("WebCrawler: adding '"); - fputs(aURL, stdout); + fputs(NS_LossyConvertUCS2toASCII(aURL).get(), stdout); printf("'\n"); } } @@ -702,7 +703,7 @@ nsWebCrawler::OkToLoad(const nsString& aURLSpec) nsString* s = (nsString*) mAvoidDomains.ElementAt(i); if (s && EndsWith(*s, host, hostlen)) { printf("Avoiding '"); - fputs(aURLSpec, stdout); + fputs(NS_LossyConvertUCS2toASCII(aURLSpec).get(), stdout); printf("'\n"); return PR_FALSE; } @@ -732,7 +733,7 @@ void nsWebCrawler::RecordLoadedURL(const nsString& aURL) { if (nsnull != mRecord) { - fputs(aURL, mRecord); + fputs(NS_LossyConvertUCS2toASCII(aURL).get(), mRecord); fputs("\n", mRecord); fflush(mRecord); } @@ -765,14 +766,14 @@ nsWebCrawler::FindURLsIn(nsIDocument* aDocument, nsIContent* aNode) mPendingURLs.AppendElement(new nsString(absURLSpec)); if (mVerbose) { printf("Adding '"); - fputs(absURLSpec, stdout); + fputs(NS_LossyConvertUCS2toASCII(absURLSpec).get(), stdout); printf("'\n"); } } else { if (mVerbose) { printf("Skipping '"); - fputs(absURLSpec, stdout); + fputs(NS_LossyConvertUCS2toASCII(absURLSpec).get(), stdout); printf("'\n"); } } @@ -780,7 +781,7 @@ nsWebCrawler::FindURLsIn(nsIDocument* aDocument, nsIContent* aNode) else { if (mVerbose) { printf("Already visited '"); - fputs(absURLSpec, stdout); + fputs(NS_LossyConvertUCS2toASCII(absURLSpec).get(), stdout); printf("'\n"); } } diff --git a/webshell/tests/viewer/windows/nsButton.cpp b/webshell/tests/viewer/windows/nsButton.cpp index e781e5f187b0..2aae3fd01e2a 100644 --- a/webshell/tests/viewer/windows/nsButton.cpp +++ b/webshell/tests/viewer/windows/nsButton.cpp @@ -131,9 +131,7 @@ NS_METHOD nsButton::SetLabel(const nsString& aText) if (NULL == mWnd) { return NS_ERROR_FAILURE; } - NS_ALLOC_STR_BUF(label, aText, 256); - VERIFY(::SetWindowText(mWnd, label)); - NS_FREE_STR_BUF(label); + VERIFY(::SetWindowText(mWnd, NS_LossyConvertUCS2toASCII(aText).get())); return NS_OK; } diff --git a/webshell/tests/viewer/windows/nsLabel.cpp b/webshell/tests/viewer/windows/nsLabel.cpp index 55c412d08013..c9eed40697c0 100644 --- a/webshell/tests/viewer/windows/nsLabel.cpp +++ b/webshell/tests/viewer/windows/nsLabel.cpp @@ -136,9 +136,7 @@ NS_METHOD nsLabel::SetAlignment(nsLabelAlignment aAlignment) //------------------------------------------------------------------------- NS_METHOD nsLabel::SetLabel(const nsString& aText) { - NS_ALLOC_STR_BUF(label, aText, 256); - VERIFY(::SetWindowText(mWnd, label)); - NS_FREE_STR_BUF(label); + VERIFY(::SetWindowText(mWnd, NS_LossyConvertUCS2toASCII(aText).get())); return NS_OK; } diff --git a/webshell/tests/viewer/windows/nsTextHelper.cpp b/webshell/tests/viewer/windows/nsTextHelper.cpp index c1ab01233609..b63a8415fc62 100644 --- a/webshell/tests/viewer/windows/nsTextHelper.cpp +++ b/webshell/tests/viewer/windows/nsTextHelper.cpp @@ -77,9 +77,7 @@ NS_METHOD nsTextHelper::SetText(const nsString &aText, PRUint32& aActualSize) { mText = aText; - NS_ALLOC_STR_BUF(buf, aText, 512); - SetWindowText(mWnd, buf); - NS_FREE_STR_BUF(buf); + SetWindowText(mWnd, NS_LossyConvertUCS2toASCII(aText).get()); aActualSize = aText.Length(); return NS_OK; } diff --git a/widget/public/nsStringUtil.h b/widget/public/nsStringUtil.h index fc84b9229f56..9165aa90b306 100644 --- a/widget/public/nsStringUtil.h +++ b/widget/public/nsStringUtil.h @@ -41,13 +41,12 @@ #ifndef NS_STR_UTIL_H #define NS_STR_UTIL_H -// nsString to temporary char[] macro +// temporary char[] macro -// Convience MACROS to convert an nsString to a char * which use a -// static char array if possible to reduce memory fragmentation, -// otherwise they allocate a char[] which must be freed. -// REMEMBER to always use the NS_FREE_STR_BUF after using the -// NS_ALLOC_STR_BUF. You can not nest NS_ALLOC_STR_BUF's. +// Convience MACROS which use a static char array if possible to reduce +// memory fragmentation, otherwise they allocate a char[] which must be +// freed. REMEMBER to always use the NS_FREE_CHAR_BUF after using the +// NS_ALLOC_CHAR_BUF. You can not nest NS_ALLOC_CHAR_BUF's. #define NS_ALLOC_CHAR_BUF(aBuf, aSize, aActualSize) \ int _ns_tmpActualSize = aActualSize; \ @@ -58,12 +57,4 @@ if (aBuf != _ns_smallBuffer) \ delete[] aBuf; -#define NS_ALLOC_STR_BUF(aBuf, aStrName, aTempSize) \ - NS_ALLOC_CHAR_BUF(aBuf, aTempSize, aStrName.Length()+1); \ - aStrName.ToCString(aBuf, aStrName.Length()+1); - -#define NS_FREE_STR_BUF(aBuf) \ - NS_FREE_CHAR_BUF(aBuf) - - -#endif // NSStringUtil +#endif // !defined(NS_STR_UTIL_H) diff --git a/widget/src/beos/nsButton.cpp b/widget/src/beos/nsButton.cpp index 07a614cf4e33..bb3042a6bd2c 100644 --- a/widget/src/beos/nsButton.cpp +++ b/widget/src/beos/nsButton.cpp @@ -40,7 +40,6 @@ #include "nsColor.h" #include "nsGUIEvent.h" #include "nsString.h" -#include "nsStringUtil.h" #include "nsILookAndFeel.h" #include "nsWidgetsCID.h" @@ -111,18 +110,16 @@ NS_METHOD nsButton::SetLabel(const nsString& aText) if(NULL == mView) { return NS_ERROR_FAILURE; } - NS_ALLOC_STR_BUF(label, aText, 256); if(mButton) { if(mButton->Looper()) mButton->LockLooper(); - mButton->SetLabel(label); + mButton->SetLabel(NS_LossyConvertUCS2toASCII(aText).get()); if(mButton->Looper()) mButton->UnlockLooper(); } - NS_FREE_STR_BUF(label); return NS_OK; } diff --git a/widget/src/beos/nsCheckButton.cpp b/widget/src/beos/nsCheckButton.cpp index f56035c67681..f45c5ba98bb1 100644 --- a/widget/src/beos/nsCheckButton.cpp +++ b/widget/src/beos/nsCheckButton.cpp @@ -40,7 +40,6 @@ #include "nsColor.h" #include "nsGUIEvent.h" #include "nsString.h" -#include "nsStringUtil.h" #include "nsILookAndFeel.h" #include "nsWidgetsCID.h" @@ -136,12 +135,10 @@ NS_METHOD nsCheckButton::GetState(PRBool& aState) //------------------------------------------------------------------------- NS_METHOD nsCheckButton::SetLabel(const nsString& aText) { - char label[256]; - aText.ToCString(label, 256); - label[255] = '\0'; if(mCheckBox && mCheckBox->LockLooper()) { - mCheckBox->SetLabel(label); + mCheckBox->SetLabel( + NS_LossyConvertUCS2toASCII(Substring(aText,0,255)).get()); mCheckBox->UnlockLooper(); } return NS_OK; diff --git a/widget/src/beos/nsLabel.cpp b/widget/src/beos/nsLabel.cpp index 789ddf4c79f8..f1fffaff4808 100644 --- a/widget/src/beos/nsLabel.cpp +++ b/widget/src/beos/nsLabel.cpp @@ -41,7 +41,6 @@ #include "nsColor.h" #include "nsGUIEvent.h" #include "nsString.h" -#include "nsStringUtil.h" #include "nsIFontMetrics.h" #include "nsIDeviceContext.h" @@ -118,12 +117,10 @@ NS_METHOD nsLabel::SetAlignment(nsLabelAlignment aAlignment) //------------------------------------------------------------------------- NS_METHOD nsLabel::SetLabel(const nsString& aText) { - char label[256]; - aText.ToCString(label, 256); - label[255] = '\0'; if(mStringView && mStringView->LockLooper()) { - mStringView->SetText(label); + mStringView->SetText( + NS_LossyConvertUCS2toASCII(Substring(aText,0,255)).get()); mStringView->UnlockLooper(); } return NS_OK; diff --git a/widget/src/beos/nsPopUpMenu.cpp b/widget/src/beos/nsPopUpMenu.cpp index bf82f5554c89..d56639e4c4dd 100644 --- a/widget/src/beos/nsPopUpMenu.cpp +++ b/widget/src/beos/nsPopUpMenu.cpp @@ -43,7 +43,6 @@ #include "nsGUIEvent.h" #include "nsString.h" #include "nsReadableUtils.h" -#include "nsStringUtil.h" #include "nsIAppShell.h" #include "nsGUIEvent.h" diff --git a/widget/src/beos/nsTextHelper.cpp b/widget/src/beos/nsTextHelper.cpp index f6d7579f8473..94ac341e4fea 100644 --- a/widget/src/beos/nsTextHelper.cpp +++ b/widget/src/beos/nsTextHelper.cpp @@ -41,7 +41,6 @@ #include "nsGUIEvent.h" #include "nsString.h" #include "nsReadableUtils.h" -#include "nsStringUtil.h" #include NS_METHOD nsTextHelper::PreCreateWidget(nsWidgetInitData *aInitData) diff --git a/widget/src/beos/nsWindow.cpp b/widget/src/beos/nsWindow.cpp index 067a3e85c051..805f57a46965 100644 --- a/widget/src/beos/nsWindow.cpp +++ b/widget/src/beos/nsWindow.cpp @@ -46,7 +46,6 @@ #include "nsRect.h" #include "nsIRegion.h" #include "nsTransform2D.h" -#include "nsStringUtil.h" //#include "sysmets.h" #include "nsGfxCIID.h" #include "resource.h" diff --git a/widget/src/beos/nsWindow.h b/widget/src/beos/nsWindow.h index 5a28e076327a..320490e26e7b 100644 --- a/widget/src/beos/nsWindow.h +++ b/widget/src/beos/nsWindow.h @@ -49,7 +49,6 @@ #include "nsIMouseListener.h" #include "nsIEventListener.h" -#include "nsStringUtil.h" #include "nsString.h" #include "nsVoidArray.h" diff --git a/widget/src/gtk/nsButton.cpp b/widget/src/gtk/nsButton.cpp index 108df86cc5e8..7e688f2c1bf7 100644 --- a/widget/src/gtk/nsButton.cpp +++ b/widget/src/gtk/nsButton.cpp @@ -120,11 +120,8 @@ void nsButton::InitCallbacks(char * aName) //------------------------------------------------------------------------- NS_IMETHODIMP nsButton::SetLabel(const nsString& aText) { - NS_ALLOC_STR_BUF(label, aText, 256); - - gtk_label_set(GTK_LABEL(GTK_BIN (mWidget)->child), label); - - NS_FREE_STR_BUF(label); + gtk_label_set(GTK_LABEL(GTK_BIN (mWidget)->child), + NS_LossyConvertUCS2toASCII(aText).get()); return (NS_OK); } diff --git a/widget/src/gtk/nsCheckButton.cpp b/widget/src/gtk/nsCheckButton.cpp index 2bcf0bc8dd2e..831211535ae7 100644 --- a/widget/src/gtk/nsCheckButton.cpp +++ b/widget/src/gtk/nsCheckButton.cpp @@ -169,11 +169,11 @@ NS_METHOD nsCheckButton::GetState(PRBool& aState) NS_METHOD nsCheckButton::SetLabel(const nsString& aText) { if (mWidget) { - NS_ALLOC_STR_BUF(label, aText, 256); + NS_LossyConvertUCS2toASCII label(aText); if (mLabel) { - gtk_label_set(GTK_LABEL(mLabel), label); + gtk_label_set(GTK_LABEL(mLabel), label.get()); } else { - mLabel = gtk_label_new(label); + mLabel = gtk_label_new(label.get()); gtk_misc_set_alignment (GTK_MISC (mLabel), 0.0, 0.5); gtk_container_add(GTK_CONTAINER(mCheckButton), mLabel); gtk_widget_show(mLabel); @@ -182,7 +182,6 @@ NS_METHOD nsCheckButton::SetLabel(const nsString& aText) GTK_SIGNAL_FUNC(DestroySignal), this); } - NS_FREE_STR_BUF(label); } return NS_OK; } diff --git a/widget/src/gtk/nsLabel.cpp b/widget/src/gtk/nsLabel.cpp index de0298b3350b..b868867acebd 100644 --- a/widget/src/gtk/nsLabel.cpp +++ b/widget/src/gtk/nsLabel.cpp @@ -134,9 +134,8 @@ GtkJustification nsLabel::GetNativeAlignment() //------------------------------------------------------------------------- NS_METHOD nsLabel::SetLabel(const nsString& aText) { - NS_ALLOC_STR_BUF(label, aText, 256); - gtk_label_set(GTK_LABEL(mWidget), label); - NS_FREE_STR_BUF(label); + gtk_label_set(GTK_LABEL(mWidget), + NS_LossyConvertUCS2toASCII(aText).get()); return NS_OK; } diff --git a/widget/src/mac/nsFilePicker.cpp b/widget/src/mac/nsFilePicker.cpp index 6b0767b060ab..e05b99ec8a7b 100644 --- a/widget/src/mac/nsFilePicker.cpp +++ b/widget/src/mac/nsFilePicker.cpp @@ -29,7 +29,6 @@ #include "nsILocalFileMac.h" #include "nsIURL.h" #include "nsVoidArray.h" -#include "nsStringUtil.h" #include "nsIFileChannel.h" #include diff --git a/widget/src/mac/nsMacControl.cpp b/widget/src/mac/nsMacControl.cpp index c416b10d5168..0b5befd3d1e8 100644 --- a/widget/src/mac/nsMacControl.cpp +++ b/widget/src/mac/nsMacControl.cpp @@ -405,7 +405,6 @@ void nsMacControl::SetupMacControlFont() void nsMacControl::StringToStr255(const nsString& aText, Str255& aStr255) { - char buffer[256]; nsresult rv = NS_OK; // get file system charset and create a unicode encoder @@ -434,9 +433,9 @@ void nsMacControl::StringToStr255(const nsString& aText, Str255& aStr255) if (NS_FAILED(rv)) { // NS_ASSERTION(0, "error: charset covnersion"); - aText.ToCString(buffer, 255); - PRInt32 len = nsCRT::strlen(buffer); - memcpy(&aStr255[1], buffer, len); + NS_LossyConvertUCS2toASCII buffer(Substring(aText,0,254)); + PRInt32 len = buffer.Length(); + memcpy(&aStr255[1], buffer.get(), len); aStr255[0] = len; } } diff --git a/widget/src/mac/nsMenu.cpp b/widget/src/mac/nsMenu.cpp index 278b8a18ea19..bf7bcb7ab41a 100644 --- a/widget/src/mac/nsMenu.cpp +++ b/widget/src/mac/nsMenu.cpp @@ -55,7 +55,6 @@ #include "nsString.h" #include "nsReadableUtils.h" -#include "nsStringUtil.h" #include "nsINameSpaceManager.h" #include "nsWidgetAtoms.h" diff --git a/widget/src/mac/nsMenuBar.cpp b/widget/src/mac/nsMenuBar.cpp index 6eea9302d065..a10c3ce90fc9 100644 --- a/widget/src/mac/nsMenuBar.cpp +++ b/widget/src/mac/nsMenuBar.cpp @@ -50,7 +50,6 @@ #include "nsIWidget.h" #include "nsGUIEvent.h" #include "nsString.h" -#include "nsStringUtil.h" #include "nsIDocument.h" #include "nsIDocShell.h" #include "nsIDocumentViewer.h" diff --git a/widget/src/mac/nsMenuBarX.cpp b/widget/src/mac/nsMenuBarX.cpp index c638088c3d65..c0ad17cc8dd2 100644 --- a/widget/src/mac/nsMenuBarX.cpp +++ b/widget/src/mac/nsMenuBarX.cpp @@ -50,7 +50,6 @@ #include "nsISupports.h" #include "nsIWidget.h" #include "nsString.h" -#include "nsStringUtil.h" #include "nsIStringBundle.h" #include "nsIDocument.h" #include "nsIDocShell.h" diff --git a/widget/src/mac/nsMenuItem.cpp b/widget/src/mac/nsMenuItem.cpp index 89f7fc57c04d..b0ae9e767293 100644 --- a/widget/src/mac/nsMenuItem.cpp +++ b/widget/src/mac/nsMenuItem.cpp @@ -49,8 +49,6 @@ #include "nsDynamicMDEF.h" #include "nsGUIEvent.h" -#include "nsStringUtil.h" - #include "nsIDocument.h" #include "nsIDOMDocument.h" #include "nsINameSpaceManager.h" diff --git a/widget/src/mac/nsMenuItemX.cpp b/widget/src/mac/nsMenuItemX.cpp index a79fac24defb..cf69216e43a5 100644 --- a/widget/src/mac/nsMenuItemX.cpp +++ b/widget/src/mac/nsMenuItemX.cpp @@ -55,8 +55,6 @@ #include "nsGUIEvent.h" -#include "nsStringUtil.h" - #if DEBUG nsInstanceCounter gMenuItemCounterX("nsMenuItemX"); diff --git a/widget/src/mac/nsMenuX.cpp b/widget/src/mac/nsMenuX.cpp index 45d51fc1332e..b52b58c16cde 100644 --- a/widget/src/mac/nsMenuX.cpp +++ b/widget/src/mac/nsMenuX.cpp @@ -55,7 +55,7 @@ #include "nsString.h" #include "nsReadableUtils.h" -#include "nsStringUtil.h" +#include "plstr.h" #include "nsINameSpaceManager.h" #include "nsWidgetAtoms.h" diff --git a/widget/src/mac/nsTextHelper.cpp b/widget/src/mac/nsTextHelper.cpp index dfa13ddc3f96..972ea54ef367 100644 --- a/widget/src/mac/nsTextHelper.cpp +++ b/widget/src/mac/nsTextHelper.cpp @@ -44,7 +44,6 @@ #include "nsGUIEvent.h" #include "nsString.h" #include "nsReadableUtils.h" -#include "nsStringUtil.h" #define DBG 0 @@ -111,9 +110,7 @@ PRUint32 nsTextHelper::SetText(const nsString& aText) //printf("SetText Password %d\n", mIsPassword); if (!mIsPassword) { - NS_ALLOC_STR_BUF(buf, aText, 512); - //XmTextSetString(mWidget, buf); - NS_FREE_STR_BUF(buf); + //XmTextSetString(mWidget, NS_LossyConvertUCS2toASCII(aText).get()); } else { @@ -137,9 +134,7 @@ PRUint32 nsTextHelper::InsertText(const nsString &aText, PRUint32 aStartPos, PR if (!mIsPassword) { - NS_ALLOC_STR_BUF(buf, aText, 512); - //XmTextInsert(mWidget, aStartPos, buf); - NS_FREE_STR_BUF(buf); + //XmTextInsert(mWidget, aStartPos, NS_LossyConvertUCS2toASCII(aText).get()); } else { diff --git a/widget/src/mac/nsTextWidget.cpp b/widget/src/mac/nsTextWidget.cpp index e55ff941115f..d22d5ee022ce 100644 --- a/widget/src/mac/nsTextWidget.cpp +++ b/widget/src/mac/nsTextWidget.cpp @@ -304,7 +304,9 @@ PRBool nsTextWidget::DispatchWindowEvent(nsGUIEvent &aEvent) // now |selection| holds the current selection in unicode. // We need to convert it to a c-string for MacOS. auto_ptr cRepOfSelection(new char[selectionLen + 1]); - selection.ToCString(cRepOfSelection.get(), selectionLen + 1); + PL_strncpyz(cRepOfSelection.get(), + NS_LossyConvertUCS2toASCII(selection).get(), + selectionLen + 1); // copy it to the scrapMgr #if TARGET_CARBON @@ -573,22 +575,14 @@ NS_METHOD nsTextWidget::GetText(nsString& aTextBuffer, PRUint32 /*aBufferSize*/ NS_METHOD nsTextWidget::SetText(const nsString& aText, PRUint32& outSize) { outSize = aText.Length(); - const unsigned int bufferSize = outSize + 1; // add 1 for null if (!mControl) return NS_ERROR_NOT_INITIALIZED; - - auto_ptr str ( new char[bufferSize] ); - if ( str.get() ) - { - ResType textTag = (mIsPassword ? kControlEditTextPasswordTag : kControlEditTextTextTag); - aText.ToCString(str.get(), bufferSize); - ::SetControlData(mControl, kControlNoPart, textTag, outSize, (Ptr)str.get()); - Invalidate(PR_FALSE); - } - else - return NS_ERROR_OUT_OF_MEMORY; + ResType textTag = (mIsPassword ? kControlEditTextPasswordTag : kControlEditTextTextTag); + ::SetControlData(mControl, kControlNoPart, textTag, outSize, + (Ptr)NS_LossyConvertUCS2toASCII(aText).get()); + Invalidate(PR_FALSE); return NS_OK; } diff --git a/widget/src/os2/nsWindow.cpp b/widget/src/os2/nsWindow.cpp index 7c7ca533ce01..3f34b6d6b26f 100644 --- a/widget/src/os2/nsWindow.cpp +++ b/widget/src/os2/nsWindow.cpp @@ -50,7 +50,6 @@ #include "nsIDeviceContext.h" #include "nsRect.h" #include "nsTransform2D.h" -#include "nsStringUtil.h" #include "nsGfxCIID.h" #include "prtime.h" // #include "nsTooltipManager.h" diff --git a/widget/src/photon/nsButton.cpp b/widget/src/photon/nsButton.cpp index 7284a114b16c..8e13d71452c6 100644 --- a/widget/src/photon/nsButton.cpp +++ b/widget/src/photon/nsButton.cpp @@ -40,7 +40,6 @@ #include "nsColor.h" #include "nsGUIEvent.h" #include "nsString.h" -#include "nsStringUtil.h" #include #include "nsILookAndFeel.h" @@ -89,12 +88,9 @@ NS_METHOD nsButton::SetLabel(const nsString& aText) { PtArg_t arg; - NS_ALLOC_STR_BUF(label, aText, aText.Length()); - - PtSetArg( &arg, Pt_ARG_TEXT_STRING, label, 0 ); + PtSetArg( &arg, Pt_ARG_TEXT_STRING, + NS_LossyConvertUCS2toASCII(aText).get(), 0 ); PtSetResources( mWidget, 1, &arg ); - - NS_FREE_STR_BUF(label); } return NS_OK; diff --git a/widget/src/photon/nsCheckButton.cpp b/widget/src/photon/nsCheckButton.cpp index b33b1397d9cd..d2b4952c2a13 100644 --- a/widget/src/photon/nsCheckButton.cpp +++ b/widget/src/photon/nsCheckButton.cpp @@ -40,7 +40,6 @@ #include "nsColor.h" #include "nsGUIEvent.h" #include "nsString.h" -#include "nsStringUtil.h" #include #include "nsILookAndFeel.h" @@ -179,13 +178,10 @@ NS_METHOD nsCheckButton::SetLabel(const nsString& aText) { PtArg_t arg; - NS_ALLOC_STR_BUF(label, aText, aText.Length()); - - PtSetArg( &arg, Pt_ARG_TEXT_STRING, label, 0 ); + PtSetArg( &arg, Pt_ARG_TEXT_STRING, + NS_LossyConvertUCS2toASCII(aText).get(), 0 ); if( PtSetResources( mWidget, 1, &arg ) == 0 ) res = NS_OK; - - NS_FREE_STR_BUF(label); } return res; diff --git a/widget/src/photon/nsLabel.cpp b/widget/src/photon/nsLabel.cpp index 6661226770db..916294e20274 100644 --- a/widget/src/photon/nsLabel.cpp +++ b/widget/src/photon/nsLabel.cpp @@ -40,7 +40,6 @@ #include "nsColor.h" #include "nsGUIEvent.h" #include "nsString.h" -#include "nsStringUtil.h" #include #include "nsPhWidgetLog.h" @@ -167,13 +166,10 @@ NS_METHOD nsLabel::SetLabel(const nsString& aText) { PtArg_t arg; - NS_ALLOC_STR_BUF(label, aText, aText.Length()); - - PtSetArg( &arg, Pt_ARG_TEXT_STRING, label, 0 ); + PtSetArg( &arg, Pt_ARG_TEXT_STRING, + NS_LossyConvertUCS2toASCII(aText).get(), 0 ); if( PtSetResources( mWidget, 1, &arg ) == 0 ) res = NS_OK; - - NS_FREE_STR_BUF(label); } return res; diff --git a/widget/src/photon/nsMenu.cpp b/widget/src/photon/nsMenu.cpp index 27d14dcc18a7..e5929671a5c5 100644 --- a/widget/src/photon/nsMenu.cpp +++ b/widget/src/photon/nsMenu.cpp @@ -48,7 +48,6 @@ #include "nsGUIEvent.h" #include "nsString.h" #include "nsReadableUtils.h" -#include "nsStringUtil.h" #include "nsIAppShell.h" #include "nsGUIEvent.h" diff --git a/widget/src/photon/nsMenuBar.cpp b/widget/src/photon/nsMenuBar.cpp index c834f6c38ddc..b7989284a4b3 100644 --- a/widget/src/photon/nsMenuBar.cpp +++ b/widget/src/photon/nsMenuBar.cpp @@ -44,7 +44,6 @@ #include "nsIWidget.h" #include "nsString.h" -#include "nsStringUtil.h" #include "nsIComponentManager.h" #include "nsCOMPtr.h" diff --git a/widget/src/photon/nsMenuItem.cpp b/widget/src/photon/nsMenuItem.cpp index 73924269999c..2eb70387477d 100644 --- a/widget/src/photon/nsMenuItem.cpp +++ b/widget/src/photon/nsMenuItem.cpp @@ -42,8 +42,6 @@ #include "nsIMenuBar.h" #include "nsIWidget.h" -#include "nsStringUtil.h" - #include "nsIPopUpMenu.h" #include "nsCOMPtr.h" diff --git a/widget/src/photon/nsPopUpMenu.cpp b/widget/src/photon/nsPopUpMenu.cpp index de271a35cd9c..368b65d8f1b9 100644 --- a/widget/src/photon/nsPopUpMenu.cpp +++ b/widget/src/photon/nsPopUpMenu.cpp @@ -41,7 +41,6 @@ #include "nsString.h" #include "nsReadableUtils.h" -#include "nsStringUtil.h" #include "nsPhWidgetLog.h" NS_IMPL_ISUPPORTS1(nsPopUpMenu, nsIPopUpMenu) diff --git a/widget/src/photon/nsStringUtil.h b/widget/src/photon/nsStringUtil.h deleted file mode 100644 index ee1b8e49eb34..000000000000 --- a/widget/src/photon/nsStringUtil.h +++ /dev/null @@ -1,99 +0,0 @@ -/* -*- Mode: c++; tab-width: 2; indent-tabs-mode: nil; -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the NPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -// Convience macros for converting nsString's to chars + -// creating temporary char[] bufs. -#include "nsReadableUtils.h" - -#ifndef NS_STR_UTIL_H -#define NS_STR_UTIL_H - -// nsString to temporary char[] macro - -// Convience MACROS to convert an nsString to a char * which use a -// static char array if possible to reduce memory fragmentation, -// otherwise they allocate a char[] which must be freed. -// REMEMBER to always use the NS_FREE_STR_BUF after using the -// NS_ALLOC_STR_BUF. You can not nest NS_ALLOC_STR_BUF's. - -#define NS_ALLOC_STR_BUF(varName, strName, tempSize) \ - static const int _ns_kSmallBufferSize = tempSize; \ - char* varName = 0; \ - int _ns_smallBufUsed = 0; \ - char _ns_smallBuffer[_ns_kSmallBufferSize]; \ - if (strName.Length() < (_ns_kSmallBufferSize - 1)) { \ - strName.ToCString(_ns_smallBuffer, _ns_kSmallBufferSize); \ - _ns_smallBuffer[_ns_kSmallBufferSize - 1] = '\0'; \ - _ns_smallBufUsed = 1; \ - varName = _ns_smallBuffer; \ - } \ - else { \ - varName = ToNewCString(strName); \ - } - -#define NS_FREE_STR_BUF(varName) \ - if (! _ns_smallBufUsed) \ - delete[] varName; - -// Create temporary char[] macro -// -// Create a temporary buffer for storing chars. -// If the actual size is > size then the buffer -// is allocated from the heap, otherwise the buffer -// is a stack variable. REMEMBER: use NS_FREE_BUF -// when finished with the buffer allocated, and do -// NOT nest INSERT_BUF'S. - -#define NS_ALLOC_CHAR_BUF(aBuf, aSize, aActualSize) \ - char *aBuf; \ - int _ns_smallBufUsed = 0; \ - static const int _ns_kSmallBufferSize = aSize; \ - if (aActualSize < _ns_kSmallBufferSize) { \ - char _ns_smallBuffer[_ns_kSmallBufferSize]; \ - aBuf = _ns_smallBuffer; \ - _ns_smallBufUsed = 1; \ - } \ - else { \ - aBuf = new char[aActualSize]; \ - } - -#define NS_FREE_CHAR_BUF(aBuf) \ -if (! _ns_smallBufUsed) \ - delete[] aBuf; - - -#endif // NSStringUtil diff --git a/widget/src/photon/nsTextHelper.cpp b/widget/src/photon/nsTextHelper.cpp index 282633d7327b..ef688f297579 100644 --- a/widget/src/photon/nsTextHelper.cpp +++ b/widget/src/photon/nsTextHelper.cpp @@ -40,7 +40,6 @@ #include "nsColor.h" #include "nsGUIEvent.h" #include "nsString.h" -#include "nsStringUtil.h" #include #include "nsPhWidgetLog.h" @@ -98,12 +97,9 @@ NS_METHOD nsTextHelper::SetText(const nsString &aText, PRUint32& aActualSize) if (mWidget) { - NS_ALLOC_STR_BUF(buf, aText, aText.Length()); - - PtSetArg(&arg[0], Pt_ARG_TEXT_STRING, buf, 0); + PtSetArg(&arg[0], Pt_ARG_TEXT_STRING, + NS_LossyConvertUCS2toASCII(aText).get(), 0); PtSetResources(mWidget, 1, arg); - - NS_FREE_STR_BUF(buf); } aActualSize = aText.Length(); @@ -117,9 +113,9 @@ NS_METHOD nsTextHelper::InsertText(const nsString &aText, PRUint32 aStartPos, P PRUint32 currentTextLength; if (mWidget) { - NS_ALLOC_STR_BUF(buf, aText, aText.Length()); - PtTextModifyText(mWidget,0,0,aStartPos,buf,aText.Length()); - NS_FREE_STR_BUF(buf); + PtTextModifyText(mWidget, 0, 0, aStartPos, + NS_LossyConvertUCS2toASCII(aText).get(), + aText.Length()); } aActualSize = aText.Length(); diff --git a/widget/src/qt/nsButton.cpp b/widget/src/qt/nsButton.cpp index cfebd1dfd22d..de629d823f61 100644 --- a/widget/src/qt/nsButton.cpp +++ b/widget/src/qt/nsButton.cpp @@ -40,7 +40,6 @@ #include "nsColor.h" #include "nsGUIEvent.h" #include "nsString.h" -#include "nsStringUtil.h" //============================================================================= // @@ -99,13 +98,11 @@ void nsButton::InitCallbacks(char * aName) //------------------------------------------------------------------------- NS_METHOD nsButton::SetLabel(const nsString& aText) { - NS_ALLOC_STR_BUF(label, aText, 256); + PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, + ("nsButton::SetLabel to %s()\n", + NS_LossyConvertUCS2toASCII(aText).get())); - PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsButton::SetLabel to %s()\n", label)); - - ((QPushButton *)mWidget)->setText(label); - - NS_FREE_STR_BUF(label); + ((QPushButton *)mWidget)->setText(NS_LossyConvertUCS2toASCII(aText).get()); return (NS_OK); } diff --git a/widget/src/qt/nsCheckButton.cpp b/widget/src/qt/nsCheckButton.cpp index f902d24cdea7..c7096b6b18d5 100644 --- a/widget/src/qt/nsCheckButton.cpp +++ b/widget/src/qt/nsCheckButton.cpp @@ -39,7 +39,6 @@ #include "nsColor.h" #include "nsGUIEvent.h" #include "nsString.h" -#include "nsStringUtil.h" //============================================================================= // @@ -126,11 +125,7 @@ NS_METHOD nsCheckButton::GetState(PRBool& aState) NS_METHOD nsCheckButton::SetLabel(const nsString& aText) { PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsCheckButton::SetLabel()\n")); - NS_ALLOC_STR_BUF(label, aText, 256); - - ((QButton *)mWidget)->setText(label); - - NS_FREE_STR_BUF(label); + ((QButton *)mWidget)->setText(NS_LossyConvertUCS2toASCII(aText).get()); return (NS_OK); } diff --git a/widget/src/qt/nsLabel.cpp b/widget/src/qt/nsLabel.cpp index 73c7e82224d2..e45a422c5dcc 100644 --- a/widget/src/qt/nsLabel.cpp +++ b/widget/src/qt/nsLabel.cpp @@ -40,7 +40,6 @@ #include "nsColor.h" #include "nsGUIEvent.h" #include "nsString.h" -#include "nsStringUtil.h" //============================================================================= @@ -162,12 +161,7 @@ NS_METHOD nsLabel::SetLabel(const nsString& aText) PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsLabel::SetLabel()\n")); - NS_ALLOC_STR_BUF(label, aText, 256); - - ((QLabel *)mWidget)->setText(label); - - NS_FREE_STR_BUF(label); - + ((QLabel *)mWidget)->setText(NS_LossyConvertUCS2toASCII(aText).get()); return NS_OK; } diff --git a/widget/src/qt/nsMenu.cpp b/widget/src/qt/nsMenu.cpp index 48ccc419ce7a..bd21a0aff357 100644 --- a/widget/src/qt/nsMenu.cpp +++ b/widget/src/qt/nsMenu.cpp @@ -42,7 +42,6 @@ #include "nsString.h" #include "nsReadableUtils.h" -#include "nsStringUtil.h" #include "nsIMenuListener.h" #include "nsQEventHandler.h" diff --git a/widget/src/qt/nsMenuBar.cpp b/widget/src/qt/nsMenuBar.cpp index b1443e80b833..34e652f64139 100644 --- a/widget/src/qt/nsMenuBar.cpp +++ b/widget/src/qt/nsMenuBar.cpp @@ -41,7 +41,6 @@ #include "nsString.h" #include "nsReadableUtils.h" -#include "nsStringUtil.h" #include "nsQEventHandler.h" diff --git a/widget/src/qt/nsMenuItem.cpp b/widget/src/qt/nsMenuItem.cpp index 004ed206b15c..1498ccd75bf7 100644 --- a/widget/src/qt/nsMenuItem.cpp +++ b/widget/src/qt/nsMenuItem.cpp @@ -40,7 +40,6 @@ #include "nsIMenuBar.h" #include "nsIWidget.h" -#include "nsStringUtil.h" #include "nsIPopUpMenu.h" #include "nsQEventHandler.h" #include "nsCOMPtr.h" diff --git a/widget/src/qt/nsPopUpMenu.cpp b/widget/src/qt/nsPopUpMenu.cpp index cd4811a162d0..05f67b54b134 100644 --- a/widget/src/qt/nsPopUpMenu.cpp +++ b/widget/src/qt/nsPopUpMenu.cpp @@ -41,7 +41,6 @@ #include "nsString.h" #include "nsReadableUtils.h" -#include "nsStringUtil.h" #include "nsQEventHandler.h" NS_IMPL_ISUPPORTS1(nsPopUpMenu, nsIPopUpMenu) diff --git a/widget/src/qt/nsTextHelper.cpp b/widget/src/qt/nsTextHelper.cpp index 76f1bf224a20..456bf59a7ec3 100644 --- a/widget/src/qt/nsTextHelper.cpp +++ b/widget/src/qt/nsTextHelper.cpp @@ -42,7 +42,6 @@ #include "nsGUIEvent.h" #include "nsString.h" #include "nsReadableUtils.h" -#include "nsStringUtil.h" #include "nsWindow.h" diff --git a/widget/src/windows/nsMenu.cpp b/widget/src/windows/nsMenu.cpp index ab25d3eac258..d83bb8ce1cc2 100644 --- a/widget/src/windows/nsMenu.cpp +++ b/widget/src/windows/nsMenu.cpp @@ -49,7 +49,6 @@ #include "nsColor.h" #include "nsGUIEvent.h" #include "nsString.h" -#include "nsStringUtil.h" #include #include "nsIAppShell.h" diff --git a/widget/src/windows/nsMenuBar.cpp b/widget/src/windows/nsMenuBar.cpp index 910548403120..fd3f1e864d43 100644 --- a/widget/src/windows/nsMenuBar.cpp +++ b/widget/src/windows/nsMenuBar.cpp @@ -43,7 +43,6 @@ #include "nsColor.h" #include "nsGUIEvent.h" #include "nsString.h" -#include "nsStringUtil.h" #include #include "nsIAppShell.h" diff --git a/widget/src/windows/nsPopUpMenu.cpp b/widget/src/windows/nsPopUpMenu.cpp index abdcc2f08f8e..115c0c8633e9 100644 --- a/widget/src/windows/nsPopUpMenu.cpp +++ b/widget/src/windows/nsPopUpMenu.cpp @@ -43,7 +43,6 @@ #include "nsGUIEvent.h" #include "nsString.h" #include "nsReadableUtils.h" -#include "nsStringUtil.h" #include #include "nsIAppShell.h" diff --git a/widget/src/windows/nsWindow.cpp b/widget/src/windows/nsWindow.cpp index 15c83568fff8..5c26a25664f3 100644 --- a/widget/src/windows/nsWindow.cpp +++ b/widget/src/windows/nsWindow.cpp @@ -59,7 +59,6 @@ #include "nsIDeviceContext.h" #include "nsRect.h" #include "nsTransform2D.h" -#include "nsStringUtil.h" #include //#include diff --git a/widget/src/windows/nsWindow.h b/widget/src/windows/nsWindow.h index fcb6de370c89..b38eedded666 100644 --- a/widget/src/windows/nsWindow.h +++ b/widget/src/windows/nsWindow.h @@ -50,7 +50,6 @@ #include "nsIMouseListener.h" #include "nsIEventListener.h" -#include "nsStringUtil.h" #include "nsString.h" #include "nsVoidArray.h" diff --git a/widget/src/xpwidgets/nsBaseWidget.h b/widget/src/xpwidgets/nsBaseWidget.h index 2b2f99db035e..850ea5416ed9 100644 --- a/widget/src/xpwidgets/nsBaseWidget.h +++ b/widget/src/xpwidgets/nsBaseWidget.h @@ -45,7 +45,6 @@ #include "nsIMenuListener.h" #include "nsIToolkit.h" #include "nsIAppShell.h" -#include "nsStringUtil.h" #include "nsString.h" #include "nsVoidArray.h" #include "nsISupportsArray.h" diff --git a/xpcom/ds/nsAtomTable.cpp b/xpcom/ds/nsAtomTable.cpp index 04a0aef0e2d6..5d0c1d75b4dc 100644 --- a/xpcom/ds/nsAtomTable.cpp +++ b/xpcom/ds/nsAtomTable.cpp @@ -60,7 +60,7 @@ DumpAtomLeaks(PLHashEntry *he, PRIntn index, void *arg) if (atom) { nsAutoString tmp; atom->ToString(tmp); - fputs(tmp, stdout); + fputs(NS_LossyConvertUCS2toASCII(tmp).get(), stdout); fputs("\n", stdout); } return HT_ENUMERATE_NEXT;