Added linux implementation of GetSystemLocale and GetApplicationLocale

This commit is contained in:
tague%netscape.com 1999-04-27 20:01:35 +00:00
Родитель 17ed890811
Коммит 7f1f79c878
6 изменённых файлов: 73 добавлений и 22 удалений

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

@ -28,6 +28,9 @@
#ifdef XP_PC
#include "nsIWin32Locale.h"
#endif
#ifdef XP_UNIX
#include "nsIPosixLocale.h"
#endif
class nsLocaleFactory : public nsILocaleFactory
{
@ -40,6 +43,8 @@ private:
nsILocale* fApplicationLocale;
#ifdef XP_PC
nsIWin32Locale* fWin32LocaleInterface;
#elif defined(XP_UNIX)
nsIPosixLocale* fPosixLocaleInterface;
#endif
public:

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

@ -67,10 +67,6 @@ extern "C" NS_EXPORT nsresult NSGetFactory(nsISupports* serviceMgr,
nsIFactory* factoryInstance;
nsresult res;
#ifdef DEBUG_tague
fprintf(stderr,"nsLocale: NSGetFactory\n");
#endif
if (aFactory == NULL) return NS_ERROR_NULL_POINTER;
//
@ -91,9 +87,6 @@ extern "C" NS_EXPORT nsresult NSGetFactory(nsISupports* serviceMgr,
}
if (aClass.Equals(kPosixLocaleFactoryCID))
{
#ifdef DEBUG_tague
fprintf(stderr,"nsLocale: reuqest for kPosixLocaleFactory\n");
#endif
nsPosixLocaleFactory *posix_factory = new nsPosixLocaleFactory();
res = posix_factory->QueryInterface(kIFactoryIID,(void**)aFactory);
if (NS_FAILED(res))
@ -101,8 +94,7 @@ extern "C" NS_EXPORT nsresult NSGetFactory(nsISupports* serviceMgr,
*aFactory = NULL;
delete posix_factory;
}
return res;
return res;
}
//

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

@ -32,9 +32,7 @@ NS_IMPL_ISUPPORTS(nsPosixLocale,kIPosixLocaleIID)
nsPosixLocale::nsPosixLocale(void)
{
#ifdef DEBUG_tague
fprintf(stderr,"nsLocale: creating nsIPosixLocale implementation\n");
#endif
NS_INIT_REFCNT();
}
nsPosixLocale::~nsPosixLocale(void)
@ -51,9 +49,6 @@ nsPosixLocale::GetPlatformLocale(const nsString* locale,char* posixLocale, size_
char region_code[3];
char posix_locale[9];
#ifdef DEBUG_tague
fprintf(stderr,"nsLocale: nsPosixLocale::GetPlatformLocale\n");
#endif
xp_locale = locale->ToNewCString();
if (xp_locale!=nsnull) {
if (!ParseLocaleString(xp_locale,lang_code,country_code,region_code,'-')) {
@ -84,7 +79,7 @@ nsPosixLocale::GetXPLocale(const char* posixLocale, nsString* locale)
if (posixLocale!=nsnull) {
if (strcmp(posixLocale,"C")==0 || strcmp(posixLocale,"POSIX")==0) {
*locale = "x-user-defined";
*locale = "en";
return NS_OK;
}
if (!ParseLocaleString(posixLocale,lang_code,country_code,region_code,'_')) {

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

@ -33,7 +33,7 @@ class nsPosixLocale : public nsIPosixLocale {
public:
nsPosixLocale();
~nsPosixLocale();
virtual ~nsPosixLocale();
NS_IMETHOD GetPlatformLocale(const nsString* locale,char* posixLocale,
size_t length);

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

@ -58,12 +58,10 @@ nsPosixLocaleFactory::CreateInstance(nsISupports* aOuter, REFNSIID aIID,
NS_ADDREF_THIS(); // Increase reference count for caller
} else if (aIID.Equals(kIPosixLocaleIID))
{
#ifdef DEBUG_tague
fprintf(stderr,"nsLocale: nsPosixLocaleFactory--creating nsIPosixLocale\n");
#endif
nsPosixLocale *localeImpl = new nsPosixLocale();
if(localeImpl)
NS_ADDREF(localeImpl);
localeImpl->AddRef();
*aResult = (void*)localeImpl;
}

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

@ -864,7 +864,7 @@ posixlocale_reverse_conversion_test()
locale = new nsString("");
result = posix_locale->GetXPLocale("C",locale);
NS_ASSERTION(result==NS_OK,"nsLocaleTest: GetXPLocale failed.\n");
NS_ASSERTION(*locale=="x-user-defined","nsLocaleTest: GetXPLocale failed.\n");
NS_ASSERTION(*locale=="en","nsLocaleTest: GetXPLocale failed.\n");
delete locale;
locale = new nsString("");
@ -877,6 +877,66 @@ posixlocale_reverse_conversion_test()
}
void
posixlocale_test_special(void)
{
nsresult result;
nsILocaleFactory* xp_factory;
nsILocale* xp_locale;
nsString* locale, *result_locale;
nsString* lc_message;
//
// create the locale objects
//
result = nsComponentManager::FindFactory(kLocaleFactoryCID,
(nsIFactory**)&xp_factory);
NS_ASSERTION(xp_factory!=NULL,"nsLocaleTest: factory_create_interface failed.");
NS_ASSERTION(result==NS_OK,"nsLocaleTest: factory_create_interface failed");
//
// settup strings
//
locale = new nsString("en");
result_locale = new nsString();
lc_message = new nsString("NSILOCALE_MESSAGES");
//
// test GetSystemLocale
//
result = xp_factory->GetSystemLocale(&xp_locale);
NS_ASSERTION(xp_locale!=NULL,"nsLocaleTest: GetSystemLocale failed.\n");
NS_ASSERTION(result==NS_OK,"nsLocaleTest: GetSystemLocale failed.\n");
result = xp_locale->GetCatagory(lc_message,result_locale);
NS_ASSERTION(*result_locale==*locale,"nsLocaleTest: GetSystemLocale failed.\n");
NS_ASSERTION(result==NS_OK,"nsLocaleTest: GetSystemLocale failed.\n");
xp_locale->Release();
result = xp_factory->GetApplicationLocale(&xp_locale);
NS_ASSERTION(xp_locale!=NULL,"nsLocaleTest: GetApplicationLocale failed.\n");
NS_ASSERTION(result==NS_OK,"nsLocaleTest: GetApplicationLocale failed.\n");
result = xp_locale->GetCatagory(lc_message,result_locale);
NS_ASSERTION(*result_locale==*locale,"nsLocaleTest: GetSystemLocale failed.\n");
NS_ASSERTION(result==NS_OK,"nsLocaleTest: GetSystemLocale failed.\n");
xp_locale->Release();
//
// delete strings
//
delete locale;
delete result_locale;
delete lc_message;
xp_factory->Release();
}
#endif
int
@ -917,6 +977,7 @@ main(int argc, char** argv)
posixlocale_test();
posixlocale_conversion_test();
posixlocale_reverse_conversion_test();
posixlocale_test_special();
#endif