diff --git a/mozilla/accessible/src/atk/nsAccessibleHyperText.cpp b/mozilla/accessible/src/atk/nsAccessibleHyperText.cpp index 37dea063a0d..cec7aa55fc8 100644 --- a/mozilla/accessible/src/atk/nsAccessibleHyperText.cpp +++ b/mozilla/accessible/src/atk/nsAccessibleHyperText.cpp @@ -104,12 +104,6 @@ PRBool nsAccessibleHyperText::GetAllTextChildren(nsPresContext *aPresContext, ns if (! aCurFrame->GetRect().IsEmpty()) { nsCOMPtr node(do_QueryInterface(aCurFrame->GetContent())); if (bSave || node == aNode) { -#ifdef DEBUG - nsAutoString text; - node->GetNodeValue(text); - char buf[1024]; - text.ToCString(buf, sizeof(buf)); -#endif // some long text node may be divided into several frames, // so we must check whether this node is already in the array PRUint32 index; diff --git a/mozilla/content/xul/templates/src/nsXULTemplateBuilder.cpp b/mozilla/content/xul/templates/src/nsXULTemplateBuilder.cpp index d5c5cef22ef..89317e247b9 100644 --- a/mozilla/content/xul/templates/src/nsXULTemplateBuilder.cpp +++ b/mozilla/content/xul/templates/src/nsXULTemplateBuilder.cpp @@ -1227,8 +1227,7 @@ nsXULTemplateBuilder::SynchronizeAll(nsIRDFResource* aSource, Value val; match->GetAssignmentFor(mConflictSet, var, &val); - nsCAutoString str; - val.ToCString(str); + NS_LossyConvertUTF16toASCII str(val); PR_LOG(gXULTemplateLog, PR_LOG_DEBUG, ("xultemplate[%p] %d <= %s", this, var, str.get())); diff --git a/mozilla/editor/libeditor/base/nsEditor.cpp b/mozilla/editor/libeditor/base/nsEditor.cpp index d32cdc6f7d1..9bd5422876a 100644 --- a/mozilla/editor/libeditor/base/nsEditor.cpp +++ b/mozilla/editor/libeditor/base/nsEditor.cpp @@ -5425,11 +5425,8 @@ nsEditor::DumpNode(nsIDOMNode *aNode, PRInt32 indent) if (element) { nsAutoString tag; - char ctag[40]; element->GetTagName(tag); - tag.ToCString(ctag,40); - ctag[40]=0; - printf("<%s>\n", ctag); + printf("<%s>\n", NS_LossyConvertUTF16toASCII(tag).get()); } else { @@ -5454,11 +5451,10 @@ nsEditor::DumpNode(nsIDOMNode *aNode, PRInt32 indent) nsCOMPtr textNode = do_QueryInterface(aNode); nsAutoString str; textNode->GetData(str); - char theText[30], *c; - str.ToCString(theText,30); - theText[30]=0; - while (c=strchr(theText,'\n')) (*c) = ' '; - printf(" %s\n", theText); + nsCAutoString cstr; + LossyCopyUTF16toASCII(str, cstr); + cstr.ReplaceChar('\n', ' '); + printf(" %s\n", cstr.get()); } } #endif diff --git a/mozilla/embedding/qa/testembed/BrowserView.cpp b/mozilla/embedding/qa/testembed/BrowserView.cpp index ac59efff140..b4332cf2531 100644 --- a/mozilla/embedding/qa/testembed/BrowserView.cpp +++ b/mozilla/embedding/qa/testembed/BrowserView.cpp @@ -773,7 +773,9 @@ void CBrowserView::OnCopyLinkLocation() if(!pszClipData) return; - mCtxMenuLinkUrl.ToCString(pszClipData, mCtxMenuLinkUrl.Length() + 1); + nsFixedCString clipDataStr(pszClipData, mCtxMenuLinkUrl.Length() + 1); + LossyCopyUTF16toASCII(mCtxMenuLinkUrl, clipDataStr); + NS_ASSERTION(clipDataStr.get() == pszClipData, "buffer too small"); GlobalUnlock(hClipData); diff --git a/mozilla/embedding/qa/testembed/BrowserView.cpp.mod b/mozilla/embedding/qa/testembed/BrowserView.cpp.mod index bb69c4d48b8..4c173c09235 100644 --- a/mozilla/embedding/qa/testembed/BrowserView.cpp.mod +++ b/mozilla/embedding/qa/testembed/BrowserView.cpp.mod @@ -768,7 +768,9 @@ void CBrowserView::OnCopyLinkLocation() if(!pszClipData) return; - mCtxMenuLinkUrl.ToCString(pszClipData, mCtxMenuLinkUrl.Length() + 1); + nsFixedCString clipDataStr(pszClipData, mCtxMenuLinkUrl.Length() + 1); + LossyCopyUTF16toASCII(mCtxMenuLinkUrl, clipDataStr); + NS_ASSERTION(clipDataStr.get() == pszClipData, "buffer too small"); GlobalUnlock(hClipData); diff --git a/mozilla/gfx/src/windows/nsDeviceContextWin.cpp b/mozilla/gfx/src/windows/nsDeviceContextWin.cpp index b131e0c5730..ddec97c244b 100644 --- a/mozilla/gfx/src/windows/nsDeviceContextWin.cpp +++ b/mozilla/gfx/src/windows/nsDeviceContextWin.cpp @@ -581,8 +581,13 @@ NS_IMETHODIMP nsDeviceContextWin :: CheckFontExistence(const nsString& aFontName logFont.lfFaceName, sizeof(logFont.lfFaceName), nsnull, nsnull); // somehow the WideCharToMultiByte failed, let's try the old code - if(0 == outlen) - aFontName.ToCString(logFont.lfFaceName, LF_FACESIZE); + if(0 == outlen) { + nsFixedCString logFontStr(logFont.lfFaceName, LF_FACESIZE); + LossyCopyUTF16toASCII(aFontName, logFontStr); + if (logFontStr.get() != logFont.lfFaceName) { + return NS_ERROR_FAILURE; // the font name is too large + } + } ::EnumFontFamiliesEx(hdc, &logFont, (FONTENUMPROC)fontcallback, (LPARAM)&isthere, 0); diff --git a/mozilla/layout/mathml/base/src/nsMathMLChar.cpp b/mozilla/layout/mathml/base/src/nsMathMLChar.cpp index 0571b0125bc..f662de4ff4f 100644 --- a/mozilla/layout/mathml/base/src/nsMathMLChar.cpp +++ b/mozilla/layout/mathml/base/src/nsMathMLChar.cpp @@ -956,9 +956,8 @@ nsGlyphTableList::GetPreferredListAt(nsPresContext* aPresContext, glyphTable->GetPrimaryFontName(fontName); if (CheckFontExistence(aPresContext, fontName)) { #ifdef NOISY_SEARCH - char str[50]; - fontName.ToCString(str, sizeof(str)); - printf("Found preferreed font %s\n", str); + printf("Found preferreed font %s\n", + NS_LossyConvertUTF16toASCII(fontName).get()); #endif if (index == aStartingIndex) { // At least one font is found, clear aGlyphTableList @@ -1078,9 +1077,8 @@ SetPreferredFonts(const char* aKey, nsString& aFamilyList) const char* extension = aKey + 27; #ifdef DEBUG_rbs - char str[50]; - aFamilyList.ToCString(str, sizeof(str)); - printf("Setting preferred fonts for \\u%04X%s: %s\n", uchar, extension, str); + printf("Setting preferred fonts for \\u%04X%s: %s\n", uchar, extension, + NS_LossyConvertUTF16toASCII(aFamilyList).get()); #endif if (!strcmp(extension, ".base")) { @@ -1238,10 +1236,9 @@ InitGlobals(nsPresContext* aPresContext) prefBranch->GetChildList("font.mathfont-family.", &count, &allKey); for (i = 0; i < count; ++i) { #ifdef DEBUG_rbs - char str[50]; GetPrefValue(prefBranch, allKey[i], value); - value.ToCString(str, sizeof(str)); - printf("Found user pref %s: %s\n", allKey[i], str); + printf("Found user pref %s: %s\n", allKey[i], + NS_LossyConvertUTF16toASCII(value).get()); #endif if ((30 < strlen(allKey[i])) && GetPrefValue(prefBranch, allKey[i], value)) { @@ -1660,9 +1657,8 @@ nsMathMLChar::Stretch(nsPresContext* aPresContext, SetFirstFamily(theFont, fontName); aRenderingContext.SetFont(theFont, nsnull); #ifdef NOISY_SEARCH - char str[50]; - fontName.ToCString(str, sizeof(str)); - printf(" searching in %s ...\n", str); + printf(" searching in %s ...\n", + NS_LossyConvertUTF16toASCII(fontName).get()); #endif ch = glyphTable->BigOf(aPresContext, this, size++); while (ch) { @@ -1736,10 +1732,9 @@ nsMathMLChar::Stretch(nsPresContext* aPresContext, rv = ComposeChildren(aPresContext, aRenderingContext, glyphTable, aContainerSize, compositeSize, aStretchHint); #ifdef NOISY_SEARCH - char str[50]; - fontName.ToCString(str, sizeof(str)); printf(" Composing %d chars in font %s %s!\n", - glyphTable->ChildCountOf(aPresContext, this), str, + glyphTable->ChildCountOf(aPresContext, this), + NS_LossyConvertUTF16toASCII(fontName).get(), NS_SUCCEEDED(rv)? "OK" : "Rejected"); #endif if (NS_FAILED(rv)) continue; // to next table @@ -1794,9 +1789,9 @@ nsMathMLChar::Stretch(nsPresContext* aPresContext, // bounding metrics of all parts. computedSize = ComputeSizeFromParts(chdata, sizedata, targetSize, aStretchHint); #ifdef NOISY_SEARCH - char str[50]; - fontName.ToCString(str, sizeof(str)); - printf(" Font %s %s!\n", str, (computedSize) ? "OK" : "Rejected"); + printf(" Font %s %s!\n", + NS_LossyConvertUTF16toASCII(fontName).get(), + (computedSize) ? "OK" : "Rejected"); #endif if (!computedSize) continue; // to next table diff --git a/mozilla/layout/xul/base/src/nsBox.cpp b/mozilla/layout/xul/base/src/nsBox.cpp index b3c4c390268..8b181a9a76a 100644 --- a/mozilla/layout/xul/base/src/nsBox.cpp +++ b/mozilla/layout/xul/base/src/nsBox.cpp @@ -178,7 +178,7 @@ nsBox::BeginLayout(nsBoxLayoutState& aState) nsBoxAddIndents(); - nsAutoString reason; + nsCAutoString reason; switch(aState.LayoutReason()) { case nsBoxLayoutState::Dirty: @@ -192,9 +192,7 @@ nsBox::BeginLayout(nsBoxLayoutState& aState) break; } - char ch[100]; - reason.ToCString(ch,100); - printf("%s Layout: ", ch); + printf("%s Layout: ", reason.get()); DumpBox(stdout); printf("\n"); gIndent++; diff --git a/mozilla/modules/plugin/samples/SanePlugin/nsSanePluginFactory.cpp b/mozilla/modules/plugin/samples/SanePlugin/nsSanePluginFactory.cpp index 572cd294f58..46196fec48d 100644 --- a/mozilla/modules/plugin/samples/SanePlugin/nsSanePluginFactory.cpp +++ b/mozilla/modules/plugin/samples/SanePlugin/nsSanePluginFactory.cpp @@ -285,19 +285,10 @@ NSRegisterSelf( nsISupports* aServMgr, const char* aPath ) aPath, PR_TRUE, PR_TRUE ); // Register the plugin portion. - nsString contractID; - contractID.AssignWithConversion( NS_INLINE_PLUGIN_CONTRACTID_PREFIX ); - - contractID.AppendWithConversion(PLUGIN_MIME_TYPE); - buf = ( char * )calloc( 2000, sizeof( char ) ); - contractID.ToCString( buf, 1999 ); - rv = compMgr->RegisterComponent( knsSanePluginInst, "SANE Plugin Component", - buf, + NS_INLINE_PLUGIN_CONTRACTID_PREFIX PLUGIN_MIME_TYPE aPath, PR_TRUE, PR_TRUE); - free( buf ); - if ( NS_FAILED( rv ) ) return rv; diff --git a/mozilla/webshell/tests/viewer/nsViewerApp.cpp b/mozilla/webshell/tests/viewer/nsViewerApp.cpp index 2d62cbbe42b..ed972e7f47a 100644 --- a/mozilla/webshell/tests/viewer/nsViewerApp.cpp +++ b/mozilla/webshell/tests/viewer/nsViewerApp.cpp @@ -820,8 +820,10 @@ nsEventStatus PR_CALLBACK HandleRobotEvent(nsGUIEvent *aEvent) delete[] cStr; mVerDirTxt->GetText(str, 255, size); - str.ToCString(gVerifyDir, (PRInt32)_MAX_PATH); - if (!strcmp(gVerifyDir,DEBUG_EMPTY)) { + nsFixedCString verifyDirStr(gVerifyDir, sizeof(gVerifyDir)); + LossyCopyUTF16toASCII(str, verifyDirStr); + if (verifyDirStr.get() != gVerifyDir || + !strcmp(gVerifyDir,DEBUG_EMPTY)) { gVerifyDir[0] = '\0'; } PRBool state = PR_FALSE; diff --git a/mozilla/webshell/tests/viewer/nsWebCrawler.cpp b/mozilla/webshell/tests/viewer/nsWebCrawler.cpp index de0441ed56a..1436327d4cd 100644 --- a/mozilla/webshell/tests/viewer/nsWebCrawler.cpp +++ b/mozilla/webshell/tests/viewer/nsWebCrawler.cpp @@ -558,10 +558,7 @@ nsWebCrawler::GetOutputFile(nsIURI *aURL, nsString& aOutputName) nsAutoString outputFileName(mOutputDir); outputFileName.AppendWithConversion(inputFileName); PRInt32 bufLen = outputFileName.Length()+1; - char *buf = new char[bufLen+1]; - outputFileName.ToCString(buf, bufLen); - result = fopen(buf, "wt"); - delete [] buf; + result = fopen(NS_LossyConvertUTF16toASCII(outputFileName).get(), "wt"); delete [] inputFileName; } return result; @@ -942,12 +939,10 @@ nsWebCrawler::PerformRegressionTest(const nsString& aOutputName) rv = fu->CompareRegressionData(f1, f2,mRegressionOutputLevel); NS_RELEASE(fu); - char dirName[BUF_SIZE]; - char fileName[BUF_SIZE]; - mOutputDir.ToCString(dirName, BUF_SIZE-1); - aOutputName.ToCString(fileName, BUF_SIZE-1); - - printf("regression test %s%s %s\n", dirName, fileName, NS_SUCCEEDED(rv) ? "passed" : "failed"); + printf("regression test %s%s %s\n", + NS_LossyConvertUTF16toASCII(mOutputDir).get(), + NS_LossyConvertUTF16toASCII(aOutputName).get(), + NS_SUCCEEDED(rv) ? "passed" : "failed"); } //---------------------------------------------------------------------- diff --git a/mozilla/webshell/tests/viewer/os2/nsCheckButton.cpp b/mozilla/webshell/tests/viewer/os2/nsCheckButton.cpp index 6a84d21e379..189b139fa09 100644 --- a/mozilla/webshell/tests/viewer/os2/nsCheckButton.cpp +++ b/mozilla/webshell/tests/viewer/os2/nsCheckButton.cpp @@ -158,10 +158,7 @@ NS_METHOD nsCheckButton::GetState(PRBool& aState) //------------------------------------------------------------------------- NS_METHOD nsCheckButton::SetLabel(const nsString& aText) { - char label[256]; - aText.ToCString(label, 256); - label[255] = '\0'; - ::WinSetWindowText(mWnd, label); + ::WinSetWindowText(mWnd, NS_LossyConvertUTF16toASCII(aText).get()); return NS_OK; } diff --git a/mozilla/webshell/tests/viewer/windows/nsCheckButton.cpp b/mozilla/webshell/tests/viewer/windows/nsCheckButton.cpp index a163e3f1a95..058807763e8 100644 --- a/mozilla/webshell/tests/viewer/windows/nsCheckButton.cpp +++ b/mozilla/webshell/tests/viewer/windows/nsCheckButton.cpp @@ -155,10 +155,7 @@ NS_METHOD nsCheckButton::GetState(PRBool& aState) //------------------------------------------------------------------------- NS_METHOD nsCheckButton::SetLabel(const nsString& aText) { - char label[256]; - aText.ToCString(label, 256); - label[255] = '\0'; - VERIFY(::SetWindowText(mWnd, label)); + VERIFY(::SetWindowText(mWnd, NS_LossyConvertUTF16toASCII(aText).get())); return NS_OK; } diff --git a/mozilla/widget/src/mac/nsMenuX.cpp b/mozilla/widget/src/mac/nsMenuX.cpp index a7cd3964f95..169e55fe67c 100644 --- a/mozilla/widget/src/mac/nsMenuX.cpp +++ b/mozilla/widget/src/mac/nsMenuX.cpp @@ -257,9 +257,7 @@ NS_METHOD nsMenuX::AddMenuItem(nsIMenuItem * aMenuItem) aMenuItem->GetShortcutChar(keyEquivalent); if (!keyEquivalent.EqualsLiteral(" ")) { ToUpperCase(keyEquivalent); - char keyStr[2]; - keyEquivalent.ToCString(keyStr, sizeof(keyStr)); - short inKey = keyStr[0]; + short inKey = NS_LossyConvertUTF16toASCII(keyEquivalent).First(); ::SetItemCmd(mMacMenuHandle, currItemIndex, inKey); //::SetMenuItemKeyGlyph(mMacMenuHandle, mNumMenuItems, 0x61); } diff --git a/mozilla/widget/src/os2/nsFilePicker.cpp b/mozilla/widget/src/os2/nsFilePicker.cpp index 7936ecc6e5b..ff72aadc6e6 100644 --- a/mozilla/widget/src/os2/nsFilePicker.cpp +++ b/mozilla/widget/src/os2/nsFilePicker.cpp @@ -127,13 +127,13 @@ NS_IMETHODIMP nsFilePicker::Show(PRInt16 *retval) NS_ENSURE_ARG_POINTER(retval); PRBool result = PR_FALSE; - char fileBuffer[MAX_PATH+1] = ""; + nsCAutoString fileBuffer; char *converted = ConvertToFileSystemCharset(mDefault); if (nsnull == converted) { - mDefault.ToCString(fileBuffer,MAX_PATH); + LossyCopyUTF16toASCII(mDefault, fileBuffer); } else { - PL_strncpyz(fileBuffer, converted, MAX_PATH+1); + fileBuffer.Assign(converted); nsMemory::Free( converted ); } @@ -177,7 +177,7 @@ NS_IMETHODIMP nsFilePicker::Show(PRInt16 *retval) else { PL_strncpy(filedlg.szFullFile, initialDir.get(), MAX_PATH); PL_strncat(filedlg.szFullFile, "\\", 1); - PL_strncat(filedlg.szFullFile, fileBuffer, MAX_PATH); + PL_strncat(filedlg.szFullFile, fileBuffer.get(), MAX_PATH); filedlg.fl = FDS_CENTER; if (mMode == modeSave) { filedlg.fl |= FDS_SAVEAS_DIALOG | FDS_ENABLEFILELB; diff --git a/mozilla/widget/src/photon/nsFilePicker.cpp b/mozilla/widget/src/photon/nsFilePicker.cpp index 5ccc1e2457f..82c0cda48d8 100644 --- a/mozilla/widget/src/photon/nsFilePicker.cpp +++ b/mozilla/widget/src/photon/nsFilePicker.cpp @@ -146,11 +146,11 @@ NS_IMETHODIMP nsFilePicker::Show(PRInt16 *aReturnVal) initialDir.AppendWithConversion( mDefault ); } - char extensionBuffer[MAX_EXTENSION_LENGTH+1] = "*"; + nsCAutoString extensionBuffer('*'); if( !mFilterList.IsEmpty() ) { char *text = ToNewUTF8String( mFilterList ); if( text ) { - extensionBuffer[0] = 0; + extensionBuffer.Truncate(0); /* eliminate the ';' and the duplicates */ char buffer[MAX_EXTENSION_LENGTH+1], buf[MAX_EXTENSION_LENGTH+1], *q, *delims = "; ", *dummy; @@ -158,8 +158,8 @@ NS_IMETHODIMP nsFilePicker::Show(PRInt16 *aReturnVal) q = strtok_r( buffer, delims, &dummy ); while( q ) { sprintf( buf, "%s ", q ); - if( !strstr( extensionBuffer, buf ) ) - strcat( extensionBuffer, buf ); + if ( !strstr(extensionBuffer.get(), buf ) ) + extensionBuffer.Append(buf); q = strtok_r( NULL, delims, &dummy ); } @@ -170,10 +170,10 @@ NS_IMETHODIMP nsFilePicker::Show(PRInt16 *aReturnVal) // Someone was cool and told us what to do char *convertedExt = ToNewUTF8String( mDefaultExtension ); if (!convertedExt) { - mDefaultExtension.ToCString(extensionBuffer, MAX_EXTENSION_LENGTH); + LossyCopyUTF16toASCII(mDefaultExtension, extensionBuffer); } else { - PL_strncpyz(extensionBuffer, convertedExt, MAX_EXTENSION_LENGTH+1); + extensionBuffer.Assign(convertedExt); nsMemory::Free( convertedExt ); } } @@ -182,7 +182,7 @@ NS_IMETHODIMP nsFilePicker::Show(PRInt16 *aReturnVal) memset( &info, 0, sizeof( info ) ); if( PtFileSelection( mParentWidget, NULL, title, initialDir.get(), - extensionBuffer, btn1, "&Cancel", "nsd", &info, flags ) ) { + extensionBuffer.get(), btn1, "&Cancel", "nsd", &info, flags ) ) { if (title) nsMemory::Free( title ); return NS_ERROR_FAILURE; } diff --git a/mozilla/xpcom/obsolete/nsFileSpec.cpp b/mozilla/xpcom/obsolete/nsFileSpec.cpp index 5ccda3ab5e0..77ff1860623 100644 --- a/mozilla/xpcom/obsolete/nsFileSpec.cpp +++ b/mozilla/xpcom/obsolete/nsFileSpec.cpp @@ -150,7 +150,9 @@ void nsSimpleCharString::operator = (const nsString& inString) ReallocData(len); if (!mData) return; - inString.ToCString(mData->mString, len + 1); + nsFixedCString dataString(mData->mString, len + 1); + LossyCopyUTF16toASCII(inString, dataString); + NS_ASSERTION(dataString.get() == mData->mString, "buffer too small"); } // nsSimpleCharString::operator = //---------------------------------------------------------------------------------------- diff --git a/mozilla/xpcom/string/public/nsTString.h b/mozilla/xpcom/string/public/nsTString.h index 621fab59e6d..5093b0f2616 100644 --- a/mozilla/xpcom/string/public/nsTString.h +++ b/mozilla/xpcom/string/public/nsTString.h @@ -266,18 +266,6 @@ class nsTString_CharT : public nsTSubstring_CharT NS_COM PRBool EqualsIgnoreCase( const char* aString, PRInt32 aCount=-1 ) const; - /** - * Copies data from internal buffer onto given char* buffer - * - * NOTE: This only copies as many chars as will fit in given buffer (clips) - * @param aBuf is the buffer where data is stored - * @param aBuflength is the max # of chars to move to buffer - * @param aOffset is the offset to copy from - * @return ptr to given buffer - */ - - NS_COM char* ToCString( char* aBuf, PRUint32 aBufLength, PRUint32 aOffset=0 ) const; - #endif // !CharT_is_PRUnichar /** diff --git a/mozilla/xpcom/string/src/nsStringObsolete.cpp b/mozilla/xpcom/string/src/nsStringObsolete.cpp index 453df715fd4..31752f66182 100644 --- a/mozilla/xpcom/string/src/nsStringObsolete.cpp +++ b/mozilla/xpcom/string/src/nsStringObsolete.cpp @@ -1105,24 +1105,9 @@ nsString::EqualsIgnoreCase( const char* aString, PRInt32 aCount ) const } /** - * ToCString, ToFloat, ToInteger + * nsTString::ToFloat */ -char* -nsString::ToCString( char* aBuf, PRUint32 aBufLength, PRUint32 aOffset ) const - { - // because the old implementation checked aBuf - if (!(aBuf && aBufLength > 0 && aOffset <= mLength)) - return nsnull; - - PRUint32 maxCount = NS_MIN(aBufLength-1, mLength - aOffset); - - LossyConvertEncoding converter(aBuf); - converter.write(mData + aOffset, maxCount); - converter.write_terminator(); - return aBuf; - } - float nsCString::ToFloat(PRInt32* aErrorCode) const { @@ -1149,25 +1134,7 @@ nsCString::ToFloat(PRInt32* aErrorCode) const float nsString::ToFloat(PRInt32* aErrorCode) const { - float res = 0.0f; - char buf[100]; - if (mLength > 0 && mLength < sizeof(buf)) - { - char *conv_stopped; - const char *str = ToCString(buf, sizeof(buf)); - // Use PR_strtod, not strtod, since we don't want locale involved. - res = (float)PR_strtod(str, &conv_stopped); - if (conv_stopped == str+mLength) - *aErrorCode = (PRInt32) NS_OK; - else // Not all the string was scanned - *aErrorCode = (PRInt32) NS_ERROR_ILLEGAL_VALUE; - } - else - { - // The string was too short (0 characters) or too long (sizeof(buf)) - *aErrorCode = (PRInt32) NS_ERROR_ILLEGAL_VALUE; - } - return res; + return NS_LossyConvertUTF16toASCII(*this).ToFloat(aErrorCode); } diff --git a/mozilla/xpcom/tests/windows/nsStringTest.h b/mozilla/xpcom/tests/windows/nsStringTest.h index 723f9a1cd33..8d8bf464a9a 100644 --- a/mozilla/xpcom/tests/windows/nsStringTest.h +++ b/mozilla/xpcom/tests/windows/nsStringTest.h @@ -956,9 +956,6 @@ int CStringTester::TestCreators(){ if(str) Recycle(str); - char buffer[6]; - theString5.ToCString(buffer,sizeof(buffer)); - } { @@ -974,9 +971,6 @@ int CStringTester::TestCreators(){ if(str) Recycle(str); - char buffer[100]; - theString5.ToCString(buffer,sizeof(buffer)-1); - nsCString theOther=theString5.GetBuffer(); } */ return result; @@ -1591,10 +1585,8 @@ int CStringTester::TestRandomOps(){ output<< "(" << str[index] << ", " << pos << ") "; } - thePrevString.ToCString(buffer,1000,0); - output << " Old: [" << buffer << "]"; - theString.ToCString(buffer,1000,0); - output << " New: [" << buffer << "]"; + output << " Old: [" << NS_LossyConvertUTF16toASCII(thePrevString).get() << "]"; + output << " New: [" << NS_LossyConvertUTF16toASCII(theString).get() << "]"; output << " STL: [" << theSTLString.c_str() << "]" << endl; if(theString.mStringValue.mLength>300) { diff --git a/mozilla/xpfe/browser/src/nsBrowserInstance.cpp b/mozilla/xpfe/browser/src/nsBrowserInstance.cpp index 76614402e4f..01fb689fc81 100644 --- a/mozilla/xpfe/browser/src/nsBrowserInstance.cpp +++ b/mozilla/xpfe/browser/src/nsBrowserInstance.cpp @@ -378,12 +378,12 @@ NS_IMPL_ISUPPORTS1(PageCycler, nsIObserver) void TimesUp(nsITimer *aTimer, void *aClosure) { if(aClosure){ - char urlBuf[64]; PageCycler *pCycler = (PageCycler *)aClosure; pCycler->StopTimer(); - pCycler->GetLastRequest().ToCString( urlBuf, sizeof(urlBuf), 0 ); - fprintf(stderr,"########## PageCycler Timeout on URL: %s\n", urlBuf); - pCycler->Observe( pCycler, nsnull, (pCycler->GetLastRequest()).get() ); + const nsAutoString &url = pCycler->GetLastRequest(); + fprintf(stderr,"########## PageCycler Timeout on URL: %s\n", + NS_LossyConvertUTF16toASCII(url).get()); + pCycler->Observe( pCycler, nsnull, url.get() ); } } diff --git a/mozilla/xpinstall/src/nsWinProfileItem.cpp b/mozilla/xpinstall/src/nsWinProfileItem.cpp index ece2ddb12ff..911dd1b2a88 100644 --- a/mozilla/xpinstall/src/nsWinProfileItem.cpp +++ b/mozilla/xpinstall/src/nsWinProfileItem.cpp @@ -103,9 +103,7 @@ char* nsWinProfileItem::toString() result->AppendLiteral("="); result->Append(*mValue); - resultCString = new char[result->Length() + 1]; - if(resultCString != nsnull) - result->ToCString(resultCString, result->Length() + 1); + resultCString = ToNewCString(*result); if (result) delete result; if (filename) delete filename; diff --git a/mozilla/xpinstall/src/nsWinRegItem.cpp b/mozilla/xpinstall/src/nsWinRegItem.cpp index 8ece31b5475..f554d6b0713 100644 --- a/mozilla/xpinstall/src/nsWinRegItem.cpp +++ b/mozilla/xpinstall/src/nsWinRegItem.cpp @@ -201,9 +201,7 @@ char* nsWinRegItem::toString() if (result) { result->Append(*keyString); - resultCString = new char[result->Length() + 1]; - if(resultCString != nsnull) - result->ToCString(resultCString, result->Length() + 1); + resultCString = ToNewCString(*result); } if (keyString) delete keyString;