making string conversions explicit

This commit is contained in:
scc%netscape.com 2000-04-01 00:39:02 +00:00
parent 4ea707a4ba
commit c05019b2a8
17 changed files with 59 additions and 33 deletions

View File

@ -243,7 +243,7 @@ AppendCapability(nsHashKey *aKey, void *aData, void *aStr)
char value = (char)((unsigned int)aData) + '0';
nsCString *capStr = (nsCString*) aStr;
capStr->Append(' ');
capStr->Append(((nsStringKey *) aKey)->GetString());
capStr->AppendWithConversion(((nsStringKey *) aKey)->GetString());
capStr->Append('=');
capStr->Append(value);
return PR_TRUE;

View File

@ -76,12 +76,13 @@ nsCertificatePrincipal::CanEnableCapability(const char *capability,
NS_IMETHODIMP
nsCertificatePrincipal::ToString(char **result)
{
// STRING USE WARNING: perhaps |str| should be an |nsCAutoString|? -- scc
nsAutoString str;
str += "[Certificate ";
str += mIssuerName;
str += ' ';
str += mSerialNumber;
str += ']';
str.AppendWithConversion("[Certificate ");
str.AppendWithConversion(mIssuerName);
str.AppendWithConversion(' ');
str.AppendWithConversion(mSerialNumber);
str.AppendWithConversion(']');
*result = str.ToNewCString();
return (*result) ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
}

View File

@ -784,7 +784,9 @@ Localize(char *genericString, nsString &result)
}
/* localize the given string */
nsAutoString strtmp(genericString);
nsAutoString strtmp;
strtmp.AssignWithConversion(genericString);
PRUnichar *ptrv = nsnull;
ret = bundle->GetStringFromName(strtmp.GetUnicode(), &ptrv);
NS_RELEASE(bundle);

View File

@ -44,7 +44,10 @@ NSBASEPRINCIPALS_RELEASE(nsSystemPrincipal);
NS_IMETHODIMP
nsSystemPrincipal::ToString(char **result)
{
nsAutoString buf("[System]");
// STRING USE WARNING: perhaps |buf| should be an |nsCAutoString|? -- scc
nsAutoString buf;
buf.AssignWithConversion("[System]");
*result = buf.ToNewCString();
return *result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
}

View File

@ -210,7 +210,9 @@ Reporter(JSContext *cx, const char *message, JSErrorReport *rep)
* Got an error object; prepare appropriate-width versions of
* various arguments to it.
*/
nsAutoString fileUni(rep->filename);
nsAutoString fileUni;
fileUni.AssignWithConversion(rep->filename);
const PRUnichar *newFileUni = fileUni.ToNewUnicode();
PRUint32 column = rep->uctokenptr - rep->uclinebuf;

View File

@ -237,7 +237,7 @@ NS_MakeAbsoluteURI(nsString& result,
nsAllocator::Free(specStr);
if (NS_FAILED(rv)) return rv;
result = resultStr;
result.AssignWithConversion(resultStr);
nsAllocator::Free(resultStr);
return rv;
}

View File

@ -574,7 +574,8 @@ nsresult NS_COM NS_ShutdownXPCOM(nsIServiceManager* servMgr)
rv = nsServiceManager::GetGlobalServiceManager(&mgr);
if (NS_SUCCEEDED(rv))
{
nsAutoString topic = NS_XPCOM_SHUTDOWN_OBSERVER_ID;
nsAutoString topic;
topic.AssignWithConversion(NS_XPCOM_SHUTDOWN_OBSERVER_ID);
(void) observerService->Notify(mgr, topic.GetUnicode(), nsnull);
}
}

View File

@ -135,7 +135,8 @@ static PRIntn CompareKeys(const PRUnichar* k1, const PRUnichar* k2)
NS_COM nsIAtom* NS_NewAtom(const char* isolatin1)
{
nsAutoString tmp(isolatin1);
nsAutoString tmp;
tmp.AssignWithConversion(isolatin1);
return NS_NewAtom(tmp.GetUnicode());
}

View File

@ -250,7 +250,7 @@ void nsHashtable::Reset(nsHashtableEnumFunc destroyFunc, void* closure)
nsStringKey::nsStringKey(const char* str)
{
mStr.Assign(str);
mStr.AssignWithConversion(str);
}
nsStringKey::nsStringKey(const PRUnichar* str)
@ -263,7 +263,7 @@ nsStringKey::nsStringKey(const nsString& str) {
}
nsStringKey::nsStringKey(const nsCString& str) {
mStr.Assign(str);
mStr.AssignWithConversion(str);
}
nsStringKey::~nsStringKey(void)

View File

@ -95,7 +95,9 @@ nsPersistentProperties::Load(nsIInputStream *aIn)
PRInt32 c;
nsresult ret;
nsAutoString uesc("x-u-escaped");
nsAutoString uesc;
uesc.AssignWithConversion("x-u-escaped");
ret = NS_NewConverterStream(&mIn, nsnull, aIn, 0, &uesc);
if (ret != NS_OK) {
#ifdef NS_DEBUG
@ -114,7 +116,7 @@ nsPersistentProperties::Load(nsIInputStream *aIn)
continue;
}
else {
nsAutoString key("");
nsAutoString key;
while ((c >= 0) && (c != '=') && (c != ':')) {
key.Append((PRUnichar) c);
c = Read();
@ -125,7 +127,7 @@ nsPersistentProperties::Load(nsIInputStream *aIn)
char *trimThese = " \t";
key.Trim(trimThese, PR_FALSE, PR_TRUE);
c = Read();
nsAutoString value("");
nsAutoString value;
while ((c >= 0) && (c != '\r') && (c != '\n')) {
if (c == '\\') {
c = Read();
@ -140,7 +142,7 @@ nsPersistentProperties::Load(nsIInputStream *aIn)
c = Read();
}
value.Trim(trimThese, PR_TRUE, PR_TRUE);
nsAutoString oldValue("");
nsAutoString oldValue;
mSubclass->SetStringProperty(key, value, oldValue);
}
}

View File

@ -388,7 +388,9 @@ static int cvt_S(SprintfState *ss, const PRUnichar *s, int width, int prec,
}
/* and away we go */
nsAutoString nullstr("(null)");
nsAutoString nullstr;
nullstr.AssignWithConversion("(null)");
return fill2(ss, s ? s : nullstr.GetUnicode(), slen, width, flags);
}
@ -831,8 +833,13 @@ static int dosprintf(SprintfState *ss, const PRUnichar *fmt, va_list ap)
} u;
PRUnichar space = ' ';
const PRUnichar *fmt0;
nsAutoString hex("0123456789abcdef");
nsAutoString HEX("0123456789ABCDEF");
nsAutoString hex;
hex.AssignWithConversion("0123456789abcdef");
nsAutoString HEX;
HEX.AssignWithConversion("0123456789ABCDEF");
const PRUnichar *hexp;
int rv, i;
struct NumArgState* nas = NULL;
@ -1389,7 +1396,9 @@ PRUnichar * nsTextFormatter::vsprintf_append(PRUnichar *last, const PRUnichar *f
PRBool nsTextFormatter::SelfTest()
{
PRBool passed = PR_TRUE ;
nsAutoString fmt("%3$s %4$S %1$d %2$d");
nsAutoString fmt;
fmt.AssignWithConversion("%3$s %4$S %1$d %2$d");
char utf8[] = "Hello";
PRUnichar ucs2[]={'W', 'o', 'r', 'l', 'd', 0x4e00, 0xAc00, 0xFF45, 0x0103};
int d=3;

View File

@ -1146,7 +1146,7 @@ void nsFileSpec::GetFileSystemCharset(nsString & fileSystemCharset)
NS_ASSERTION(NS_SUCCEEDED(rv), "error getting platform charset");
if (NS_FAILED(rv))
aCharset.Assign("ISO-8859-1");
aCharset.AssignWithConversion("ISO-8859-1");
}
fileSystemCharset = aCharset;
}
@ -1198,7 +1198,7 @@ void nsFileSpec::GetNativePathString(nsString &nativePathString)
{
const char *path = GetCString();
if (nsnull == path) {
nativePathString.Assign("");
nativePathString.SetLength(0);
return;
}
else {
@ -1208,7 +1208,7 @@ void nsFileSpec::GetNativePathString(nsString &nativePathString)
delete [] converted;
}
else
nativePathString.Assign(path);
nativePathString.AssignWithConversion(path);
}
}
@ -1219,7 +1219,7 @@ void nsFileSpec::GetLeafName(nsString &nativePathString)
{
char * path = GetLeafName();
if (nsnull == path) {
nativePathString.Assign("");
nativePathString.SetLength(0);
return;
} else {
PRUnichar *converted = ConvertFromFileSystemCharset(path);
@ -1228,7 +1228,7 @@ void nsFileSpec::GetLeafName(nsString &nativePathString)
delete [] converted;
}
else
nativePathString.Assign(path);
nativePathString.AssignWithConversion(path);
nsCRT::free(path);
}

View File

@ -44,6 +44,7 @@
#include "nsFileSpec.h"
#include "nsEscape.h"
#include "nsXPIDLString.h"
#ifndef RHAPSODY
@ -1283,7 +1284,8 @@ nsFilePath::nsFilePath(const nsString& inString, PRBool inCreateDirs)
void nsFilePath::operator = (const char* inString)
//----------------------------------------------------------------------------------------
{
AssignFromPath(*this, nsAutoCString(inString), PR_FALSE);
nsXPIDLCString temp; temp = inString;
AssignFromPath(*this, temp, PR_FALSE);
}
//----------------------------------------------------------------------------------------

View File

@ -308,7 +308,7 @@ class StringImpl
chars.Seek(PR_SEEK_SET, 0);
PRUint32 newLength;
chars.Available(&newLength);
mString.Assign(cstring, newLength);
mString.AssignWithConversion(cstring, newLength);
// Set our const string also...
delete [] (char*)mConstString;
mConstString = cstring;

View File

@ -938,7 +938,7 @@ nsLocalFile::InitWithPath(const char *filePath)
// Just save the specified file path since we can't actually do anything
// about turniung it into an FSSpec until the Create() method is called
mWorkingPath.SetString(filePath);
mWorkingPath.Assign(filePath);
mInitType = eInitWithPath;
@ -2345,7 +2345,7 @@ NS_IMETHODIMP nsLocalFile::SetAppendedPath(const char *aPath)
{
MakeDirty();
mAppendedPath.SetString(aPath);
mAppendedPath.Assign(aPath);
return NS_OK;
}

View File

@ -142,7 +142,8 @@ NS_NewB2UConverter(nsIUnicodeDecoder** aInstancePtrResult,
// Create converter
nsresult res;
nsAutoString defaultCharset("ISO-8859-1");
nsAutoString defaultCharset;
defaultCharset.AssignWithConversion("ISO-8859-1");
if (aCharSet == nsnull) aCharSet = &defaultCharset;

View File

@ -160,7 +160,9 @@ void
nsEventQueueImpl::NotifyObservers(const char *aTopic)
{
nsresult rv;
nsAutoString topic(aTopic);
nsAutoString topic;
topic.AssignWithConversion(aTopic);
nsISupports *us = NS_STATIC_CAST(nsISupports *,(NS_STATIC_CAST(nsIEventQueue *,this)));
NS_WITH_SERVICE(nsIObserverService, os, NS_OBSERVERSERVICE_PROGID, &rv);