making string conversions explicit

This commit is contained in:
scc%netscape.com 2000-04-03 05:52:40 +00:00
Родитель c4f3739d2a
Коммит bc421e1e8d
5 изменённых файлов: 46 добавлений и 40 удалений

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

@ -78,17 +78,17 @@ NS_IMETHODIMP nsCharsetAlias2::GetPreferred(const nsString& aAlias, nsString& oR
{
nsAutoString aKey;
aAlias.ToLowerCase(aKey);
oResult = "";
oResult.SetLength(0);
if(nsnull == mDelegate) {
if(aKey.Equals("utf-8")) {
oResult = "UTF-8";
if(aKey.EqualsWithConversion("utf-8")) {
oResult.AssignWithConversion("UTF-8");
return NS_OK;
}
if(aKey.Equals("iso-8859-1")) {
oResult = "ISO-8859-1";
if(aKey.EqualsWithConversion("iso-8859-1")) {
oResult.AssignWithConversion("ISO-8859-1");
return NS_OK;
}
nsAutoString propertyURL("resource:/res/charsetalias.properties");
nsAutoString propertyURL; propertyURL.AssignWithConversion("resource:/res/charsetalias.properties");
// we may need to protect the following section with a lock so we won't call the
// 'new nsURLProperties' from two different threads
@ -121,7 +121,7 @@ NS_IMETHODIMP nsCharsetAlias2::Equals(const nsString& aCharset1, const nsString&
return res;
}
if(aCharset1.Equals("") || aCharset2.Equals("")) {
if(aCharset1.IsEmpty() || aCharset2.IsEmpty()) {
*oResult = PR_FALSE;
return res;
}

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

@ -239,8 +239,8 @@ nsresult nsCharsetConverterManager::RegisterConverterTitles(
nsresult res;
nsRegistryKey key;
nsAutoString str(aRegistryPath);
str.Append("defaultFile");
nsAutoString str; str.AssignWithConversion(aRegistryPath);
str.AppendWithConversion("defaultFile");
char * p = str.ToNewCString();
res = aRegistry->AddSubtree(nsIRegistry::Common, p, &key);
@ -259,8 +259,8 @@ nsresult nsCharsetConverterManager::RegisterConverterData(
nsresult res;
nsRegistryKey key;
nsAutoString str(aRegistryPath);
str.Append("defaultFile");
nsAutoString str; str.AssignWithConversion(aRegistryPath);
str.AppendWithConversion("defaultFile");
char * p = str.ToNewCString();
res = aRegistry->AddSubtree(nsIRegistry::Common, p, &key);
@ -340,11 +340,13 @@ void nsCharsetConverterManager::FillInfoArrays()
// XXX do an alias resolution here instead
if (!strcmp(src, "Unicode")) {
ci->mName = new nsString(dest);
ci->mName = new nsString;
ci->mName->AssignWithConversion(dest);
ci->mName->ToLowerCase();
mEncoderArray.AddObject(ci);
} else if (!strcmp(dest, "Unicode")) {
ci->mName = new nsString(src);
ci->mName = new nsString;
ci->mName->AssignWithConversion(src);
ci->mName->ToLowerCase();
mDecoderArray.AddObject(ci);
} else goto done1;
@ -504,12 +506,15 @@ nsresult nsCharsetConverterManager::GetRegistryEnumeration(
res = node->GetNameUTF8(&name);
if (NS_FAILED(res)) goto done1;
s = new nsString("charsetDetector.");
// STRING USE WARNING: this use should be looked at. Why does |s| have to be allocated?
// Couldn't it just be an |nsAutoString| on the stack?
s = new nsString;
s->AssignWithConversion("charsetDetector.");
if (s == NULL) {
res = NS_ERROR_OUT_OF_MEMORY;
goto done1;
}
s->Append(name);
s->AppendWithConversion(name);
aArray->AppendString(*s);
done1:
@ -623,7 +628,7 @@ NS_IMETHODIMP nsCharsetConverterManager::GetCharsetTitle(nsString * aCharset,
*aResult = NULL;
nsresult res = NS_OK;
nsAutoString prop(".title");
nsAutoString prop; prop.AssignWithConversion(".title");
if (mTitleBundle == NULL) {
res = LoadExtensibleBundle(NS_TITLE_BUNDLE_REGISTRY_KEY, &mTitleBundle);
@ -643,7 +648,7 @@ NS_IMETHODIMP nsCharsetConverterManager::GetCharsetLangGroup(
*aResult = NULL;
nsresult res = NS_OK;;
nsAutoString prop(".LangGroup");
nsAutoString prop; prop.AssignWithConversion(".LangGroup");
if (mDataBundle == NULL) {
res = LoadExtensibleBundle(NS_DATA_BUNDLE_REGISTRY_KEY, &mDataBundle);
@ -658,7 +663,7 @@ NS_IMETHODIMP nsCharsetConverterManager::GetMIMEMailCharset(
nsString * aCharset,
nsString ** aResult)
{
nsAutoString prop(".MIMEMailCharset");
nsAutoString prop; prop.AssignWithConversion(".MIMEMailCharset");
return GetCharsetData(aCharset, &prop, aResult);
}
@ -666,7 +671,7 @@ NS_IMETHODIMP nsCharsetConverterManager::GetMIMEHeaderEncodingMethod(
nsString * aCharset,
nsString ** aResult)
{
nsAutoString prop(".MIMEHeaderEncodingMethod");
nsAutoString prop; prop.AssignWithConversion(".MIMEHeaderEncodingMethod");
return GetCharsetData(aCharset, &prop, aResult);
}

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

@ -423,7 +423,7 @@ nsresult nsCharsetMenu::SetCharsetCheckmark(nsString * aCharset,
// set checkmark value
nsCOMPtr<nsIRDFLiteral> checkedLiteral;
nsAutoString checked((aValue == PR_TRUE) ? "true" : "false");
nsAutoString checked; checked.AssignWithConversion((aValue == PR_TRUE) ? "true" : "false");
res = rdfServ->GetLiteral(checked.GetUnicode(), getter_AddRefs(checkedLiteral));
if (NS_FAILED(res)) return res;
res = Assert(node, kNC_Checked, checkedLiteral, PR_TRUE);
@ -560,7 +560,7 @@ nsresult nsCharsetMenu::InitBrowserMoreMenu(nsIRDFService * aRDFServ,
if (NS_FAILED(res)) return res;
// remove charsets "not for browser"
nsAutoString prop(".notForBrowser");
nsAutoString prop; prop.AssignWithConversion(".notForBrowser");
RemoveFlaggedCharsets(aDecs, aCount, aCCMan, &prop);
for (i = 0; i < aCount; i++) if (aDecs[i] != NULL)
@ -646,7 +646,8 @@ nsresult nsCharsetMenu::AddItemToArray(nsICharsetConverterManager * aCCMan,
// XXX positively hacky
if (aObjectArray == &mBrowserMenu) {
item->mName = new nsString("charset.");
item->mName = new nsString;
item->mName->AssignWithConversion("charset.");
item->mName->Append(*aCharset);
} else {
item->mName = new nsString(*aCharset);
@ -726,7 +727,7 @@ nsresult nsCharsetMenu::AddSeparatorToContainer(nsIRDFService * aRDFServ,
res = aRDFServ->GetResource(csID, getter_AddRefs(node));
if (NS_FAILED(res)) return res;
nsAutoString str(csID);
nsAutoString str; str.AssignWithConversion(csID);
// set node's title
nsCOMPtr<nsIRDFLiteral> titleLiteral;
@ -758,7 +759,7 @@ nsresult nsCharsetMenu::AddFromStringToMenu(char * aCharsetList,
char temp = *q;
*q = 0;
nsAutoString str(p);
nsAutoString str; str.AssignWithConversion(p);
// if this charset is not on accepted list of charsets, ignore it
PRInt32 i;
@ -810,7 +811,7 @@ nsresult nsCharsetMenu::AddCharsetToCache(nsObjectArray * aArray,
PRInt32 i;
nsresult res = NS_OK;
nsAutoString charset("charset.");
nsAutoString charset; charset.AssignWithConversion("charset.");
charset.Append(*aCharset);
i = FindItem(aArray, &charset, NULL);
if (i >= 0) return res;

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

@ -63,7 +63,7 @@ nsMacCharset::nsMacCharset()
// XXX we should make the following block critical section
if(gInfo == nsnull)
{
nsAutoString propertyURL("resource:/res/maccharset.properties");
nsAutoString propertyURL; propertyURL.AssignWithConversion("resource:/res/maccharset.properties");
nsURLProperties *info = new nsURLProperties( propertyURL );
NS_ASSERTION(info , "cannot open properties file");
@ -73,23 +73,23 @@ nsMacCharset::nsMacCharset()
if( gInfo ) {
long ret = ::GetScriptManagerVariable(smRegionCode);
PRInt32 reg = (PRInt32)(ret & 0x00FFFF);
nsAutoString regionKey("region.");
regionKey.Append(reg, 10);
nsAutoString regionKey; regionKey.AssignWithConversion("region.");
regionKey.AppendWithConversion(reg, 10);
nsresult res = gInfo->Get(regionKey, mCharset);
if(NS_FAILED(res)) {
ret = ::GetScriptManagerVariable(smSysScript);
PRInt32 script = (PRInt32)(ret & 0x00FFFF);
nsAutoString scriptKey("script.");
scriptKey.Append(script, 10);
nsAutoString scriptKey; scriptKey.AssignWithConversion("script.");
scriptKey.AppendWithConversion(script, 10);
nsresult res = gInfo->Get(scriptKey, mCharset);
if(NS_FAILED(res)) {
mCharset = "x-mac-roman";
mCharset.AssignWithConversion("x-mac-roman");
}
}
} else {
mCharset = "x-mac-roman";
mCharset.AssignWithConversion("x-mac-roman");
}
}
nsMacCharset::~nsMacCharset()
@ -108,7 +108,7 @@ NS_IMETHODIMP
nsMacCharset::GetDefaultCharsetForLocale(const PRUnichar* localeName, PRUnichar** _retValue)
{
nsCOMPtr<nsIMacLocale> pMacLocale;
nsString localeAsString(localeName), charset("x-mac-roman");
nsString localeAsString(localeName), charset; charset.AssignWithConversion("x-mac-roman");
short script, language, region;
nsresult rv = nsComponentManager::CreateInstance(kMacLocaleFactoryCID,nsnull,kMacLocaleIID,
@ -120,15 +120,15 @@ nsMacCharset::GetDefaultCharsetForLocale(const PRUnichar* localeName, PRUnichar*
if (!gInfo) { *_retValue = charset.ToNewUnicode(); return NS_ERROR_OUT_OF_MEMORY; }
nsAutoString locale_key("region.");
locale_key.Append(region,10);
nsAutoString locale_key; locale_key.AssignWithConversion("region.");
locale_key.AppendWithConversion(region,10);
rv = gInfo->Get(locale_key,charset);
if (NS_FAILED(rv)) {
locale_key = "script.";
locale_key.Append(script,10);
locale_key.AssignWithConversion("script.");
locale_key.AppendWithConversion(script,10);
rv = gInfo->Get(locale_key,charset);
if (NS_FAILED(rv)) { charset="x-mac-roman";}
if (NS_FAILED(rv)) { charset.AssignWithConversion("x-mac-roman");}
}
*_retValue = charset.ToNewUnicode();
return rv;

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

@ -58,7 +58,7 @@ NS_IMETHODIMP nsTextToSubURI::ConvertAndEscape(
if(nsnull == _retval)
return NS_ERROR_NULL_POINTER;
*_retval = nsnull;
nsAutoString charsetStr(charset);
nsAutoString charsetStr; charsetStr.AssignWithConversion(charset);
nsIUnicodeEncoder *encoder = nsnull;
nsresult rv = NS_OK;
@ -122,7 +122,7 @@ NS_IMETHODIMP nsTextToSubURI::UnEscapeAndConvert(
// Convert from the charset to unicode
NS_WITH_SERVICE(nsICharsetConverterManager, ccm, kCharsetConverterManagerCID, &rv);
if (NS_SUCCEEDED(rv)) {
nsAutoString charsetStr(charset);
nsAutoString charsetStr; charsetStr.AssignWithConversion(charset);
nsIUnicodeDecoder *decoder;
rv = ccm->GetUnicodeDecoder(&charsetStr, &decoder);
if (NS_SUCCEEDED(rv)) {