зеркало из https://github.com/mozilla/pjs.git
Change to call OS API with null argument for default locale, bug 39677, r=ftang.
This commit is contained in:
Родитель
71e86b8871
Коммит
c1f80caba6
|
@ -80,6 +80,7 @@ static Intl1Hndl GetItl1Resource(short scriptcode, short regioncode)
|
||||||
// get itl1 resource
|
// get itl1 resource
|
||||||
Intl1Hndl Itl1RecordHandle;
|
Intl1Hndl Itl1RecordHandle;
|
||||||
Itl1RecordHandle = (Intl1Hndl)::GetResource('itl1', itl1num);
|
Itl1RecordHandle = (Intl1Hndl)::GetResource('itl1', itl1num);
|
||||||
|
NS_ASSERTION(Itl1RecordHandle, "failed to get itl1 handle");
|
||||||
return Itl1RecordHandle;
|
return Itl1RecordHandle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,9 +113,10 @@ static Intl0Hndl GetItl0Resource(short scriptcode, short regioncode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// get itl1 resource
|
// get itl0 resource
|
||||||
Intl0Hndl Itl0RecordHandle;
|
Intl0Hndl Itl0RecordHandle;
|
||||||
Itl0RecordHandle = (Intl0Hndl)::GetResource('itl0', itl0num);
|
Itl0RecordHandle = (Intl0Hndl)::GetResource('itl0', itl0num);
|
||||||
|
NS_ASSERTION(Itl0RecordHandle, "failed to get itl0 handle");
|
||||||
return Itl0RecordHandle;
|
return Itl0RecordHandle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -249,28 +251,33 @@ nsresult nsDateTimeFormatMac::Initialize(nsILocale* locale)
|
||||||
mScriptcode = smSystemScript;
|
mScriptcode = smSystemScript;
|
||||||
mLangcode = langEnglish;
|
mLangcode = langEnglish;
|
||||||
mRegioncode = verUS;
|
mRegioncode = verUS;
|
||||||
mCharset.AssignWithConversion("ISO-8859-1");
|
mCharset.AssignWithConversion("x-mac-roman");
|
||||||
|
|
||||||
|
|
||||||
// get locale string, use app default if no locale specified
|
// get application locale
|
||||||
if (NULL == locale) {
|
NS_WITH_SERVICE(nsILocaleService, localeService, kLocaleServiceCID, &res);
|
||||||
NS_WITH_SERVICE(nsILocaleService, localeService, kLocaleServiceCID, &res);
|
if (NS_SUCCEEDED(res)) {
|
||||||
|
nsILocale *appLocale;
|
||||||
|
res = localeService->GetApplicationLocale(&appLocale);
|
||||||
if (NS_SUCCEEDED(res)) {
|
if (NS_SUCCEEDED(res)) {
|
||||||
nsILocale *appLocale;
|
res = appLocale->GetCategory(aCategory.GetUnicode(), &aLocaleUnichar);
|
||||||
res = localeService->GetApplicationLocale(&appLocale);
|
if (NS_SUCCEEDED(res) && NULL != aLocaleUnichar) {
|
||||||
if (NS_SUCCEEDED(res)) {
|
mAppLocale.Assign(aLocaleUnichar); // cache app locale name
|
||||||
res = appLocale->GetCategory(aCategory.GetUnicode(), &aLocaleUnichar);
|
|
||||||
if (NS_SUCCEEDED(res) && NULL != aLocaleUnichar) {
|
|
||||||
mAppLocale.Assign(aLocaleUnichar); // cache app locale name
|
|
||||||
}
|
|
||||||
appLocale->Release();
|
|
||||||
}
|
}
|
||||||
|
appLocale->Release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// use app default if no locale specified
|
||||||
|
if (NULL == locale) {
|
||||||
|
mUseDefaultLocale = true;
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
|
mUseDefaultLocale = false;
|
||||||
|
nsMemory::Free(aLocaleUnichar);
|
||||||
res = locale->GetCategory(aCategory.GetUnicode(), &aLocaleUnichar);
|
res = locale->GetCategory(aCategory.GetUnicode(), &aLocaleUnichar);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get a script code and charset name from locale, if available
|
// Get a script code and charset name from locale, if available
|
||||||
if (NS_SUCCEEDED(res) && NULL != aLocaleUnichar) {
|
if (NS_SUCCEEDED(res) && NULL != aLocaleUnichar) {
|
||||||
mLocale.Assign(aLocaleUnichar); // cache locale name
|
mLocale.Assign(aLocaleUnichar); // cache locale name
|
||||||
|
@ -289,6 +296,9 @@ nsresult nsDateTimeFormatMac::Initialize(nsILocale* locale)
|
||||||
mCharset.Assign(mappedCharset);
|
mCharset.Assign(mappedCharset);
|
||||||
nsMemory::Free(mappedCharset);
|
nsMemory::Free(mappedCharset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get a system charset (used when getting date/time strings as default)
|
||||||
|
res = platformCharset->GetCharset(kPlatformCharsetSel_FileName, mSystemCharset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -352,9 +362,9 @@ nsresult nsDateTimeFormatMac::FormatTMTime(nsILocale* locale,
|
||||||
|
|
||||||
::DateToSeconds( &macDateTime, (unsigned long *) &dateTime);
|
::DateToSeconds( &macDateTime, (unsigned long *) &dateTime);
|
||||||
|
|
||||||
Handle itl1Handle = (Handle) GetItl1Resource(mScriptcode, mRegioncode);
|
// specify itl if not using a default locale
|
||||||
Handle itl0Handle = (Handle) GetItl0Resource(mScriptcode, mRegioncode);
|
Handle itl1Handle = mUseDefaultLocale ? nil : (Handle) GetItl1Resource(mScriptcode, mRegioncode);
|
||||||
NS_ASSERTION(itl1Handle && itl0Handle, "failed to get itl handle");
|
Handle itl0Handle = mUseDefaultLocale ? nil : (Handle) GetItl0Resource(mScriptcode, mRegioncode);
|
||||||
|
|
||||||
// get time string
|
// get time string
|
||||||
if (timeFormatSelector != kTimeFormatNone) {
|
if (timeFormatSelector != kTimeFormatNone) {
|
||||||
|
@ -411,7 +421,7 @@ nsresult nsDateTimeFormatMac::FormatTMTime(nsILocale* locale,
|
||||||
NS_WITH_SERVICE(nsICharsetConverterManager, ccm, kCharsetConverterManagerCID, &res);
|
NS_WITH_SERVICE(nsICharsetConverterManager, ccm, kCharsetConverterManagerCID, &res);
|
||||||
if(NS_SUCCEEDED(res) && ccm) {
|
if(NS_SUCCEEDED(res) && ccm) {
|
||||||
nsCOMPtr <nsIUnicodeDecoder> decoder;
|
nsCOMPtr <nsIUnicodeDecoder> decoder;
|
||||||
res = ccm->GetUnicodeDecoder(&mCharset, getter_AddRefs(decoder));
|
res = ccm->GetUnicodeDecoder(mUseDefaultLocale ? &mSystemCharset : &mCharset, getter_AddRefs(decoder));
|
||||||
if(NS_SUCCEEDED(res) && decoder) {
|
if(NS_SUCCEEDED(res) && decoder) {
|
||||||
PRInt32 unicharLength = 0;
|
PRInt32 unicharLength = 0;
|
||||||
PRInt32 srcLength = (PRInt32) PL_strlen(aBuffer);
|
PRInt32 srcLength = (PRInt32) PL_strlen(aBuffer);
|
||||||
|
|
|
@ -70,9 +70,11 @@ private:
|
||||||
nsString mLocale;
|
nsString mLocale;
|
||||||
nsString mAppLocale;
|
nsString mAppLocale;
|
||||||
nsString mCharset;
|
nsString mCharset;
|
||||||
|
nsString mSystemCharset;
|
||||||
short mScriptcode;
|
short mScriptcode;
|
||||||
short mLangcode;
|
short mLangcode;
|
||||||
short mRegioncode;
|
short mRegioncode;
|
||||||
|
bool mUseDefaultLocale;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* nsDateTimeFormatMac_h__ */
|
#endif /* nsDateTimeFormatMac_h__ */
|
||||||
|
|
Загрузка…
Ссылка в новой задаче