making string conversions explicit

This commit is contained in:
scc%netscape.com 2000-04-03 06:20:05 +00:00
parent 5bc18af705
commit 137a813c22
8 changed files with 36 additions and 34 deletions

View File

@ -142,10 +142,10 @@ nsresult nsCollationMac::Initialize(nsILocale* locale)
// locale -> script code + charset name
m_scriptcode = smRoman;
mCharset.SetString("ISO-8859-1");
mCharset.AssignWithConversion("ISO-8859-1");
PRUnichar *aLocaleUnichar;
nsAutoString aCategory("NSILOCALE_COLLATE");
nsAutoString aCategory; aCategory.AssignWithConversion("NSILOCALE_COLLATE");
// get locale string, use app default if no locale specified
if (locale == nsnull) {
@ -180,7 +180,7 @@ nsresult nsCollationMac::Initialize(nsILocale* locale)
PRUnichar* mappedCharset = NULL;
res = platformCharset->GetDefaultCharsetForLocale(aLocale.GetUnicode(), &mappedCharset);
if (NS_SUCCEEDED(res) && mappedCharset) {
mCharset.SetString(mappedCharset);
mCharset.Assign(mappedCharset);
nsAllocator::Free(mappedCharset);
}
}

View File

@ -226,7 +226,7 @@ NS_IMPL_ISUPPORTS(nsDateTimeFormatMac, kIDateTimeFormatIID);
nsresult nsDateTimeFormatMac::Initialize(nsILocale* locale)
{
PRUnichar *aLocaleUnichar = NULL;
nsString aCategory("NSILOCALE_TIME");
nsString aCategory; aCategory.AssignWithConversion("NSILOCALE_TIME");
nsresult res;
// use cached info if match with stored locale
@ -249,7 +249,7 @@ nsresult nsDateTimeFormatMac::Initialize(nsILocale* locale)
mScriptcode = smSystemScript;
mLangcode = langEnglish;
mRegioncode = verUS;
mCharset.SetString("ISO-8859-1");
mCharset.AssignWithConversion("ISO-8859-1");
// get locale string, use app default if no locale specified
@ -261,7 +261,7 @@ nsresult nsDateTimeFormatMac::Initialize(nsILocale* locale)
if (NS_SUCCEEDED(res)) {
res = appLocale->GetCategory(aCategory.GetUnicode(), &aLocaleUnichar);
if (NS_SUCCEEDED(res) && NULL != aLocaleUnichar) {
mAppLocale.SetString(aLocaleUnichar); // cache app locale name
mAppLocale.Assign(aLocaleUnichar); // cache app locale name
}
appLocale->Release();
}
@ -273,7 +273,7 @@ nsresult nsDateTimeFormatMac::Initialize(nsILocale* locale)
// Get a script code and charset name from locale, if available
if (NS_SUCCEEDED(res) && NULL != aLocaleUnichar) {
mLocale.SetString(aLocaleUnichar); // cache locale name
mLocale.Assign(aLocaleUnichar); // cache locale name
nsAllocator::Free(aLocaleUnichar);
nsCOMPtr <nsIMacLocale> macLocale = do_GetService(kMacLocaleFactoryCID, &res);
@ -286,7 +286,7 @@ nsresult nsDateTimeFormatMac::Initialize(nsILocale* locale)
PRUnichar* mappedCharset = NULL;
res = platformCharset->GetDefaultCharsetForLocale(mLocale.GetUnicode(), &mappedCharset);
if (NS_SUCCEEDED(res) && mappedCharset) {
mCharset.SetString(mappedCharset);
mCharset.Assign(mappedCharset);
nsAllocator::Free(mappedCharset);
}
}
@ -322,11 +322,11 @@ nsresult nsDateTimeFormatMac::FormatTMTime(nsILocale* locale,
// return, nothing to format
if (dateFormatSelector == kDateFormatNone && timeFormatSelector == kTimeFormatNone) {
stringOut.SetString("");
stringOut.SetLength(0);
return NS_OK;
}
stringOut.SetString(asctime(tmTime)); // set the default string, in case for API/conversion errors
stringOut.AssignWithConversion(asctime(tmTime)); // set the default string, in case for API/conversion errors
// convert struct tm to input format of mac toolbox call
NS_ASSERTION(tmTime->tm_mon >= 0, "tm is not set correctly");
@ -422,7 +422,7 @@ nsresult nsDateTimeFormatMac::FormatTMTime(nsILocale* locale,
res = decoder->Convert(aBuffer, &srcLength,
unichars, &unicharLength);
if (NS_SUCCEEDED(res)) {
stringOut.SetString(unichars, unicharLength);
stringOut.Assign(unichars, unicharLength);
}
}
delete [] unichars;

View File

@ -59,8 +59,7 @@ public:
const PRExplodedTime* explodedTime,
nsString& stringOut);
nsDateTimeFormatMac() {NS_INIT_REFCNT();
mLocale.SetString("");mAppLocale.SetString("");}
nsDateTimeFormatMac() {NS_INIT_REFCNT();}
virtual ~nsDateTimeFormatMac() {}

View File

@ -278,7 +278,7 @@ nsMacLocale::GetXPLocale(short scriptCode, short langCode, short regionCode, nsS
//
for(i=0;strlen(lang_list[i].iso_code)!=0;i++) {
if (langCode==lang_list[i].mac_lang_code && scriptCode==lang_list[i].mac_script_code) {
temp = lang_list[i].iso_code;
temp.AssignWithConversion(lang_list[i].iso_code);
validResultFound = true;
break;
}
@ -289,8 +289,8 @@ nsMacLocale::GetXPLocale(short scriptCode, short langCode, short regionCode, nsS
//
for(i=0;strlen(country_list[i].iso_code)!=0;i++) {
if (regionCode==country_list[i].mac_region_code) {
temp += '-';
temp += country_list[i].iso_code;
temp.AppendWithConversion('-');
temp.AppendWithConversion(country_list[i].iso_code);
validResultFound = true;
break;
}

View File

@ -106,8 +106,11 @@ nsLocaleFactory::nsLocaleFactory(void)
fCategoryList = new nsString*[LOCALE_CATEGORY_LISTLEN];
for(i=0;i< LOCALE_CATEGORY_LISTLEN;i++)
fCategoryList[i] = new nsString(localeCategoryList[i]);
for(i=0;i< LOCALE_CATEGORY_LISTLEN;i++) {
nsString* temp = new nsString;
temp->AssignWithConversion(localeCategoryList[i]);
fCategoryList[i] = temp;
}
#if defined(XP_PC) && !defined(XP_OS2)
fWin32LocaleInterface = nsnull;
@ -339,7 +342,7 @@ nsLocaleFactory::GetSystemLocale(nsILocale** systemLocale)
#else
nsString* systemLocaleName;
systemLocaleName = new nsString("en-US");
systemLocaleName = new nsString; systemLocaleName->AssignWithConversion("en-US");
result = this->NewLocale(systemLocaleName,&fSystemLocale);
if (NS_FAILED(result)) {
delete systemLocaleName;
@ -421,7 +424,7 @@ nsLocaleFactory::GetApplicationLocale(nsILocale** applicationLocale)
#else
nsString* applicationLocaleName;
applicationLocaleName = new nsString("en-US");
applicationLocaleName = new nsString; applicationLocaleName->AssignWithConversion("en-US");
result = this->NewLocale(applicationLocaleName,&fApplicationLocale);
if (NS_FAILED(result)) {
delete applicationLocaleName;
@ -538,7 +541,7 @@ nsLocaleFactory::GetLocaleFromAcceptLanguage(const char* acceptLanguage, nsILoca
//
result = NS_ERROR_FAILURE;
if (countLang>0) {
localeName = new nsString(acceptLanguageList[0]);
localeName = new nsString; localeName->AssignWithConversion(acceptLanguageList[0]);
result = NewLocale(localeName,acceptLocale);
delete localeName;
}

View File

@ -375,7 +375,7 @@ nsLocaleService::NewLocale(const PRUnichar *aLocale, nsILocale **_retval)
if (!resultLocale) return NS_ERROR_OUT_OF_MEMORY;
for(i=0;i<LocaleListLength;i++) {
nsString category = LocaleList[i];
nsString category; category.AssignWithConversion(LocaleList[i]);
result = resultLocale->AddCategory(category.GetUnicode(),aLocale);
if (NS_FAILED(result)) { delete resultLocale; return result;}
}
@ -520,7 +520,7 @@ nsLocaleService::GetLocaleFromAcceptLanguage(const char *acceptLanguage, nsILoca
//
result = NS_ERROR_FAILURE;
if (countLang>0) {
PRUnichar* localeName = nsString(acceptLanguageList[0]).ToNewUnicode();
PRUnichar* localeName = NS_ConvertToString(acceptLanguageList[0]).ToNewUnicode();
result = NewLocale(localeName,_retval);
delete localeName;
}
@ -542,7 +542,7 @@ nsLocaleService::GetLocaleComponentForUserAgent(PRUnichar **_retval)
result = GetSystemLocale(getter_AddRefs(system_locale));
if (NS_SUCCEEDED(result))
{
nsString lc_messages(NSILOCALE_MESSAGE);
nsString lc_messages; lc_messages.AssignWithConversion(NSILOCALE_MESSAGE);
result = system_locale->GetCategory(lc_messages.GetUnicode(),_retval);
return result;
}

View File

@ -111,25 +111,25 @@ nsresult nsLWBreakerFImp::GetBreaker(nsString& aParam, nsILineBreaker** oResult)
if( NULL == oResult) {
return NS_ERROR_NULL_POINTER;
}
if( aParam.Equals("ja") )
if( aParam.EqualsWithConversion("ja") )
{
*oResult = new nsJISx4501LineBreaker (
gJaNoBegin, sizeof(gJaNoBegin)/sizeof(PRUnichar),
gJaNoEnd, sizeof(gJaNoEnd)/sizeof(PRUnichar));
}
else if(aParam.Equals("ko"))
else if(aParam.EqualsWithConversion("ko"))
{
*oResult = new nsJISx4501LineBreaker (
gKoNoBegin, sizeof(gKoNoBegin)/sizeof(PRUnichar),
gKoNoEnd, sizeof(gKoNoEnd)/sizeof(PRUnichar));
}
else if(aParam.Equals("tw"))
else if(aParam.EqualsWithConversion("tw"))
{
*oResult = new nsJISx4501LineBreaker (
gTwNoBegin, sizeof(gTwNoBegin)/sizeof(PRUnichar),
gTwNoEnd, sizeof(gTwNoEnd)/sizeof(PRUnichar));
}
else if(aParam.Equals("cn"))
else if(aParam.EqualsWithConversion("cn"))
{
*oResult = new nsJISx4501LineBreaker (
gCnNoBegin, sizeof(gCnNoBegin)/sizeof(PRUnichar),

View File

@ -112,8 +112,8 @@ nsStringBundle::~nsStringBundle()
nsresult
nsStringBundle::GetStringFromID(PRInt32 aID, nsString& aResult)
{
nsAutoString name("");
name.Append(aID, 10);
nsAutoString name;
name.AppendWithConversion(aID, 10);
nsresult ret = mProps->GetStringProperty(name, aResult);
#ifdef DEBUG_tao
@ -147,7 +147,7 @@ NS_IMETHODIMP
nsStringBundle::GetStringFromID(PRInt32 aID, PRUnichar **aResult)
{
*aResult = nsnull;
nsString tmpstr("");
nsString tmpstr;
nsresult ret = GetStringFromID(aID, tmpstr);
PRInt32 len = tmpstr.Length()+1;
@ -166,7 +166,7 @@ NS_IMETHODIMP
nsStringBundle::GetStringFromName(const PRUnichar *aName, PRUnichar **aResult)
{
*aResult = nsnull;
nsString tmpstr("");
nsString tmpstr;
nsString nameStr(aName);
nsresult ret = GetStringFromName(nameStr, tmpstr);
PRInt32 len = tmpstr.Length()+1;
@ -205,7 +205,7 @@ nsStringBundle::GetInputStream(const char* aURLSpec, nsILocale* aLocale, nsIInpu
#if 1
/* plan A: don't fallback; use aURLSpec: xxx.pro -> xxx.pro
*/
strFile2 = aURLSpec;
strFile2.AssignWithConversion(aURLSpec);
ret = OpenInputStream(strFile2, in);
#else
nsString lc_lang;
@ -293,7 +293,7 @@ nsStringBundle::GetLangCountry(nsILocale* aLocale, nsString& lang, nsString& cou
PRUnichar *lc_name_unichar;
nsString lc_name;
nsString category("NSILOCALE_MESSAGES");
nsString category; category.AssignWithConversion("NSILOCALE_MESSAGES");
nsresult result = aLocale->GetCategory(category.GetUnicode(), &lc_name_unichar);
lc_name.Assign(lc_name_unichar);
nsAllocator::Free(lc_name_unichar);