From 137a813c220f656828879a584e31780ebe87a8be Mon Sep 17 00:00:00 2001 From: "scc%netscape.com" Date: Mon, 3 Apr 2000 06:20:05 +0000 Subject: [PATCH] making string conversions explicit --- intl/locale/src/mac/nsCollationMac.cpp | 6 +++--- intl/locale/src/mac/nsDateTimeFormatMac.cpp | 16 ++++++++-------- intl/locale/src/mac/nsDateTimeFormatMac.h | 3 +-- intl/locale/src/mac/nsMacLocale.cpp | 6 +++--- intl/locale/src/nsLocaleFactory.cpp | 13 ++++++++----- intl/locale/src/nsLocaleService.cpp | 6 +++--- intl/lwbrk/src/nsLWBreakerFImp.cpp | 8 ++++---- intl/strres/src/nsStringBundle.cpp | 12 ++++++------ 8 files changed, 36 insertions(+), 34 deletions(-) diff --git a/intl/locale/src/mac/nsCollationMac.cpp b/intl/locale/src/mac/nsCollationMac.cpp index fedb19bc1b7f..0b6ce501af48 100644 --- a/intl/locale/src/mac/nsCollationMac.cpp +++ b/intl/locale/src/mac/nsCollationMac.cpp @@ -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); } } diff --git a/intl/locale/src/mac/nsDateTimeFormatMac.cpp b/intl/locale/src/mac/nsDateTimeFormatMac.cpp index fe5991e98f4d..11ba534546ed 100644 --- a/intl/locale/src/mac/nsDateTimeFormatMac.cpp +++ b/intl/locale/src/mac/nsDateTimeFormatMac.cpp @@ -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 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; diff --git a/intl/locale/src/mac/nsDateTimeFormatMac.h b/intl/locale/src/mac/nsDateTimeFormatMac.h index 41ee4f014dc2..cb14e695866e 100644 --- a/intl/locale/src/mac/nsDateTimeFormatMac.h +++ b/intl/locale/src/mac/nsDateTimeFormatMac.h @@ -59,8 +59,7 @@ public: const PRExplodedTime* explodedTime, nsString& stringOut); - nsDateTimeFormatMac() {NS_INIT_REFCNT(); - mLocale.SetString("");mAppLocale.SetString("");} + nsDateTimeFormatMac() {NS_INIT_REFCNT();} virtual ~nsDateTimeFormatMac() {} diff --git a/intl/locale/src/mac/nsMacLocale.cpp b/intl/locale/src/mac/nsMacLocale.cpp index efc9ac3bab1b..78924a96246a 100644 --- a/intl/locale/src/mac/nsMacLocale.cpp +++ b/intl/locale/src/mac/nsMacLocale.cpp @@ -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; } diff --git a/intl/locale/src/nsLocaleFactory.cpp b/intl/locale/src/nsLocaleFactory.cpp index b31acf3e2f21..3f48fcc90010 100644 --- a/intl/locale/src/nsLocaleFactory.cpp +++ b/intl/locale/src/nsLocaleFactory.cpp @@ -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; } diff --git a/intl/locale/src/nsLocaleService.cpp b/intl/locale/src/nsLocaleService.cpp index 3370f9f48bd3..67ce6b2516fa 100644 --- a/intl/locale/src/nsLocaleService.cpp +++ b/intl/locale/src/nsLocaleService.cpp @@ -375,7 +375,7 @@ nsLocaleService::NewLocale(const PRUnichar *aLocale, nsILocale **_retval) if (!resultLocale) return NS_ERROR_OUT_OF_MEMORY; for(i=0;iAddCategory(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; } diff --git a/intl/lwbrk/src/nsLWBreakerFImp.cpp b/intl/lwbrk/src/nsLWBreakerFImp.cpp index e7f47f3f650f..eaa9c099b268 100644 --- a/intl/lwbrk/src/nsLWBreakerFImp.cpp +++ b/intl/lwbrk/src/nsLWBreakerFImp.cpp @@ -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), diff --git a/intl/strres/src/nsStringBundle.cpp b/intl/strres/src/nsStringBundle.cpp index c8780fbf5d41..a3b6b5d1b060 100644 --- a/intl/strres/src/nsStringBundle.cpp +++ b/intl/strres/src/nsStringBundle.cpp @@ -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);