зеркало из https://github.com/mozilla/gecko-dev.git
Added XPLocale -> Linux Locale support
This commit is contained in:
Родитель
00322fb185
Коммит
9e24c25ee5
|
@ -28,6 +28,7 @@ EXPORTS = \
|
|||
nsIDateTimeFormat.h \
|
||||
nsILocale.h \
|
||||
nsILocaleFactory.h \
|
||||
nsIPosixLocale.h \
|
||||
nsLocaleCID.h \
|
||||
$(NULL)
|
||||
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
#ifndef nsIPosixLocale_h__
|
||||
#define nsIPosixLocale_h__
|
||||
|
||||
|
||||
#include "nsISupports.h"
|
||||
#include "nscore.h"
|
||||
#include "nsString.h"
|
||||
|
||||
// {21434951-EC71-11d2-9E89-0060089FE59B}
|
||||
#define NS_IPOSIXLOCALE_IID \
|
||||
{ 0x21434951, 0xec71, 0x11d2, \
|
||||
{ 0x9e, 0x89, 0x0, 0x60, 0x8, 0x9f, 0xe5, 0x9b }}
|
||||
|
||||
|
||||
class nsIPosixLocale : public nsISupports {
|
||||
|
||||
public:
|
||||
|
||||
NS_IMETHOD GetPlatformLocale(const nsString* locale,char* posixLocale,size_t length)=0;
|
||||
NS_IMETHOD GetXPLocale(const char* posixLocale, nsString* locale)=0;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
|
@ -47,11 +47,22 @@
|
|||
{ 0xd92d57c4, 0xba1d, 0x11d2, \
|
||||
{ 0xaf, 0xc, 0x0, 0x60, 0x8, 0x9f, 0xe5, 0x9b } }
|
||||
|
||||
// {8C0E453F-EC7E-11d2-9E89-0060089FE59B}
|
||||
#define NS_MACLOCALEFACTORY_CID \
|
||||
{ 0x8c0e453f, 0xec7e, 0x11d2, \
|
||||
{ 0x9e, 0x89, 0x0, 0x60, 0x8, 0x9f, 0xe5, 0x9b }}
|
||||
|
||||
// {D92D57C5-BA1D-11d2-AF0C-0060089FE59B}
|
||||
#define NS_POSIXLOCALE_CID \
|
||||
{ 0xd92d57c5, 0xba1d, 0x11d2, \
|
||||
{ 0xaf, 0xc, 0x0, 0x60, 0x8, 0x9f, 0xe5, 0x9b } }
|
||||
|
||||
// {8C0E4531-EC7E-11d2-9E89-0060089FE59B}
|
||||
#define NS_POSIXLOCALEFACTORY_CID \
|
||||
{ 0x8c0e4531, 0xec7e, 0x11d2, \
|
||||
{ 0x9e, 0x89, 0x0, 0x60, 0x8, 0x9f, 0xe5, 0x9b }}
|
||||
|
||||
|
||||
|
||||
#endif // nsLocaleCID_h__
|
||||
|
||||
|
|
|
@ -36,6 +36,8 @@ CPPSRCS = \
|
|||
nsDateTimeFormatUnix.cpp \
|
||||
nsLocaleFactoryUnix.cpp \
|
||||
nsLocaleSO.cpp \
|
||||
nsPosixLocale.cpp \
|
||||
nsPosixLocaleFactory.cpp \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
|
|
@ -24,6 +24,9 @@
|
|||
#include "nsILocaleFactory.h"
|
||||
#include "nsLocaleFactory.h"
|
||||
#include "nsLocaleCID.h"
|
||||
#include "nsIPosixLocale.h"
|
||||
#include "nsPosixLocale.h"
|
||||
#include "nsPosixLocaleFactory.h"
|
||||
#include "nsCollationUnix.h"
|
||||
#include "nsDateTimeFormatUnix.h"
|
||||
#include "nsLocaleFactoryUnix.h"
|
||||
|
@ -40,6 +43,7 @@ static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
|
|||
//
|
||||
NS_DEFINE_IID(kLocaleFactoryCID, NS_LOCALEFACTORY_CID);
|
||||
NS_DEFINE_IID(kILocaleFactoryIID,NS_ILOCALEFACTORY_IID);
|
||||
NS_DEFINE_CID(kPosixLocaleFactoryCID, NS_POSIXLOCALEFACTORY_CID);
|
||||
|
||||
//
|
||||
// for the collation and formatting interfaces
|
||||
|
@ -63,6 +67,10 @@ 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;
|
||||
|
||||
//
|
||||
|
@ -81,6 +89,21 @@ extern "C" NS_EXPORT nsresult NSGetFactory(nsISupports* serviceMgr,
|
|||
|
||||
return res;
|
||||
}
|
||||
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))
|
||||
{
|
||||
*aFactory = NULL;
|
||||
delete posix_factory;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
//
|
||||
// let the nsLocaleUnixFactory logic take over from here
|
||||
|
@ -106,6 +129,9 @@ extern "C" NS_EXPORT nsresult NSRegisterSelf(nsISupports* aServMgr, const char *
|
|||
{
|
||||
nsresult rv;
|
||||
|
||||
#ifdef DEBUG_tague
|
||||
fprintf(stderr,"nsLocale: NSRegisterSelf called\n");
|
||||
#endif
|
||||
nsCOMPtr<nsIServiceManager> servMgr(do_QueryInterface(aServMgr, &rv));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
|
@ -119,28 +145,37 @@ extern "C" NS_EXPORT nsresult NSRegisterSelf(nsISupports* aServMgr, const char *
|
|||
// register the generic factory
|
||||
//
|
||||
rv = compMgr->RegisterComponent(kLocaleFactoryCID,NULL,NULL,path,PR_TRUE,PR_TRUE);
|
||||
NS_ASSERTION(rv==NS_OK,"nsLocaleTest: RegisterFactory failed.");
|
||||
NS_ASSERTION(rv==NS_OK,"nsLocale: RegisterFactory failed.");
|
||||
if(NS_FAILED(rv) && (NS_ERROR_FACTORY_EXISTS != rv)) goto done;
|
||||
|
||||
//
|
||||
// register the Posix factory
|
||||
//
|
||||
rv = compMgr->RegisterComponent(kPosixLocaleFactoryCID,NULL,NULL,path,PR_TRUE,PR_TRUE);
|
||||
if (rv==NS_OK) printf("Registered Ok\n");
|
||||
|
||||
NS_ASSERTION(rv==NS_OK,"nsLocale: Register Factory failed.");
|
||||
if (NS_FAILED(rv) && (NS_ERROR_FACTORY_EXISTS !=rv)) goto done;
|
||||
|
||||
//
|
||||
// register the collation factory
|
||||
//
|
||||
rv = compMgr->RegisterComponent(kCollationFactoryCID, NULL, NULL, path, PR_TRUE, PR_TRUE);
|
||||
NS_ASSERTION(rv==NS_OK,"nsLocaleTest: Register CollationFactory failed.");
|
||||
NS_ASSERTION(rv==NS_OK,"nsLocale: Register CollationFactory failed.");
|
||||
if(NS_FAILED(rv) && (NS_ERROR_FACTORY_EXISTS != rv)) goto done;
|
||||
|
||||
//
|
||||
// register the collation interface
|
||||
//
|
||||
rv = compMgr->RegisterComponent(kCollationCID, NULL, NULL, path, PR_TRUE, PR_TRUE);
|
||||
NS_ASSERTION(rv==NS_OK,"nsLocaleTest: Register Collation failed.");
|
||||
NS_ASSERTION(rv==NS_OK,"nsLocale: Register Collation failed.");
|
||||
if(NS_FAILED(rv) && (NS_ERROR_FACTORY_EXISTS != rv)) goto done;
|
||||
|
||||
//
|
||||
// register the date time formatter
|
||||
//
|
||||
rv = compMgr->RegisterComponent(kDateTimeFormatCID, NULL, NULL, path, PR_TRUE, PR_TRUE);
|
||||
NS_ASSERTION(rv==NS_OK,"nsLocaleTest: Register DateTimeFormat failed.");
|
||||
NS_ASSERTION(rv==NS_OK,"nsLocale: Register DateTimeFormat failed.");
|
||||
if(NS_FAILED(rv) && (NS_ERROR_FACTORY_EXISTS != rv)) goto done;
|
||||
|
||||
done:
|
||||
|
@ -152,6 +187,10 @@ extern "C" NS_EXPORT nsresult NSUnregisterSelf(nsISupports* aServMgr, const char
|
|||
{
|
||||
nsresult rv;
|
||||
|
||||
#ifdef DEBUG_tague
|
||||
fprintf(stderr,"nsLocale: NSUnregisterSelf called\n");
|
||||
#endif
|
||||
|
||||
nsCOMPtr<nsIServiceManager> servMgr(do_QueryInterface(aServMgr, &rv));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
|
@ -164,6 +203,9 @@ extern "C" NS_EXPORT nsresult NSUnregisterSelf(nsISupports* aServMgr, const char
|
|||
rv = compMgr->UnregisterFactory(kLocaleFactoryCID, path);
|
||||
if (NS_FAILED(rv)) goto done;
|
||||
|
||||
rv = compMgr->UnregisterFactory(kPosixLocaleFactoryCID,path);
|
||||
if (NS_FAILED(rv)) goto done;
|
||||
|
||||
rv = compMgr->UnregisterFactory(kCollationFactoryCID, path);
|
||||
if (NS_FAILED(rv)) goto done;
|
||||
|
||||
|
|
|
@ -0,0 +1,152 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "nsISupports.h"
|
||||
#include "nscore.h"
|
||||
#include "nsString.h"
|
||||
#include "nsILocale.h"
|
||||
#include "nsPosixLocale.h"
|
||||
#include "nsLocaleCID.h"
|
||||
#include "prprf.h"
|
||||
|
||||
NS_DEFINE_IID(kIPosixLocaleIID, NS_IPOSIXLOCALE_IID);
|
||||
NS_DEFINE_IID(kPosixLocaleCID, NS_POSIXLOCALE_CID);
|
||||
|
||||
/* nsPosixLocale ISupports */
|
||||
NS_IMPL_ISUPPORTS(nsPosixLocale,kIPosixLocaleIID)
|
||||
|
||||
nsPosixLocale::nsPosixLocale(void)
|
||||
{
|
||||
#ifdef DEBUG_tague
|
||||
fprintf(stderr,"nsLocale: creating nsIPosixLocale implementation\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
nsPosixLocale::~nsPosixLocale(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPosixLocale::GetPlatformLocale(const nsString* locale,char* posixLocale, size_t length)
|
||||
{
|
||||
char* xp_locale;
|
||||
char country_code[3];
|
||||
char lang_code[3];
|
||||
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,'-')) {
|
||||
strncpy(posixLocale,"C",length);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (country_code[0]==0) {
|
||||
PR_snprintf(posix_locale,9,"%s%c",lang_code,0);
|
||||
} else {
|
||||
PR_snprintf(posix_locale,9,"%s_%s%c",lang_code,country_code,0);
|
||||
}
|
||||
|
||||
strncpy(posixLocale,posix_locale,length);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPosixLocale::GetXPLocale(const char* posixLocale, nsString* locale)
|
||||
{
|
||||
char country_code[3];
|
||||
char lang_code[3];
|
||||
char region_code[3];
|
||||
char posix_locale[9];
|
||||
|
||||
if (posixLocale!=nsnull) {
|
||||
if (strcmp(posixLocale,"C")==0 || strcmp(posixLocale,"POSIX")==0) {
|
||||
*locale = "x-user-defined";
|
||||
return NS_OK;
|
||||
}
|
||||
if (!ParseLocaleString(posixLocale,lang_code,country_code,region_code,'_')) {
|
||||
* locale = "x-user-defined";
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (country_code[0]==0) {
|
||||
PR_snprintf(posix_locale,9,"%s%c",lang_code,0);
|
||||
} else {
|
||||
PR_snprintf(posix_locale,9,"%s-%s%c",lang_code,country_code,0);
|
||||
}
|
||||
|
||||
*locale = posix_locale;
|
||||
return NS_OK;
|
||||
|
||||
}
|
||||
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
// returns PR_FALSE/PR_TRUE depending on if it was of the form LL-CC-RR
|
||||
PRBool
|
||||
nsPosixLocale::ParseLocaleString(const char* locale_string, char* language, char* country, char* region, char separator)
|
||||
{
|
||||
size_t len;
|
||||
|
||||
len = strlen(locale_string);
|
||||
if (len==0 || (len!=2 && len!=5 && len!=8))
|
||||
return PR_FALSE;
|
||||
|
||||
if (len==2) {
|
||||
language[0]=locale_string[0];
|
||||
language[1]=locale_string[1];
|
||||
language[2]=0;
|
||||
country[0]=0;
|
||||
region[0]=0;
|
||||
} else if (len==5) {
|
||||
language[0]=locale_string[0];
|
||||
language[1]=locale_string[1];
|
||||
language[2]=0;
|
||||
country[0]=locale_string[3];
|
||||
country[1]=locale_string[4];
|
||||
country[2]=0;
|
||||
region[0]=0;
|
||||
if (locale_string[2]!=separator) return PR_FALSE;
|
||||
} else if (len==8) {
|
||||
language[0]=locale_string[0];
|
||||
language[1]=locale_string[1];
|
||||
language[2]=0;
|
||||
country[0]=locale_string[3];
|
||||
country[1]=locale_string[4];
|
||||
country[2]=0;
|
||||
region[0]=locale_string[6];
|
||||
region[1]=locale_string[7];
|
||||
region[2]=0;
|
||||
if (locale_string[2]!=separator || locale_string[5]!=separator) return PR_FALSE;
|
||||
} else {
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
return PR_TRUE;
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
#ifndef nsPosixLocale_h__
|
||||
#define nsPosixLocale_h__
|
||||
|
||||
|
||||
#include "nsISupports.h"
|
||||
#include "nscore.h"
|
||||
#include "nsString.h"
|
||||
#include "nsIPosixLocale.h"
|
||||
|
||||
|
||||
|
||||
class nsPosixLocale : public nsIPosixLocale {
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
public:
|
||||
|
||||
nsPosixLocale();
|
||||
~nsPosixLocale();
|
||||
|
||||
NS_IMETHOD GetPlatformLocale(const nsString* locale,char* posixLocale,
|
||||
size_t length);
|
||||
NS_IMETHOD GetXPLocale(const char* posixLocale, nsString* locale);
|
||||
|
||||
protected:
|
||||
inline PRBool ParseLocaleString(const char* locale_string, char* language, char* country, char* region, char separator);
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
|
@ -0,0 +1,125 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "nsIPosixLocale.h"
|
||||
#include "nsPosixLocale.h"
|
||||
#include "nsPosixLocaleFactory.h"
|
||||
#include "nsLocaleCID.h"
|
||||
|
||||
NS_DEFINE_IID(kIPosixLocaleIID, NS_IPOSIXLOCALE_IID);
|
||||
NS_DEFINE_IID(kPosixLocaleFactoryCID, NS_WIN32LOCALEFACTORY_CID);
|
||||
NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
|
||||
|
||||
|
||||
nsPosixLocaleFactory::nsPosixLocaleFactory()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
nsPosixLocaleFactory::~nsPosixLocaleFactory()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPosixLocaleFactory::CreateInstance(nsISupports* aOuter, REFNSIID aIID,
|
||||
void** aResult)
|
||||
{
|
||||
if (aResult == NULL) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
// Always NULL result, in case of failure
|
||||
*aResult = NULL;
|
||||
|
||||
if (aIID.Equals(kISupportsIID))
|
||||
{
|
||||
*aResult = (void *)(nsISupports*)this;
|
||||
NS_ADDREF_THIS(); // Increase reference count for caller
|
||||
} else if (aIID.Equals(kIFactoryIID))
|
||||
{
|
||||
*aResult = (void *)(nsIFactory*)this;
|
||||
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);
|
||||
*aResult = (void*)localeImpl;
|
||||
|
||||
}
|
||||
|
||||
if (*aResult == NULL) {
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult nsPosixLocaleFactory::QueryInterface(const nsIID &aIID,
|
||||
void **aResult)
|
||||
{
|
||||
if (aResult == NULL) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
// Always NULL result, in case of failure
|
||||
*aResult = NULL;
|
||||
|
||||
if (aIID.Equals(kISupportsIID)) {
|
||||
*aResult = (void *)(nsISupports*)this;
|
||||
} else if (aIID.Equals(kIFactoryIID)) {
|
||||
*aResult = (void *)(nsIFactory*)this;
|
||||
}
|
||||
|
||||
if (*aResult == NULL) {
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
NS_ADDREF_THIS(); // Increase reference count for caller
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPosixLocaleFactory::LockFactory(PRBool aBool)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsrefcnt
|
||||
nsPosixLocaleFactory::AddRef()
|
||||
{
|
||||
return ++mRefCnt;
|
||||
}
|
||||
|
||||
nsrefcnt
|
||||
nsPosixLocaleFactory::Release()
|
||||
{
|
||||
if (--mRefCnt == 0) {
|
||||
delete this;
|
||||
return 0; // Don't access mRefCnt after deleting!
|
||||
}
|
||||
return mRefCnt;
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
|
||||
* the License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are Copyright (C) 1998
|
||||
* Netscape Communications Corporation. All Rights Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsPosixLocaleFactory_h__
|
||||
#define nsPosixLocaleFactory_h__
|
||||
|
||||
#include "nsString.h"
|
||||
#include "nsISupports.h"
|
||||
#include "nsIFactory.h"
|
||||
#include "nsIPosixLocale.h"
|
||||
#include "nsPosixLocale.h"
|
||||
|
||||
|
||||
class nsPosixLocaleFactory : public nsIFactory
|
||||
{
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
public:
|
||||
|
||||
|
||||
nsPosixLocaleFactory(void);
|
||||
virtual ~nsPosixLocaleFactory(void);
|
||||
|
||||
NS_IMETHOD CreateInstance(nsISupports* aOuter, REFNSIID aIID,
|
||||
void** aResult);
|
||||
|
||||
NS_IMETHOD LockFactory(PRBool aLock);
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif /* nsPosixLocaleFactory_h__ */
|
|
@ -32,7 +32,6 @@ LOCAL_INCLUDES = -I$(srcdir)/../src
|
|||
include $(topsrcdir)/config/config.mk
|
||||
|
||||
LIBS = \
|
||||
-lnslocale \
|
||||
-lraptorbase \
|
||||
-lxpcom \
|
||||
-lreg \
|
||||
|
|
|
@ -24,6 +24,9 @@
|
|||
#include "nsIWin32Locale.h"
|
||||
#include <windows.h>
|
||||
#endif
|
||||
#ifdef XP_UNIX
|
||||
#include "nsIPosixLocale.h"
|
||||
#endif
|
||||
|
||||
NS_DEFINE_CID(kLocaleFactoryCID, NS_LOCALEFACTORY_CID);
|
||||
NS_DEFINE_IID(kILocaleFactoryIID, NS_ILOCALEFACTORY_IID);
|
||||
|
@ -39,6 +42,11 @@ NS_DEFINE_IID(kIWin32LocaleIID, NS_IWIN32LOCALE_IID);
|
|||
#define USER_DEFINED_PRIMARYLANG 0x0200
|
||||
#define USER_DEFINED_SUBLANGUAGE 0x20
|
||||
|
||||
#endif
|
||||
#ifdef XP_UNIX
|
||||
NS_DEFINE_CID(kPosixLocaleFactoryCID, NS_POSIXLOCALEFACTORY_CID);
|
||||
NS_DEFINE_IID(kIPosixLocaleIID, NS_IPOSIXLOCALE_IID);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -552,6 +560,255 @@ win32locale_reverse_conversion_test(void)
|
|||
|
||||
#endif XP_PC
|
||||
|
||||
#ifdef XP_UNIX
|
||||
void
|
||||
posixfactory_create_interface(void)
|
||||
{
|
||||
nsresult result;
|
||||
nsIFactory* factory;
|
||||
nsIPosixLocale* posix_locale;
|
||||
|
||||
result = nsComponentManager::CreateInstance(kPosixLocaleFactoryCID,
|
||||
NULL,
|
||||
kIFactoryIID,
|
||||
(void**)&factory);
|
||||
NS_ASSERTION(factory!=NULL,"nsLocaleTest: factory_create_interface failed.");
|
||||
NS_ASSERTION(result==NS_OK,"nsLocaleTest: factory_create_interface failed");
|
||||
|
||||
factory->Release();
|
||||
|
||||
result = nsComponentManager::CreateInstance(kPosixLocaleFactoryCID,
|
||||
NULL,
|
||||
kIPosixLocaleIID,
|
||||
(void**)&posix_locale);
|
||||
NS_ASSERTION(posix_locale!=NULL,"nsLocaleTest: factory_create_interface failed.");
|
||||
NS_ASSERTION(result==NS_OK,"nsLocaleTest: factory_create_interface failed");
|
||||
|
||||
posix_locale->Release();
|
||||
}
|
||||
|
||||
void
|
||||
posixlocale_test(void)
|
||||
{
|
||||
nsresult result;
|
||||
nsIPosixLocale* posix_locale;
|
||||
nsString* locale;
|
||||
char posix_locale_string[9];
|
||||
|
||||
//
|
||||
// create the locale object
|
||||
//
|
||||
result = nsComponentManager::CreateInstance(kPosixLocaleFactoryCID,
|
||||
NULL,
|
||||
kIPosixLocaleIID,
|
||||
(void**)&posix_locale);
|
||||
NS_ASSERTION(posix_locale!=NULL,"nsLocaleTest: create interface failed.\n");
|
||||
NS_ASSERTION(result==NS_OK,"nsLocaleTest: create interface failed\n");
|
||||
|
||||
//
|
||||
// test with a simple locale
|
||||
//
|
||||
locale = new nsString("en-US");
|
||||
result = posix_locale->GetPlatformLocale(locale,posix_locale_string,9);
|
||||
NS_ASSERTION(result==NS_OK,"nsLocaleTest: GetPlatformLocale failed.\n");
|
||||
NS_ASSERTION(strcmp("en_US",posix_locale_string)==0,"nsLocaleTest: GetPlatformLocale failed.\n");
|
||||
delete locale;
|
||||
|
||||
//
|
||||
// test with a not so simple locale
|
||||
//
|
||||
locale = new nsString("x-netscape");
|
||||
result = posix_locale->GetPlatformLocale(locale,posix_locale_string,9);
|
||||
NS_ASSERTION(result==NS_OK,"nsLocaleTest: GetPlatformLocale failed.\n");
|
||||
NS_ASSERTION(strcmp("C",posix_locale_string)==0,"nsLocaleTest: GetPlatformLocale failed.\n");
|
||||
delete locale;
|
||||
|
||||
//
|
||||
// test with a generic locale
|
||||
//
|
||||
locale = new nsString("en");
|
||||
result = posix_locale->GetPlatformLocale(locale,posix_locale_string,9);
|
||||
NS_ASSERTION(result==NS_OK,"nsLocaleTest: GetPlatformLocale failed.\n");
|
||||
NS_ASSERTION(strcmp("en",posix_locale_string)==0,"nsLocaleTest: GetPlatformLocale failed.\n");
|
||||
delete locale;
|
||||
|
||||
|
||||
//
|
||||
// release the locale interface
|
||||
//
|
||||
posix_locale->Release();
|
||||
}
|
||||
|
||||
void
|
||||
posixlocale_conversion_test()
|
||||
{
|
||||
nsresult result;
|
||||
nsIPosixLocale* posix_locale;
|
||||
nsString* locale;
|
||||
char posix_locale_result[9];
|
||||
|
||||
result = nsComponentManager::CreateInstance(kPosixLocaleFactoryCID,
|
||||
NULL,
|
||||
kIPosixLocaleIID,
|
||||
(void**)&posix_locale);
|
||||
NS_ASSERTION(posix_locale!=NULL,"nsLocaleTest: factory_create_interface failed.");
|
||||
NS_ASSERTION(result==NS_OK,"nsLocaleTest: factory_create_interface failed");
|
||||
|
||||
//
|
||||
// check english variants
|
||||
//
|
||||
locale = new nsString("en"); // generic english
|
||||
result = posix_locale->GetPlatformLocale(locale,posix_locale_result,9);
|
||||
NS_ASSERTION(result==NS_OK,"nsLocaleTest: GetPlatformLocale failed.");
|
||||
NS_ASSERTION(strcmp("en",posix_locale_result)==0,"nsLocaleTest: GetPlatformLocale failed.\n");
|
||||
delete locale;
|
||||
|
||||
locale = new nsString("en-US"); // US english
|
||||
result = posix_locale->GetPlatformLocale(locale,posix_locale_result,9);
|
||||
NS_ASSERTION(result==NS_OK,"nsLocaleTest: GetPlatformLocale failed.");
|
||||
NS_ASSERTION(strcmp("en_US",posix_locale_result)==0,"nsLocaleTest: GetPlatformLocale failed.\n");
|
||||
delete locale;
|
||||
|
||||
locale = new nsString("en-GB"); // UK english
|
||||
result = posix_locale->GetPlatformLocale(locale,posix_locale_result,9);
|
||||
NS_ASSERTION(result==NS_OK,"nsLocaleTest: GetPlatformLocale failed.");
|
||||
NS_ASSERTION(strcmp("en_GB",posix_locale_result)==0,"nsLocaleTest: GetPlatformLocale failed.\n");
|
||||
delete locale;
|
||||
|
||||
locale = new nsString("en-CA"); // Canadian english
|
||||
result = posix_locale->GetPlatformLocale(locale,posix_locale_result,9);
|
||||
NS_ASSERTION(result==NS_OK,"nsLocaleTest: GetPlatformLocale failed.");
|
||||
NS_ASSERTION(strcmp("en_CA",posix_locale_result)==0,"nsLocaleTest: GetPlatformLocale failed.\n");
|
||||
delete locale;
|
||||
|
||||
//
|
||||
// japanese
|
||||
//
|
||||
locale = new nsString("ja");
|
||||
result = posix_locale->GetPlatformLocale(locale,posix_locale_result,9);
|
||||
NS_ASSERTION(result==NS_OK,"nsLocaleTest: GetPlatformLocale failed.");
|
||||
NS_ASSERTION(strcmp("ja",posix_locale_result)==0,"nsLocaleTest: GetPlatformLocale failed.\n");
|
||||
delete locale;
|
||||
|
||||
locale = new nsString("ja-JP");
|
||||
result = posix_locale->GetPlatformLocale(locale,posix_locale_result,9);
|
||||
NS_ASSERTION(result==NS_OK,"nsLocaleTest: GetPlatformLocale failed.");
|
||||
NS_ASSERTION(strcmp("ja_JP",posix_locale_result)==0,"nsLocaleTest: GetPlatformLocale failed.\n");
|
||||
delete locale;
|
||||
|
||||
//
|
||||
// chinese Locales
|
||||
//
|
||||
locale = new nsString("zh");
|
||||
result = posix_locale->GetPlatformLocale(locale,posix_locale_result,9);
|
||||
NS_ASSERTION(result==NS_OK,"nsLocaleTest: GetPlatformLocale failed.");
|
||||
NS_ASSERTION(strcmp("zh",posix_locale_result)==0,"nsLocaleTest: GetPlatformLocale failed.\n");
|
||||
delete locale;
|
||||
|
||||
locale = new nsString("zh-CN");
|
||||
result = posix_locale->GetPlatformLocale(locale,posix_locale_result,9);
|
||||
NS_ASSERTION(result==NS_OK,"nsLocaleTest: GetPlatformLocale failed.");
|
||||
NS_ASSERTION(strcmp("zh_CN",posix_locale_result)==0,"nsLocaleTest: GetPlatformLocale failed.\n");
|
||||
delete locale;
|
||||
|
||||
locale = new nsString("zh-TW");
|
||||
result = posix_locale->GetPlatformLocale(locale,posix_locale_result,9);
|
||||
NS_ASSERTION(result==NS_OK,"nsLocaleTest: GetPlatformLocale failed.");
|
||||
NS_ASSERTION(strcmp("zh_TW",posix_locale_result)==0,"nsLocaleTest: GetPlatformLocale failed.\n");
|
||||
delete locale;
|
||||
|
||||
//
|
||||
// german and variants
|
||||
//
|
||||
locale = new nsString("de");
|
||||
result = posix_locale->GetPlatformLocale(locale,posix_locale_result,9);
|
||||
NS_ASSERTION(result==NS_OK,"nsLocaleTest: GetPlatformLocale failed.");
|
||||
NS_ASSERTION(strcmp("de",posix_locale_result)==0,"nsLocaleTest: GetPlatformLocale failed.\n");
|
||||
delete locale;
|
||||
|
||||
locale = new nsString("de-DE");
|
||||
result = posix_locale->GetPlatformLocale(locale,posix_locale_result,9);
|
||||
NS_ASSERTION(result==NS_OK,"nsLocaleTest: GetPlatformLocale failed.");
|
||||
NS_ASSERTION(strcmp("de_DE",posix_locale_result)==0,"nsLocaleTest: GetPlatformLocale failed.\n");
|
||||
delete locale;
|
||||
|
||||
locale = new nsString("de-AT");
|
||||
result = posix_locale->GetPlatformLocale(locale,posix_locale_result,9);
|
||||
NS_ASSERTION(result==NS_OK,"nsLocaleTest: GetPlatformLocale failed.");
|
||||
NS_ASSERTION(strcmp("de_AT",posix_locale_result)==0,"nsLocaleTest: GetPlatformLocale failed.\n");
|
||||
delete locale;
|
||||
|
||||
//
|
||||
// french and it's variants
|
||||
//
|
||||
locale = new nsString("fr");
|
||||
result = posix_locale->GetPlatformLocale(locale,posix_locale_result,9);
|
||||
NS_ASSERTION(result==NS_OK,"nsLocaleTest: GetPlatformLocale failed.");
|
||||
NS_ASSERTION(strcmp("fr",posix_locale_result)==0,"nsLocaleTest: GetPlatformLocale failed.\n");
|
||||
delete locale;
|
||||
|
||||
locale = new nsString("fr-FR");
|
||||
result = posix_locale->GetPlatformLocale(locale,posix_locale_result,9);
|
||||
NS_ASSERTION(result==NS_OK,"nsLocaleTest: GetPlatformLocale failed.");
|
||||
NS_ASSERTION(strcmp("fr_FR",posix_locale_result)==0,"nsLocaleTest: GetPlatformLocale failed.\n");
|
||||
delete locale;
|
||||
|
||||
locale = new nsString("fr-CA");
|
||||
result = posix_locale->GetPlatformLocale(locale,posix_locale_result,9);
|
||||
NS_ASSERTION(result==NS_OK,"nsLocaleTest: GetPlatformLocale failed.");
|
||||
NS_ASSERTION(strcmp("fr_CA",posix_locale_result)==0,"nsLocaleTest: GetPlatformLocale failed.\n");
|
||||
delete locale;
|
||||
|
||||
//
|
||||
// delete the XPCOM inteface
|
||||
//
|
||||
posix_locale->Release();
|
||||
}
|
||||
|
||||
void
|
||||
posixlocale_reverse_conversion_test()
|
||||
{
|
||||
nsresult result;
|
||||
nsIPosixLocale* posix_locale;
|
||||
nsString* locale;
|
||||
|
||||
//
|
||||
// create the locale object
|
||||
//
|
||||
result = nsComponentManager::CreateInstance(kPosixLocaleFactoryCID,
|
||||
NULL,
|
||||
kIPosixLocaleIID,
|
||||
(void**)&posix_locale);
|
||||
NS_ASSERTION(posix_locale!=NULL,"nsLocaleTest: create interface failed.\n");
|
||||
NS_ASSERTION(result==NS_OK,"nsLocaleTest: create interface failed\n");
|
||||
|
||||
//
|
||||
// test with a simple locale
|
||||
//
|
||||
locale = new nsString("");
|
||||
result = posix_locale->GetXPLocale("en_US",locale);
|
||||
NS_ASSERTION(result==NS_OK,"nsLocaleTest: GetXPLocale failed.\n");
|
||||
NS_ASSERTION(*locale=="en-US","nsLocaleTest: GetXPLocale failed.\n");
|
||||
delete locale;
|
||||
|
||||
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");
|
||||
delete locale;
|
||||
|
||||
locale = new nsString("");
|
||||
result = posix_locale->GetXPLocale("en",locale);
|
||||
NS_ASSERTION(result==NS_OK,"nsLocaleTest: GetXPLocale failed.\n");
|
||||
NS_ASSERTION(*locale=="en","nsLocaleTest: GetXPLocale failed.\n");
|
||||
delete locale;
|
||||
|
||||
posix_locale->Release();
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
|
@ -581,7 +838,17 @@ main(int argc, char** argv)
|
|||
win32locale_reverse_conversion_test();
|
||||
|
||||
#endif
|
||||
#ifdef XP_UNIX
|
||||
|
||||
//
|
||||
// do the younicks tests
|
||||
//
|
||||
posixfactory_create_interface();
|
||||
posixlocale_test();
|
||||
posixlocale_conversion_test();
|
||||
posixlocale_reverse_conversion_test();
|
||||
|
||||
#endif
|
||||
|
||||
//
|
||||
// we done
|
||||
|
|
Загрузка…
Ссылка в новой задаче