зеркало из https://github.com/mozilla/pjs.git
r=mkaply, a=brendan Code from samake - report locale to current and to use OS, not c runtime
This commit is contained in:
Родитель
4fed677109
Коммит
41ac82f91b
|
@ -22,11 +22,11 @@
|
|||
#ifndef _nsios2locale_h_
|
||||
#define _nsios2locale_h_
|
||||
|
||||
#include <locale.h>
|
||||
#include "nsISupports.h"
|
||||
#include "nscore.h"
|
||||
#include "nsString.h"
|
||||
#include "unidef.h" // for LocaleObject
|
||||
#include "unidef.h"
|
||||
|
||||
|
||||
// {F25F74F0-FB59-11d3-A9F2-00203522A03C}
|
||||
#define NS_IOS2LOCALE_IID \
|
||||
|
@ -39,19 +39,8 @@ class nsIOS2Locale : public nsISupports
|
|||
public:
|
||||
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IOS2LOCALE_IID)
|
||||
NS_IMETHOD GetPlatformLocale(const nsString* locale,char* os2Locale,size_t length)=0;
|
||||
NS_IMETHOD GetPlatformLocale(PRUnichar* os2Locale,size_t length)=0;
|
||||
NS_IMETHOD GetXPLocale(const char* os2Locale, nsString* locale)=0;
|
||||
|
||||
// Init a complex locale - categories should be magic nsLocale words
|
||||
NS_IMETHOD Init( nsString **aCatList,
|
||||
nsString **aValList,
|
||||
PRUint8 aLength) = 0;
|
||||
|
||||
// Init a locale object from a xx-XX style name
|
||||
NS_IMETHOD Init( const nsString &aLocaleName) = 0;
|
||||
|
||||
// Get the OS/2 locale object
|
||||
NS_IMETHOD GetLocaleObject( LocaleObject *aLocaleObject) = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -30,11 +30,11 @@ EXTRA_DSO_LIBS = nslocale_s
|
|||
|
||||
|
||||
CPPSRCS = \
|
||||
nsLocaleOS2.cpp \
|
||||
nsOS2Locale.cpp \
|
||||
nsLocaleFactoryOS2.cpp \
|
||||
nsCollationOS2.cpp \
|
||||
nsDateTimeFormatOS2.cpp \
|
||||
nsLocaleDllOS2.cpp \
|
||||
nsOS2LocaleFactory.cpp \
|
||||
nsLocaleModule.cpp \
|
||||
$(NULL)
|
||||
|
||||
|
|
|
@ -16,222 +16,187 @@
|
|||
* Copyright (C) 1999 John Fairhurst. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* This Original Code has been modified by IBM Corporation.
|
||||
* Modifications made by IBM described herein are
|
||||
* Copyright (c) International Business Machines
|
||||
* Corporation, 2000
|
||||
*
|
||||
* Modifications to Mozilla code or documentation
|
||||
* identified per MPL Section 3.3
|
||||
*
|
||||
* Date Modified by Description of modification
|
||||
* 07/05/2000 IBM Corp. Reworked file.
|
||||
*/
|
||||
|
||||
#define INCL_DOS
|
||||
#include <os2.h>
|
||||
#include "unidef.h"
|
||||
|
||||
#include "nscore.h"
|
||||
#include "prmem.h"
|
||||
#include "nsCollationOS2.h"
|
||||
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsLocaleCID.h"
|
||||
#include "nsILocaleService.h"
|
||||
#include "nsIPlatformCharset.h"
|
||||
#include "nsIOS2Locale.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsFileSpec.h" /* for nsAutoString */
|
||||
#include "nsIPref.h"
|
||||
|
||||
|
||||
static NS_DEFINE_IID(kILocaleOS2IID, NS_IOS2LOCALE_IID);
|
||||
static NS_DEFINE_IID(kICollationIID, NS_ICOLLATION_IID);
|
||||
static NS_DEFINE_IID(kICollationFactoryIID, NS_ICOLLATIONFACTORY_IID);
|
||||
static NS_DEFINE_CID(kOS2LocaleFactoryCID, NS_OS2LOCALEFACTORY_CID);
|
||||
static NS_DEFINE_IID(kIOS2LocaleIID, NS_IOS2LOCALE_IID);
|
||||
static NS_DEFINE_CID(kLocaleServiceCID, NS_LOCALESERVICE_CID);
|
||||
static NS_DEFINE_CID(kPlatformCharsetCID, NS_PLATFORMCHARSET_CID);
|
||||
|
||||
// nsISupports implementation
|
||||
NS_IMPL_ISUPPORTS(nsCollationOS2, kICollationIID)
|
||||
|
||||
// init/term
|
||||
nsCollationOS2::nsCollationOS2() : mLocaleObject(0), mLocale(nsnull)
|
||||
nsCollationOS2::nsCollationOS2()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
NS_INIT_REFCNT();
|
||||
mCollation = NULL;
|
||||
}
|
||||
|
||||
nsCollationOS2::~nsCollationOS2()
|
||||
{
|
||||
NS_IF_RELEASE(mLocale);
|
||||
if (mCollation != NULL)
|
||||
delete mCollation;
|
||||
}
|
||||
|
||||
nsresult nsCollationOS2::Initialize( nsILocale *aLocale)
|
||||
nsresult nsCollationOS2::Initialize(nsILocale *locale)
|
||||
{
|
||||
nsIOS2Locale *mOS2Locale = nsnull;
|
||||
nsresult rc = aLocale->QueryInterface( kILocaleOS2IID,
|
||||
(void**) &mOS2Locale);
|
||||
if( NS_SUCCEEDED(rc))
|
||||
{
|
||||
mLocale = aLocale;
|
||||
NS_ADDREF(mLocale);
|
||||
mOS2Locale->GetLocaleObject( &mLocaleObject);
|
||||
NS_RELEASE(mOS2Locale);
|
||||
}
|
||||
#define kPlatformLocaleLength 64
|
||||
#define MAPPEDCHARSET_BUFFER_LEN 80
|
||||
NS_ASSERTION(mCollation == NULL, "Should only be initialized once");
|
||||
|
||||
return rc;
|
||||
nsresult res;
|
||||
|
||||
mCollation = new nsCollation;
|
||||
if (mCollation == NULL) {
|
||||
NS_ASSERTION(0, "mCollation creation failed");
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
// default local charset name
|
||||
mCharset.AssignWithConversion("ISO-8859-1");
|
||||
|
||||
// default platform locale
|
||||
mLocale.AssignWithConversion("C");
|
||||
|
||||
PRUnichar *aLocaleUnichar = NULL;
|
||||
nsString aCategory;
|
||||
aCategory.AssignWithConversion("NSILOCALE_COLLATE");
|
||||
|
||||
// get locale string, use app default if no locale specified
|
||||
if (locale == nsnull) {
|
||||
NS_WITH_SERVICE(nsILocaleService, localeService, kLocaleServiceCID, &res);
|
||||
if (NS_SUCCEEDED(res)) {
|
||||
nsILocale *appLocale;
|
||||
res = localeService->GetApplicationLocale(&appLocale);
|
||||
if (NS_SUCCEEDED(res)) {
|
||||
res = appLocale->GetCategory(aCategory.GetUnicode(), &aLocaleUnichar);
|
||||
appLocale->Release();
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
res = locale->GetCategory(aCategory.GetUnicode(), &aLocaleUnichar);
|
||||
}
|
||||
|
||||
// Get platform locale and charset name from locale, if available
|
||||
if (NS_SUCCEEDED(res)) {
|
||||
nsString aLocale;
|
||||
aLocale = aLocaleUnichar;
|
||||
if (NULL != aLocaleUnichar) {
|
||||
nsMemory::Free(aLocaleUnichar);
|
||||
}
|
||||
|
||||
// keep the same behavior as 4.x as well as avoiding Linux collation key problem
|
||||
if (aLocale.EqualsIgnoreCase("en-US")) {
|
||||
aLocale.AssignWithConversion("C");
|
||||
}
|
||||
|
||||
nsCOMPtr <nsIOS2Locale> os2Locale = do_GetService(kOS2LocaleFactoryCID, &res);
|
||||
if (NS_SUCCEEDED(res)) {
|
||||
PRUnichar platformLocale[kPlatformLocaleLength+1];
|
||||
res = os2Locale->GetPlatformLocale(platformLocale, kPlatformLocaleLength+1);
|
||||
if (NS_SUCCEEDED(res)) {
|
||||
mLocale.Assign(platformLocale, kPlatformLocaleLength+1);
|
||||
}
|
||||
}
|
||||
|
||||
// Create a locale object and query for the code page
|
||||
nsCOMPtr <nsIPlatformCharset> platformCharset = do_GetService(NS_PLATFORMCHARSET_CONTRACTID, &res);
|
||||
if (NS_SUCCEEDED(res)) {
|
||||
PRUnichar mappedCharset[MAPPEDCHARSET_BUFFER_LEN] = { 0 };
|
||||
LocaleObject locObj = NULL;
|
||||
UniChar *pmCodepage;
|
||||
|
||||
int ret = UniCreateLocaleObject(UNI_UCS_STRING_POINTER, (UniChar *)mLocale.GetUnicode(), &locObj);
|
||||
if (ret != ULS_SUCCESS)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
ret = UniQueryLocaleItem(locObj, LOCI_iCodepage, &pmCodepage);
|
||||
if (ret != ULS_SUCCESS)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
int cpLen = UniStrlen((UniChar*)pmCodepage);
|
||||
UniStrncpy((UniChar *)mappedCharset, pmCodepage, cpLen);
|
||||
UniFreeMem(pmCodepage);
|
||||
UniFreeLocaleObject(locObj);
|
||||
PRUint32 mpLen = UniStrlen(mappedCharset);
|
||||
|
||||
if (NS_SUCCEEDED(ret) && mappedCharset) {
|
||||
mCharset.Assign((PRUnichar*)mappedCharset, mpLen);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// sort-key creation
|
||||
// get a length (of character) of a sort key to be generated by an
|
||||
// input string length is a byte length
|
||||
nsresult nsCollationOS2::GetSortKeyLen( const nsCollationStrength aStrength,
|
||||
const nsString &aStringIn,
|
||||
PRUint32 *aOutLen)
|
||||
|
||||
nsresult nsCollationOS2::GetSortKeyLen(const nsCollationStrength strength,
|
||||
const nsString& stringIn, PRUint32* outLen)
|
||||
{
|
||||
if( !aOutLen)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
// this may not necessary because collation key length
|
||||
// probably will not change by this normalization
|
||||
nsresult res = NS_OK;
|
||||
nsString stringNormalized = stringIn;
|
||||
if (strength != kCollationCaseSensitive) {
|
||||
res = mCollation->NormalizeString(stringNormalized);
|
||||
}
|
||||
|
||||
// XXXX M15 LAUNCH HACK: TODO: track down why we get here before Initialize has been called...
|
||||
if (!mLocaleObject)
|
||||
UniCreateLocaleObject(UNI_UCS_STRING_POINTER, (UniChar*)L"", &mLocaleObject);
|
||||
LocaleObject locObj = NULL;
|
||||
int ret = UniCreateLocaleObject(UNI_UCS_STRING_POINTER, (UniChar *)L"", &locObj);
|
||||
if (ret != ULS_SUCCESS)
|
||||
return NS_ERROR_FAILURE;
|
||||
int uLen = UniStrxfrm(locObj, NULL, stringNormalized.GetUnicode(), 0);
|
||||
|
||||
size_t num_elems = UniStrxfrm( mLocaleObject, nsnull,
|
||||
aStringIn.GetUnicode(), 0);
|
||||
|
||||
*aOutLen = 2 * num_elems; // out is in bytes
|
||||
|
||||
return NS_OK;
|
||||
*outLen = (uLen < 1) ? 0 : (PRUint32)uLen;
|
||||
return res;
|
||||
}
|
||||
|
||||
// create sort key from input string
|
||||
// length is a byte length, caller should allocate a memory for a key
|
||||
nsresult nsCollationOS2::CreateRawSortKey( const nsCollationStrength aStrength,
|
||||
const nsString &aStringIn,
|
||||
PRUint8 *aKey,
|
||||
PRUint32 *aOutLen)
|
||||
|
||||
nsresult nsCollationOS2::CreateRawSortKey(const nsCollationStrength strength,
|
||||
const nsString& stringIn, PRUint8* key, PRUint32* outLen)
|
||||
{
|
||||
if( !aKey || !aOutLen)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
nsresult res = NS_OK;
|
||||
|
||||
UniStrxfrm( mLocaleObject, (UniChar*) aKey,
|
||||
aStringIn.GetUnicode(), *aOutLen / 2 + 1);
|
||||
nsString stringNormalized = stringIn;
|
||||
if (strength != kCollationCaseSensitive) {
|
||||
res = mCollation->NormalizeString(stringNormalized);
|
||||
}
|
||||
|
||||
// XXX hmm
|
||||
if( aStrength & kCollationCaseInsensitiveAscii)
|
||||
{
|
||||
#if 0
|
||||
// XXX this is correct, but is it guaranteed not to alter the
|
||||
// length of key needed? Ought we to do this in the 'getkeylen'
|
||||
// function above as well?
|
||||
//
|
||||
// XXX Don't currently support the 'no accent' comparison; may have
|
||||
// to bite the bullet & use the mozilla function, if it ever
|
||||
// arrives.
|
||||
//
|
||||
XformObject xform_object = 0;
|
||||
int iSize = -1, oSize = aStringIn.Length() + 1;
|
||||
UniChar *xformed = new UniChar [ oSize];
|
||||
LocaleObject locObj = NULL;
|
||||
int ret = UniCreateLocaleObject(UNI_UCS_STRING_POINTER, (UniChar *)L"", &locObj);
|
||||
if (ret != ULS_SUCCESS)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
UniCreateTransformObject( mLocaleObject, L"lower", &xform_object);
|
||||
UniTransformStr( xform_object,
|
||||
(const UniChar *) aStringIn.GetUnicode(),
|
||||
&iSize, xformed, &oSize);
|
||||
UniFreeTransformObject( xform_object);
|
||||
UniStrxfrm( mLocaleObject, (UniChar*) aKey, xformed, *aOutLen / 2 + 1);
|
||||
delete [] xformed;
|
||||
#else
|
||||
UniStrlwr( (UniChar*) aKey);
|
||||
#endif
|
||||
}
|
||||
int length = UniStrlen(stringNormalized.GetUnicode());
|
||||
int uLen = UniStrxfrm(locObj, (UniChar*)key, stringNormalized.GetUnicode(), length);
|
||||
*outLen = (uLen < 1) ? 0 : (PRUint32)uLen;
|
||||
UniFreeMem(locObj);
|
||||
|
||||
return NS_OK;
|
||||
return res;
|
||||
}
|
||||
|
||||
// compare two sort keys
|
||||
// length is a byte length, result is same as strcmp
|
||||
nsresult nsCollationOS2::CompareRawSortKey( const PRUint8 *aKey1,
|
||||
const PRUint32 aLen1,
|
||||
const PRUint8 *aKey2,
|
||||
const PRUint32 aLen2,
|
||||
PRInt32 *aResult)
|
||||
{
|
||||
if( !aKey1 || !aKey2 || !aResult)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*aResult = UniStrcmp( (UniChar*) aKey1, (UniChar*) aKey2);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// create a sort key (nsString)
|
||||
nsresult nsCollationOS2::CreateSortKey( const nsCollationStrength aStrength,
|
||||
const nsString &aStringIn,
|
||||
nsString &aKey)
|
||||
{
|
||||
PRUint32 length = 0;
|
||||
PRUint8 *key = nsnull;
|
||||
|
||||
nsresult rc = GetSortKeyLen( aStrength, aStringIn, &length);
|
||||
|
||||
if( NS_SUCCEEDED(rc))
|
||||
{
|
||||
key = new PRUint8[ length];
|
||||
CreateRawSortKey( aStrength, aStringIn, key, &length);
|
||||
aKey.Assign( (PRUnichar*) key);
|
||||
delete [] key;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
// compare two sort keys (nsString)
|
||||
nsresult nsCollationOS2::CompareSortKey( const nsString &aKey1,
|
||||
const nsString &aKey2,
|
||||
PRInt32 *aResult)
|
||||
{
|
||||
return CompareRawSortKey( (const PRUint8 *) aKey1.GetUnicode(),
|
||||
(aKey1.Length() + 1) * 2,
|
||||
(const PRUint8 *) aKey2.GetUnicode(),
|
||||
(aKey2.Length() + 1) * 2,
|
||||
aResult);
|
||||
}
|
||||
|
||||
// compare two strings; result is same as strcmp
|
||||
nsresult nsCollationOS2::CompareString( const nsCollationStrength aStrength,
|
||||
const nsString &aString1,
|
||||
const nsString &aString2,
|
||||
PRInt32 *aResult)
|
||||
{
|
||||
if( !aResult)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
nsString key1, key2;
|
||||
|
||||
CreateSortKey( aStrength, aString1, key1);
|
||||
CreateSortKey( aStrength, aString2, key2);
|
||||
|
||||
return CompareSortKey( key1, key2, aResult);
|
||||
}
|
||||
|
||||
// nsCollationFactoryOS2 implementation
|
||||
|
||||
// nsISupports implementation
|
||||
NS_IMPL_ISUPPORTS(nsCollationFactoryOS2,kICollationFactoryIID)
|
||||
|
||||
// init/term
|
||||
nsCollationFactoryOS2::nsCollationFactoryOS2()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
nsCollationFactoryOS2::~nsCollationFactoryOS2()
|
||||
{
|
||||
}
|
||||
|
||||
// strange factory method
|
||||
nsresult nsCollationFactoryOS2::CreateCollation( nsILocale *aLocale,
|
||||
nsICollation **aInstance)
|
||||
{
|
||||
if( !aLocale || !aInstance)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*aInstance = nsnull;
|
||||
|
||||
nsCollationOS2 *coll = new nsCollationOS2;
|
||||
|
||||
if(nsnull == coll)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
nsresult rc = coll->Initialize( aLocale);
|
||||
|
||||
if( NS_SUCCEEDED(rc))
|
||||
{
|
||||
NS_ADDREF(coll);
|
||||
*aInstance = coll;
|
||||
}
|
||||
else
|
||||
delete coll;
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
|
|
@ -16,82 +16,66 @@
|
|||
* Copyright (C) 1999 John Fairhurst. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _nscollationos2_h_
|
||||
#define _nscollationos2_h_
|
||||
|
||||
#include <unidef.h>
|
||||
|
||||
#include "nsICollation.h"
|
||||
#include "nsCollation.h" // static library
|
||||
|
||||
class nsIOS2Locale;
|
||||
|
||||
class nsCollationOS2 : public nsICollation
|
||||
{
|
||||
public:
|
||||
nsCollationOS2();
|
||||
virtual ~nsCollationOS2();
|
||||
|
||||
// nsISupports
|
||||
NS_DECL_ISUPPORTS
|
||||
class nsCollationOS2 : public nsICollation {
|
||||
|
||||
// nsICollation
|
||||
// compare two strings; result is same as strcmp
|
||||
NS_IMETHOD CompareString( const nsCollationStrength aStrength,
|
||||
const nsString &aString1,
|
||||
const nsString &aString2,
|
||||
PRInt32 *aResult);
|
||||
protected:
|
||||
nsCollation *mCollation;
|
||||
nsString mLocale;
|
||||
nsString mSavedLocale;
|
||||
nsString mCharset;
|
||||
|
||||
// get a length (of character) of a sort key to be generated by an
|
||||
// input string length is a byte length
|
||||
NS_IMETHOD GetSortKeyLen( const nsCollationStrength aStrength,
|
||||
const nsString &aStringIn,
|
||||
PRUint32 *aOutLen);
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// create sort key from input string
|
||||
// length is a byte length, caller should allocate a memory for a key
|
||||
NS_IMETHOD CreateRawSortKey( const nsCollationStrength aStrength,
|
||||
const nsString &aStringIn,
|
||||
PRUint8 *aKey,
|
||||
PRUint32 *aOutLen);
|
||||
// compare two strings
|
||||
// result is same as strcmp
|
||||
NS_IMETHOD CompareString(const nsCollationStrength strength,
|
||||
const nsString& string1, const nsString& string2, PRInt32* result)
|
||||
{return mCollation->CompareString(this, strength, string1, string2, result);}
|
||||
|
||||
// create a sort key (nsString)
|
||||
NS_IMETHOD CreateSortKey( const nsCollationStrength aStrength,
|
||||
const nsString &aStringIn,
|
||||
nsString &aKey);
|
||||
// get a length (of character) of a sort key to be generated by an input string
|
||||
// length is a byte length
|
||||
NS_IMETHOD GetSortKeyLen(const nsCollationStrength strength,
|
||||
const nsString& stringIn, PRUint32* outLen);
|
||||
|
||||
// compare two sort keys
|
||||
// length is a byte length, result is same as strcmp
|
||||
NS_IMETHOD CompareRawSortKey( const PRUint8 *aKey1, const PRUint32 aLen1,
|
||||
const PRUint8 *aKey2, const PRUint32 aLen2,
|
||||
PRInt32 *aResult);
|
||||
// create sort key from input string
|
||||
// length is character length not byte length, caller to allocate a memory for a key
|
||||
NS_IMETHOD CreateRawSortKey(const nsCollationStrength strength,
|
||||
const nsString& stringIn, PRUint8* key, PRUint32* outLen);
|
||||
|
||||
// compare two sort keys (nsString)
|
||||
NS_IMETHOD CompareSortKey( const nsString &aKey1,
|
||||
const nsString &aKey2,
|
||||
PRInt32 *aResult);
|
||||
// create a sort key (nsString)
|
||||
NS_IMETHOD CreateSortKey(const nsCollationStrength strength,
|
||||
const nsString& stringIn, nsString& key)
|
||||
{return mCollation->CreateSortKey(this, strength, stringIn, key);}
|
||||
|
||||
// init to a specified locale
|
||||
NS_IMETHOD Initialize( nsILocale *aLocale);
|
||||
// compare two sort keys
|
||||
// length is character length not byte length, result is same as strcmp
|
||||
NS_IMETHOD CompareRawSortKey(const PRUint8* key1, const PRUint32 len1,
|
||||
const PRUint8* key2, const PRUint32 len2,
|
||||
PRInt32* result)
|
||||
{*result = mCollation->CompareRawSortKey(key1, len1, key2, len2);return NS_OK;}
|
||||
|
||||
protected:
|
||||
LocaleObject mLocaleObject;
|
||||
nsILocale *mLocale;
|
||||
// compare two sort keys (nsString)
|
||||
NS_IMETHOD CompareSortKey(const nsString& key1, const nsString& key2, PRInt32* result)
|
||||
{*result = mCollation->CompareSortKey(key1, key2);return NS_OK;}
|
||||
|
||||
// init this interface to a specified locale (should only be called by collation factory)
|
||||
//
|
||||
NS_IMETHOD Initialize(nsILocale* locale);
|
||||
|
||||
nsCollationOS2();
|
||||
|
||||
virtual ~nsCollationOS2();
|
||||
};
|
||||
|
||||
// Strange collationfactory class
|
||||
class nsCollationFactoryOS2 : public nsICollationFactory
|
||||
{
|
||||
public:
|
||||
nsCollationFactoryOS2();
|
||||
virtual ~nsCollationFactoryOS2();
|
||||
|
||||
// nsISupports
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsICollationFactory
|
||||
NS_IMETHOD CreateCollation( nsILocale *aLocale, nsICollation **aInstance);
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif /* nsCollationOS2_h__ */
|
||||
|
|
|
@ -15,164 +15,131 @@
|
|||
* <john_fairhurst@iname.com>. Portions created by John Fairhurst are
|
||||
* Copyright (C) 1999 John Fairhurst. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Contributor(s): Henry Sobotka <sobotka@axess.com> 01/2000 review and update
|
||||
*
|
||||
* This Original Code has been modified by IBM Corporation.
|
||||
* Modifications made by IBM described herein are
|
||||
* Copyright (c) International Business Machines
|
||||
* Corporation, 2000
|
||||
*
|
||||
* Modifications to Mozilla code or documentation
|
||||
* identified per MPL Section 3.3
|
||||
*
|
||||
* Date Modified by Description of modification
|
||||
* 07/05/2000 IBM Corp. Reworked file.
|
||||
*/
|
||||
|
||||
#define INCL_DOS
|
||||
#include <os2.h>
|
||||
#include "unidef.h"
|
||||
#include "ulsitem.h"
|
||||
|
||||
#include "unidef.h"
|
||||
#include "time.h"
|
||||
#include "plstr.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsICharsetConverterManager.h"
|
||||
#include "nsDateTimeFormatOS2.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsLocaleCID.h"
|
||||
#include "nsILocaleService.h"
|
||||
#include "nsIPlatformCharset.h"
|
||||
#include "nsIOS2Locale.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsCRT.h"
|
||||
|
||||
static NS_DEFINE_IID(kILocaleOS2IID, NS_IOS2LOCALE_IID);
|
||||
static NS_DEFINE_IID(kIDateTimeFormatIID, NS_IDATETIMEFORMAT_IID);
|
||||
static NS_DEFINE_CID(kOS2LocaleFactoryCID, NS_OS2LOCALEFACTORY_CID);
|
||||
static NS_DEFINE_CID(kCharsetConverterManagerCID, NS_ICHARSETCONVERTERMANAGER_CID);
|
||||
static NS_DEFINE_IID(kICharsetConverterManagerIID, NS_ICHARSETCONVERTERMANAGER_IID);
|
||||
static NS_DEFINE_CID(kLocaleServiceCID, NS_LOCALESERVICE_CID);
|
||||
static NS_DEFINE_CID(kPlatformCharsetCID, NS_PLATFORMCHARSET_CID);
|
||||
|
||||
// nsISupports implementation
|
||||
// NS_IMPL_ISUPPORTS(nsDateTimeFormatOS2,kIDateTimeFormatIID)
|
||||
NS_IMPL_THREADSAFE_ISUPPORTS(nsDateTimeFormatOS2,kIDateTimeFormatIID)
|
||||
|
||||
// ctor/dtor
|
||||
nsDateTimeFormatOS2::nsDateTimeFormatOS2()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
nsDateTimeFormatOS2::~nsDateTimeFormatOS2()
|
||||
nsresult nsDateTimeFormatOS2::FormatTime(nsILocale* locale,
|
||||
const nsDateFormatSelector dateFormatSelector,
|
||||
const nsTimeFormatSelector timeFormatSelector,
|
||||
const time_t timetTime,
|
||||
nsString &stringOut)
|
||||
{
|
||||
}
|
||||
|
||||
// nsIDateTimeFormat
|
||||
|
||||
nsresult nsDateTimeFormatOS2::FormatTime( nsILocale *aLocale,
|
||||
const nsDateFormatSelector aDateFormatSelector,
|
||||
const nsTimeFormatSelector aTimeFormatSelector,
|
||||
const time_t aTime,
|
||||
nsString &aStringOut)
|
||||
{
|
||||
struct tm *now = 0;
|
||||
now = localtime( &aTime); // XXX dodgy (this whole thing ought to be using
|
||||
// PRTimes etc., anyway)
|
||||
return FormatTMTime( aLocale, aDateFormatSelector, aTimeFormatSelector,
|
||||
now, aStringOut);
|
||||
return FormatTMTime(locale, dateFormatSelector, timeFormatSelector, localtime( &timetTime ), stringOut);
|
||||
}
|
||||
|
||||
// performs a locale sensitive date formatting operation on the struct tm parameter
|
||||
nsresult nsDateTimeFormatOS2::FormatTMTime( nsILocale *aLocale,
|
||||
const nsDateFormatSelector aDateFormatSelector,
|
||||
const nsTimeFormatSelector aTimeFormatSelector,
|
||||
const struct tm *aTime,
|
||||
nsString &aStringOut)
|
||||
nsresult nsDateTimeFormatOS2::FormatTMTime(nsILocale* locale,
|
||||
const nsDateFormatSelector dateFormatSelector,
|
||||
const nsTimeFormatSelector timeFormatSelector,
|
||||
const struct tm* tmTime,
|
||||
nsString &stringOut)
|
||||
{
|
||||
if( !aLocale || !aTime)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
#define NSDATETIME_FORMAT_BUFFER_LEN 80
|
||||
|
||||
nsCOMPtr <nsIOS2Locale> os2locale;
|
||||
nsresult rc = NS_ERROR_FAILURE;
|
||||
nsresult rc = NS_ERROR_FAILURE;
|
||||
UniChar uFmtD[NSDATETIME_FORMAT_BUFFER_LEN] = { 0 };
|
||||
UniChar uFmtT[NSDATETIME_FORMAT_BUFFER_LEN] = { 0 };
|
||||
UniChar *pString = NULL;
|
||||
LocaleObject locObj = NULL;
|
||||
int res = UniCreateLocaleObject(UNI_UCS_STRING_POINTER, (UniChar *)L"", &locObj);
|
||||
if (res != ULS_SUCCESS)
|
||||
return rc;
|
||||
|
||||
// find a sane locale object
|
||||
// set date format
|
||||
switch (dateFormatSelector) {
|
||||
case kDateFormatNone:
|
||||
UniStrcat( uFmtD, (UniChar*)L"");
|
||||
break;
|
||||
case kDateFormatLong:
|
||||
UniStrcat( uFmtD, (UniChar*)L"%c");
|
||||
break;
|
||||
case kDateFormatShort:
|
||||
UniStrcat( uFmtD, (UniChar*)L"%x");
|
||||
break;
|
||||
case kDateFormatYearMonth:
|
||||
UniQueryLocaleItem( locObj, DATESEP, &pString);
|
||||
UniStrcat( uFmtD, (UniChar*)L"%y");
|
||||
UniStrcat( uFmtD, pString);
|
||||
UniStrcat( uFmtD, (UniChar*)L"%m");
|
||||
UniFreeMem(pString);
|
||||
break;
|
||||
case kDateFormatWeekday:
|
||||
UniStrcat( uFmtD, (UniChar*)L"%a");
|
||||
break;
|
||||
default:
|
||||
UniStrcat( uFmtD, (UniChar*)L"");
|
||||
}
|
||||
|
||||
if( NS_SUCCEEDED(aLocale->QueryInterface( kILocaleOS2IID,
|
||||
getter_AddRefs(os2locale))))
|
||||
{
|
||||
LocaleObject locale_object = 0;
|
||||
os2locale->GetLocaleObject( &locale_object);
|
||||
// set time format
|
||||
switch (timeFormatSelector) {
|
||||
case kTimeFormatNone:
|
||||
UniStrcat( uFmtT, (UniChar*)L"");
|
||||
break;
|
||||
case kTimeFormatSeconds:
|
||||
UniStrcat( uFmtT, (UniChar*)L"%r");
|
||||
break;
|
||||
case kTimeFormatNoSeconds:
|
||||
UniStrcat( uFmtT, (UniChar*)L"%R");
|
||||
break;
|
||||
case kTimeFormatSecondsForce24Hour:
|
||||
UniStrcat( uFmtT, (UniChar*)L"%T");
|
||||
break;
|
||||
case kTimeFormatNoSecondsForce24Hour:
|
||||
UniStrcat( uFmtT, (UniChar*)L"%R");
|
||||
break;
|
||||
default:
|
||||
UniStrcat( uFmtT, (UniChar*)L"");
|
||||
}
|
||||
|
||||
// Build up a strftime-style format string - date first and then
|
||||
// time.
|
||||
//
|
||||
// XXX Usage of %c for "long date" copied from unix, even though
|
||||
// it's documented as producing time as well. Change it if
|
||||
// weird things happen.
|
||||
//
|
||||
// XXX Not sure when if ever we should look at PM_National in the
|
||||
// ini and override locale-defaults. Maybe only if this locale
|
||||
// is the same as the system's LC_TIME locale?
|
||||
//
|
||||
#define FORMAT_BUFF_LEN 20 // update this if things get complex below
|
||||
|
||||
UniChar format[ FORMAT_BUFF_LEN] = { 0 };
|
||||
PRUnichar buffer[NSDATETIME_FORMAT_BUFFER_LEN] = {0};
|
||||
UniStrcat( uFmtD, (UniChar*)L" ");
|
||||
UniStrcat( uFmtD, uFmtT);
|
||||
int length = UniStrftime(locObj, buffer, NSDATETIME_FORMAT_BUFFER_LEN, uFmtD, tmTime);
|
||||
UniFreeMem(locObj);
|
||||
|
||||
UniChar *pString = nsnull;
|
||||
if ( length != 0) {
|
||||
stringOut.Assign(buffer, length);
|
||||
rc = NS_OK;
|
||||
}
|
||||
|
||||
// date
|
||||
switch( aDateFormatSelector)
|
||||
{
|
||||
case kDateFormatNone:
|
||||
break;
|
||||
case kDateFormatLong:
|
||||
UniStrcat( format, (UniChar*)L"%c");
|
||||
break;
|
||||
case kDateFormatShort:
|
||||
UniStrcat( format, (UniChar*)L"%x");
|
||||
break;
|
||||
case kDateFormatYearMonth:
|
||||
UniQueryLocaleItem( locale_object, DATESEP, &pString);
|
||||
UniStrcat( format, (UniChar*)L"%y");
|
||||
UniStrcat( format, pString);
|
||||
UniStrcat( format, (UniChar*)L"%m");
|
||||
UniFreeMem( pString);
|
||||
break;
|
||||
case kDateFormatWeekday:
|
||||
UniStrcat( format, (UniChar*)L"%a");
|
||||
break;
|
||||
default:
|
||||
printf( "Unknown date format (%d)\n", aDateFormatSelector);
|
||||
break;
|
||||
}
|
||||
|
||||
// space between date & time
|
||||
if( aDateFormatSelector != kDateFormatNone &&
|
||||
aTimeFormatSelector != kTimeFormatNone)
|
||||
UniStrcat( format, (UniChar*)L" ");
|
||||
|
||||
// time
|
||||
switch( aTimeFormatSelector)
|
||||
{
|
||||
case kTimeFormatNone:
|
||||
break;
|
||||
case kTimeFormatSeconds:
|
||||
UniStrcat( format, (UniChar*)L"%r");
|
||||
break;
|
||||
case kTimeFormatNoSeconds:
|
||||
UniQueryLocaleItem( locale_object, TIMESEP, &pString);
|
||||
UniStrcat( format, (UniChar*)L"%I");
|
||||
UniStrcat( format, pString);
|
||||
UniStrcat( format, (UniChar*)L"%M %p");
|
||||
UniFreeMem( pString);
|
||||
break;
|
||||
case kTimeFormatSecondsForce24Hour:
|
||||
UniStrcat( format, (UniChar*)L"%T");
|
||||
break;
|
||||
case kTimeFormatNoSecondsForce24Hour:
|
||||
UniStrcat( format, (UniChar*)L"%R");
|
||||
break;
|
||||
default:
|
||||
printf( "Unknown time format (%d)\n", aTimeFormatSelector);
|
||||
break;
|
||||
}
|
||||
|
||||
// now produce the string (dodgy buffer - iwbn if the function
|
||||
// had a handy `pass-me-null-to-find-the-length' mode).
|
||||
UniChar buffer[ 100]; // surely ample?
|
||||
|
||||
size_t ret = UniStrftime( locale_object, buffer, 100, format, aTime);
|
||||
|
||||
if( ret == 0)
|
||||
{
|
||||
printf( "UniStrftime needs a bigger buffer, rethink\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
aStringOut.Assign( (const PRUnichar*) buffer);
|
||||
rc = NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
return rc;
|
||||
return rc;
|
||||
}
|
||||
|
||||
// performs a locale sensitive date formatting operation on the PRTime parameter
|
||||
|
@ -221,3 +188,4 @@ nsresult nsDateTimeFormatOS2::FormatPRExplodedTime(nsILocale* locale,
|
|||
|
||||
return FormatTMTime(locale, dateFormatSelector, timeFormatSelector, &tmTime, stringOut);
|
||||
}
|
||||
|
||||
|
|
|
@ -18,38 +18,32 @@
|
|||
* Contributor(s):
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _nsdatetimeformatos2_h_
|
||||
#define _nsdatetimeformatos2_h_
|
||||
|
||||
|
||||
#include "nsIDateTimeFormat.h"
|
||||
|
||||
class nsILocaleOS2;
|
||||
#define kPlatformLocaleLength 64
|
||||
|
||||
class nsDateTimeFormatOS2 : public nsIDateTimeFormat {
|
||||
|
||||
class nsDateTimeFormatOS2 : public nsIDateTimeFormat
|
||||
{
|
||||
public:
|
||||
nsDateTimeFormatOS2();
|
||||
virtual ~nsDateTimeFormatOS2();
|
||||
|
||||
// nsISupports
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIDateTimeFormat
|
||||
// performs a locale sensitive date formatting operation on the time_t parameter
|
||||
NS_IMETHOD FormatTime(nsILocale* locale,
|
||||
const nsDateFormatSelector dateFormatSelector,
|
||||
const nsTimeFormatSelector timeFormatSelector,
|
||||
const time_t timetTime,
|
||||
nsString& stringOut);
|
||||
|
||||
// performs a locale sensitive date formatting operation on a time_t
|
||||
NS_IMETHOD FormatTime( nsILocale *aLocale,
|
||||
const nsDateFormatSelector aDateFormatSelector,
|
||||
const nsTimeFormatSelector aTimeFormatSelector,
|
||||
const time_t aTime,
|
||||
nsString &aStringOut);
|
||||
|
||||
// performs a locale sensitive date formatting operation on the struct tm parameter
|
||||
NS_IMETHOD FormatTMTime( nsILocale *aLocale,
|
||||
const nsDateFormatSelector aDateFormatSelector,
|
||||
const nsTimeFormatSelector aTimeFormatSelector,
|
||||
const struct tm *aTime,
|
||||
nsString &aStringOut);
|
||||
// performs a locale sensitive date formatting operation on the struct tm parameter
|
||||
NS_IMETHOD FormatTMTime(nsILocale* locale,
|
||||
const nsDateFormatSelector dateFormatSelector,
|
||||
const nsTimeFormatSelector timeFormatSelector,
|
||||
const struct tm* tmTime,
|
||||
nsString& stringOut);
|
||||
|
||||
// performs a locale sensitive date formatting operation on the PRTime parameter
|
||||
NS_IMETHOD FormatPRTime(nsILocale* locale,
|
||||
|
@ -65,6 +59,18 @@ class nsDateTimeFormatOS2 : public nsIDateTimeFormat
|
|||
const PRExplodedTime* explodedTime,
|
||||
nsString& stringOut);
|
||||
|
||||
nsDateTimeFormatOS2() {NS_INIT_REFCNT();
|
||||
mLocale.SetLength(0);mAppLocale.SetLength(0);}
|
||||
|
||||
|
||||
virtual ~nsDateTimeFormatOS2() {}
|
||||
|
||||
private:
|
||||
|
||||
nsString mLocale;
|
||||
nsString mAppLocale;
|
||||
nsString mCharset;
|
||||
PRUint32 mLCID;
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif /* nsDateTimeFormatOS2_h__ */
|
||||
|
|
|
@ -1,242 +0,0 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.1 (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/MPL/
|
||||
*
|
||||
* 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 the Mozilla OS/2 libraries.
|
||||
*
|
||||
* The Initial Developer of the Original Code is John Fairhurst,
|
||||
* <john_fairhurst@iname.com>. Portions created by John Fairhurst are
|
||||
* Copyright (C) 1999 John Fairhurst. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): Henry Sobotka <sobotka@axess.com> 01/2000 review and update
|
||||
*
|
||||
* This Original Code has been modified by IBM Corporation.
|
||||
* Modifications made by IBM described herein are
|
||||
* Copyright (c) International Business Machines
|
||||
* Corporation, 2000
|
||||
*
|
||||
* Modifications to Mozilla code or documentation
|
||||
* identified per MPL Section 3.3
|
||||
*
|
||||
* Date Modified by Description of modification
|
||||
* 03/23/2000 IBM Corp. Fixed unitialized members in ctor.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "nscore.h"
|
||||
#include "nsISupports.h"
|
||||
#include "nsIFactory.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsCollation.h"
|
||||
#include "nsCollationOS2.h"
|
||||
#include "nsIScriptableDateFormat.h"
|
||||
#include "nsDateTimeFormatCID.h"
|
||||
#include "nsDateTimeFormatOS2.h"
|
||||
#include "nsIOS2Locale.h"
|
||||
#include "nsLocaleOS2.h"
|
||||
#include "nsLocaleFactoryOS2.h"
|
||||
#include "nsLocaleCID.h"
|
||||
|
||||
NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
|
||||
NS_DEFINE_IID(kIOS2LocaleIID, NS_IOS2LOCALE_IID);
|
||||
NS_DEFINE_IID(kLocaleFactoryOS2CID, NS_OS2LOCALEFACTORY_CID);
|
||||
NS_DEFINE_IID(kICollationFactoryIID, NS_ICOLLATIONFACTORY_IID);
|
||||
NS_DEFINE_IID(kICollationIID, NS_ICOLLATION_IID);
|
||||
NS_DEFINE_IID(kIDateTimeFormatIID, NS_IDATETIMEFORMAT_IID);
|
||||
NS_DEFINE_CID(kScriptableDateFormatCID, NS_SCRIPTABLEDATEFORMAT_CID);
|
||||
|
||||
// ctor/dtor
|
||||
nsLocaleFactoryOS2::nsLocaleFactoryOS2() : mSysLocale(nsnull),
|
||||
mAppLocale(nsnull)
|
||||
{
|
||||
// don't need to init the ref-count because XP nsLocaleFactory does that.
|
||||
// ??? Not sure the above comment is still valid
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
nsLocaleFactoryOS2::nsLocaleFactoryOS2(const nsCID &aClass) : mSysLocale(nsnull),
|
||||
mAppLocale(nsnull)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
mClassID = aClass;
|
||||
}
|
||||
|
||||
nsLocaleFactoryOS2::~nsLocaleFactoryOS2()
|
||||
{
|
||||
NS_IF_RELEASE(mSysLocale);
|
||||
NS_IF_RELEASE(mAppLocale);
|
||||
}
|
||||
|
||||
// nsILocaleFactory
|
||||
nsresult nsLocaleFactoryOS2::NewLocale( nsString **aCatList,
|
||||
nsString **aValList,
|
||||
PRUint8 aCount,
|
||||
nsILocale **aLocale)
|
||||
{
|
||||
if( !aCatList || !aValList || !aLocale)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*aLocale = nsnull;
|
||||
nsOS2Locale *aLoc = new nsOS2Locale;
|
||||
if(nsnull == aLoc)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
nsresult rc = aLoc->Init( aCatList, aValList, aCount);
|
||||
|
||||
if( NS_FAILED(rc))
|
||||
delete aLoc;
|
||||
else
|
||||
{
|
||||
NS_ADDREF(aLoc);
|
||||
*aLocale = (nsILocale*)aLoc;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
nsresult nsLocaleFactoryOS2::NewLocale( const nsString *aName,
|
||||
nsILocale **aLocale)
|
||||
{
|
||||
if( !aName || !aLocale)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*aLocale = nsnull;
|
||||
nsOS2Locale *aLoc = new nsOS2Locale;
|
||||
if(nsnull == aLoc)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
nsresult rc = aLoc->Init( *aName);
|
||||
|
||||
if( NS_FAILED(rc))
|
||||
delete aLoc;
|
||||
else
|
||||
{
|
||||
NS_ADDREF(aLoc);
|
||||
*aLocale = (nsILocale*)aLoc;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
nsresult nsLocaleFactoryOS2::GetSystemLocale( nsILocale **aSysLocale)
|
||||
{
|
||||
if( !aSysLocale)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
if( !mSysLocale)
|
||||
mSysLocale = new nsSystemLocale;
|
||||
|
||||
NS_ADDREF(mSysLocale);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult nsLocaleFactoryOS2::GetApplicationLocale( nsILocale **aAppLocale)
|
||||
{
|
||||
if( !aAppLocale)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
if( !mAppLocale)
|
||||
mAppLocale = new nsApplicationLocale;
|
||||
|
||||
NS_ADDREF(mAppLocale);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsLocaleFactoryOS2::CreateInstance(nsISupports* aOuter, REFNSIID aIID,
|
||||
void** aResult)
|
||||
{
|
||||
if (aResult == NULL) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
// Always NULL result, in case of failure
|
||||
*aResult = NULL;
|
||||
nsISupports *inst = 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(kIOS2LocaleIID)) {
|
||||
nsOS2Locale *localeImpl = new nsOS2Locale();
|
||||
if(localeImpl)
|
||||
localeImpl->AddRef();
|
||||
*aResult = (void*)localeImpl;
|
||||
}
|
||||
else if (aIID.Equals(kICollationFactoryIID)) {
|
||||
NS_NEWXPCOM(inst, nsCollationFactory);
|
||||
}
|
||||
else if (aIID.Equals(kICollationIID)) {
|
||||
NS_NEWXPCOM(inst, nsCollationOS2);
|
||||
}
|
||||
else if (aIID.Equals(kIDateTimeFormatIID)) {
|
||||
NS_NEWXPCOM(inst, nsDateTimeFormatOS2);
|
||||
}
|
||||
else if (aIID.Equals(nsIScriptableDateFormat::GetIID())) {
|
||||
inst = NEW_SCRIPTABLE_DATEFORMAT();
|
||||
}
|
||||
else if (mClassID.Equals(kScriptableDateFormatCID)) {
|
||||
inst = NEW_SCRIPTABLE_DATEFORMAT();
|
||||
}
|
||||
if (*aResult == NULL && !inst)
|
||||
return NS_NOINTERFACE;
|
||||
|
||||
nsresult ret = NS_OK;
|
||||
|
||||
if (inst) {
|
||||
NS_ADDREF(inst);
|
||||
ret = inst->QueryInterface(aIID, aResult);
|
||||
NS_RELEASE(inst);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* nsresult nsLocaleFactoryOS2::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
|
||||
nsLocaleFactoryOS2::LockFactory(PRBool aBool)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMPL_THREADSAFE_ISUPPORTS1(nsLocaleFactoryOS2, nsIFactory);
|
|
@ -1,64 +0,0 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.1 (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/MPL/
|
||||
*
|
||||
* 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 the Mozilla OS/2 libraries.
|
||||
*
|
||||
* The Initial Developer of the Original Code is John Fairhurst,
|
||||
* <john_fairhurst@iname.com>. Portions created by John Fairhurst are
|
||||
* Copyright (C) 1999 John Fairhurst. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _nslocalefactoryos2_h_
|
||||
#define _nslocalefactoryos2_h_
|
||||
|
||||
#include "nscore.h"
|
||||
#include "nsString.h"
|
||||
#include "nsISupports.h"
|
||||
#include "nsIFactory.h"
|
||||
#include "nsILocale.h"
|
||||
#include "nsIOS2Locale.h"
|
||||
#include "nsLocaleOS2.h" // for sys/app typedef (sorry!)
|
||||
|
||||
// Although we pretty-much do our own thing for locale on OS/2 due to the
|
||||
// rich set of native functions, it is necessary to derive this class from
|
||||
// the XP nsLocaleFactory to take advantage of the GetLocaleFromAcceptLanguage()
|
||||
// method. Doing this probably drags in a load of unused XP locale code :-(
|
||||
//
|
||||
class nsLocaleFactoryOS2 : public nsIFactory
|
||||
{
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIFACTORY
|
||||
|
||||
public:
|
||||
|
||||
nsLocaleFactoryOS2();
|
||||
virtual ~nsLocaleFactoryOS2();
|
||||
nsLocaleFactoryOS2(const nsCID &aClass);
|
||||
|
||||
// nsILocaleFactory
|
||||
NS_IMETHOD NewLocale( nsString **aCatList, nsString **aValList,
|
||||
PRUint8 aCount, nsILocale **aLocale);
|
||||
NS_IMETHOD NewLocale( const nsString *aLocaleName, nsILocale **aLocale);
|
||||
NS_IMETHOD GetSystemLocale( nsILocale **aSystemLocale);
|
||||
NS_IMETHOD GetApplicationLocale( nsILocale **aApplicationLocale);
|
||||
|
||||
protected:
|
||||
nsSystemLocale *mSysLocale;
|
||||
nsApplicationLocale *mAppLocale;
|
||||
|
||||
private:
|
||||
nsCID mClassID;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -18,7 +18,20 @@
|
|||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* This Original Code has been modified by IBM Corporation.
|
||||
* Modifications made by IBM described herein are
|
||||
* Copyright (c) International Business Machines
|
||||
* Corporation, 2000
|
||||
*
|
||||
* Modifications to Mozilla code or documentation
|
||||
* identified per MPL Section 3.3
|
||||
*
|
||||
* Date Modified by Description of modification
|
||||
* 07/05/2000 IBM Corp. Reworked file after unix version.
|
||||
*/
|
||||
|
||||
#include "nspr.h"
|
||||
#include "nsString.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIModule.h"
|
||||
#include "nsIComponentManager.h"
|
||||
|
@ -29,7 +42,8 @@
|
|||
#include "nsLocaleFactory.h"
|
||||
#include "nsLocaleCID.h"
|
||||
#include "nsIOS2Locale.h"
|
||||
#include "nsLocaleOS2.h"
|
||||
#include "nsOS2Locale.h"
|
||||
#include "nsOS2LocaleFactory.h"
|
||||
#include "nsCollationOS2.h"
|
||||
#include "nsIScriptableDateFormat.h"
|
||||
#include "nsDateTimeFormatOS2.h"
|
||||
|
@ -37,6 +51,7 @@
|
|||
#include "nsDateTimeFormatCID.h"
|
||||
#include "nsCollationCID.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsLanguageAtomService.h"
|
||||
|
||||
static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
|
||||
|
||||
|
@ -48,6 +63,11 @@ NS_DEFINE_IID(kILocaleFactoryIID,NS_ILOCALEFACTORY_IID);
|
|||
NS_DEFINE_CID(kOS2LocaleFactoryCID, NS_OS2LOCALEFACTORY_CID);
|
||||
NS_DEFINE_CID(kLocaleServiceCID, NS_LOCALESERVICE_CID);
|
||||
|
||||
//
|
||||
// for language atoms
|
||||
//
|
||||
NS_DEFINE_CID(kLanguageAtomServiceCID, NS_LANGUAGEATOMSERVICE_CID);
|
||||
|
||||
//
|
||||
// for the collation and formatting interfaces
|
||||
//
|
||||
|
@ -166,7 +186,7 @@ nsLocaleModule::GetClassObject(nsIComponentManager *aCompMgr,
|
|||
}
|
||||
}
|
||||
else if (aClass.Equals(kOS2LocaleFactoryCID)) {
|
||||
nsLocaleFactoryOS2 *factory = new nsLocaleFactoryOS2();
|
||||
nsOS2LocaleFactory *factory = new nsOS2LocaleFactory();
|
||||
if (!factory) {
|
||||
rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
@ -179,7 +199,7 @@ nsLocaleModule::GetClassObject(nsIComponentManager *aCompMgr,
|
|||
}
|
||||
else {
|
||||
// let the nsLocaleFactory logic take over from here
|
||||
nsLocaleFactoryOS2* factory = new nsLocaleFactoryOS2(aClass);
|
||||
nsLocaleOS2Factory* factory = new nsLocaleOS2Factory(aClass);
|
||||
if (!factory) {
|
||||
rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
@ -222,6 +242,8 @@ static Components gComponents[] = {
|
|||
NULL, },
|
||||
{ "Scriptable Date Format", &kScriptableDateFormatCID,
|
||||
NS_SCRIPTABLEDATEFORMAT_CONTRACTID, },
|
||||
{ "Language Atom Service", &kLanguageAtomServiceCID,
|
||||
NS_LANGUAGEATOMSERVICE_CONTRACTID, },
|
||||
};
|
||||
#define NUM_COMPONENTS (sizeof(gComponents) / sizeof(gComponents[0]))
|
||||
|
||||
|
|
|
@ -0,0 +1,173 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.1 (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/MPL/
|
||||
*
|
||||
* 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 the Mozilla OS/2 libraries.
|
||||
*
|
||||
* The Initial Developer of the Original Code is John Fairhurst,
|
||||
* <john_fairhurst@iname.com>. Portions created by John Fairhurst are
|
||||
* Copyright (C) 1999 John Fairhurst. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* This Original Code has been modified by IBM Corporation.
|
||||
* Modifications made by IBM described herein are
|
||||
* Copyright (c) International Business Machines
|
||||
* Corporation, 2000
|
||||
*
|
||||
* Modifications to Mozilla code or documentation
|
||||
* identified per MPL Section 3.3
|
||||
*
|
||||
* Date Modified by Description of modification
|
||||
*
|
||||
* 07/05/2000 IBM Corp. renamed file to nsOS2Locale.cpp from ns LocaleOS2.cpp
|
||||
* added implementation for GetPlatformLocale, and GetXPlatformLocale using Unix model
|
||||
* created ParseLocaleString method
|
||||
*/
|
||||
|
||||
#include "nsISupports.h"
|
||||
#include "nscore.h"
|
||||
#include "nsString.h"
|
||||
#include "nsILocale.h"
|
||||
#include "nsOS2Locale.h"
|
||||
#include "nsLocaleCID.h"
|
||||
#include "prprf.h"
|
||||
#include "nsFileSpec.h"
|
||||
|
||||
NS_DEFINE_IID(kIOS2LocaleIID, NS_IOS2LOCALE_IID);
|
||||
NS_DEFINE_IID(kOS2LocaleCID, NS_OS2LOCALE_CID);
|
||||
|
||||
/* nsOS2Locale ISupports */
|
||||
NS_IMPL_ISUPPORTS(nsOS2Locale,kIOS2LocaleIID)
|
||||
|
||||
nsOS2Locale::nsOS2Locale(void)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
nsOS2Locale::~nsOS2Locale(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsOS2Locale::GetPlatformLocale(PRUnichar* os2Locale, size_t length)
|
||||
{
|
||||
|
||||
LocaleObject locObj = NULL;
|
||||
int result = 0;
|
||||
UniChar *localeName = NULL;
|
||||
|
||||
int res = UniCreateLocaleObject(UNI_UCS_STRING_POINTER, (UniChar *)L"", &locObj);
|
||||
if (res != ULS_SUCCESS)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
res = UniQueryLocaleItem(locObj, LOCI_sName, &localeName);
|
||||
if (res != ULS_SUCCESS)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
UniStrncpy((UniChar*)os2Locale, localeName, length);
|
||||
UniFreeMem(localeName);
|
||||
UniFreeLocaleObject(locObj);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsOS2Locale::GetXPLocale(const char* os2Locale, nsString* locale)
|
||||
{
|
||||
char country_code[3];
|
||||
char lang_code[3];
|
||||
char extra[65];
|
||||
char os2_locale[128];
|
||||
|
||||
if (os2Locale!=nsnull) {
|
||||
if (strcmp(os2Locale,"C")==0 || strcmp(os2Locale,"OS2")==0) {
|
||||
locale->AssignWithConversion("en-US");
|
||||
return NS_OK;
|
||||
}
|
||||
if (!ParseLocaleString(os2Locale,lang_code,country_code,extra,'_')) {
|
||||
// * locale = "x-user-defined";
|
||||
locale->AssignWithConversion(os2Locale); // use os2 if parse failed
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (*country_code) {
|
||||
if (*extra) {
|
||||
PR_snprintf(os2_locale,128,"%s-%s.%s",lang_code,country_code,extra);
|
||||
}
|
||||
else {
|
||||
PR_snprintf(os2_locale,128,"%s-%s",lang_code,country_code);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (*extra) {
|
||||
PR_snprintf(os2_locale,128,"%s.%s",lang_code,extra);
|
||||
}
|
||||
else {
|
||||
PR_snprintf(os2_locale,128,"%s",lang_code);
|
||||
}
|
||||
}
|
||||
|
||||
locale->AssignWithConversion(os2Locale);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
//
|
||||
// returns PR_FALSE/PR_TRUE depending on if it was of the form LL-CC.Extra
|
||||
PRBool
|
||||
nsOS2Locale::ParseLocaleString(const char* locale_string, char* language, char* country, char* extra, char separator)
|
||||
{
|
||||
PRUint32 len = PL_strlen(locale_string);
|
||||
|
||||
*language = '\0';
|
||||
*country = '\0';
|
||||
*extra = '\0';
|
||||
|
||||
if (2 == len) {
|
||||
language[0]=locale_string[0];
|
||||
language[1]=locale_string[1];
|
||||
language[2]='\0';
|
||||
country[0]='\0';
|
||||
}
|
||||
else if (5 == len) {
|
||||
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';
|
||||
}
|
||||
else if (4 <= len && '.' == locale_string[2]) {
|
||||
PL_strcpy(extra, &locale_string[3]);
|
||||
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';
|
||||
}
|
||||
else if (7 <= len && '.' == locale_string[5]) {
|
||||
PL_strcpy(extra, &locale_string[6]);
|
||||
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';
|
||||
}
|
||||
else {
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
return PR_TRUE;
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.1 (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/MPL/
|
||||
*
|
||||
* 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 the Mozilla OS/2 libraries.
|
||||
*
|
||||
* The Initial Developer of the Original Code is John Fairhurst,
|
||||
* <john_fairhurst@iname.com>. Portions created by John Fairhurst are
|
||||
* Copyright (C) 1999 John Fairhurst. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
#ifndef _nslocaleos2_h_
|
||||
#define _nslocaleos2_h_
|
||||
|
||||
|
||||
#include "nsISupports.h"
|
||||
#include "nscore.h"
|
||||
#include "nsString.h"
|
||||
#include "nsIOS2Locale.h"
|
||||
|
||||
|
||||
class nsOS2Locale : public nsIOS2Locale {
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
public:
|
||||
|
||||
nsOS2Locale();
|
||||
virtual ~nsOS2Locale();
|
||||
|
||||
NS_IMETHOD GetPlatformLocale(PRUnichar* os2Locale,
|
||||
size_t length);
|
||||
NS_IMETHOD GetXPLocale(const char* os2Locale, nsString* locale);
|
||||
|
||||
protected:
|
||||
inline PRBool ParseLocaleString(const char* locale_string, char* language, char* country, char* extra, char separator);
|
||||
|
||||
};
|
||||
|
||||
#endif
|
Загрузка…
Ссылка в новой задаче