This commit is contained in:
nhotta%netscape.com 1999-01-21 23:40:32 +00:00
Родитель 7b8d4b7b11
Коммит ed95678fea
9 изменённых файлов: 492 добавлений и 0 удалений

Двоичные данные
intl/locale/macbuild/locale.mcp Normal file

Двоичный файл не отображается.

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

@ -0,0 +1,21 @@
/* -*- 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.
*/
#define _IMPL_NS_LOCALE 1
#define __STDC__
#include "MacPrefix_debug.h"

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

@ -0,0 +1,21 @@
/* -*- 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.
*/
#define _IMPL_NS_LOCALE 1
#define __STDC__
#include "MacSharedPrefix.h"

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

@ -0,0 +1,90 @@
/* -*- 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 "nsCollationMac.h"
NS_DEFINE_IID(kICollationIID, NS_ICOLLATION_IID);
NS_IMPL_ISUPPORTS(nsCollationMac, kICollationIID);
nsCollationMac::nsCollationMac()
{
NS_INIT_REFCNT();
mCollation = NULL;
}
nsCollationMac::~nsCollationMac()
{
if (mCollation != NULL)
delete mCollation;
}
nsresult nsCollationMac::Initialize(const nsString& locale)
{
mCollation = new nsCollation;
if (mCollation == NULL) {
return NS_ERROR_OUT_OF_MEMORY;
}
// locale -> LCID
return NS_OK;
};
nsresult nsCollationMac::GetSortKeyLen(const nsCollationStrength strength,
const nsString& stringIn, PRUint32* outLen)
{
*outLen = stringIn.Length() * sizeof(PRUnichar);
return NS_OK;
}
nsresult nsCollationMac::CreateSortKey(const nsCollationStrength strength,
const nsString& stringIn, PRUint8* key, PRUint32* outLen)
{
// temporary implementation, call FE eventually
PRUint32 byteLenIn = stringIn.Length() * sizeof(PRUnichar);
if (byteLenIn > *outLen) {
*outLen = 0;
}
else {
if (mCollation != NULL) {
mCollation->NormalizeString(stringIn);
}
if (strength != kCollationCaseSensitive) {
nsString *stringLower = new nsString(stringIn);
if (NULL == stringLower)
return NS_ERROR_OUT_OF_MEMORY;
stringLower->ToLowerCase();
memcpy((void *) key, (void *) stringLower->GetUnicode(), byteLenIn);
delete stringLower;
}
else {
memcpy((void *) key, (void *) stringIn.GetUnicode(), byteLenIn);
}
*outLen = byteLenIn;
}
return NS_OK;
}

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

@ -0,0 +1,68 @@
/* -*- 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 nsCollationMac_h__
#define nsCollationMac_h__
#include "nsICollation.h"
#include "nsCollation.h" // static library
class nsCollationMac : public nsICollation {
public:
NS_DECL_ISUPPORTS
// 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);};
// get a length (of character) of a sort key to be generated by an input string
// length is character length not byte length
NS_IMETHOD GetSortKeyLen(const nsCollationStrength strength,
const nsString& stringIn, PRUint32* outLen);
// create sort key from input string
// length is character length not byte length, caller to allocate a memory for a key
NS_IMETHOD CreateSortKey(const nsCollationStrength strength,
const nsString& stringIn, PRUint8* key, PRUint32* outLen);
// compare two sort keys
// length is character length not byte length, result is same as strcmp
NS_IMETHOD CompareSortKey(const PRUint8* key1, const PRUint32 len1,
const PRUint8* key2, const PRUint32 len2,
PRInt32* result)
{*result = mCollation->CompareSortKey(key1, len1, key2, len2);return NS_OK;};
// init this interface to a specified locale (should only be called by collation factory)
//
NS_IMETHOD Initialize(const nsString& locale);
nsCollationMac();
virtual ~nsCollationMac();
protected:
nsCollation *mCollation;
};
#endif /* nsCollationMac_h__ */

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

@ -0,0 +1,67 @@
/* -*- 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 "nsDateTimeFormatMac.h"
NS_DEFINE_IID(kIDateTimeFormatIID, NS_IDATETIMEFORMAT_IID);
NS_IMPL_ISUPPORTS(nsDateTimeFormatMac, kIDateTimeFormatIID);
nsresult nsDateTimeFormatMac::FormatTime(const nsString& locale,
const nsDateFormatSelector dateFormatSelector,
const nsTimeFormatSelector timeFormatSelector,
const time_t timetTime,
PRUnichar *stringOut,
PRUint32 *outLen)
{
// Temporary implementation, real implementation to be done by FE.
//
struct tm *today;
char *str;
today = localtime( &timetTime );
str = asctime(today);
nsString aString(str);
*outLen = aString.Length();
memcpy((void *) stringOut, (void *) aString.GetUnicode(), aString.Length() * sizeof(PRUnichar));
return NS_OK;
}
// performs a locale sensitive date formatting operation on the struct tm parameter
// locale RFC1766 (e.g. "en-US"), caller should allocate the buffer, outLen is in/out
nsresult nsDateTimeFormatMac::FormatTMTime(const nsString& locale,
const nsDateFormatSelector dateFormatSelector,
const nsTimeFormatSelector timeFormatSelector,
const struct tm* tmTime,
PRUnichar *stringOut,
PRUint32 *outLen)
{
// Temporary implementation, real implementation to be done by FE.
//
char *str = asctime(tmTime);
nsString aString(str);
*outLen = aString.Length();
memcpy((void *) stringOut, (void *) aString.GetUnicode(), aString.Length() * sizeof(PRUnichar));
return NS_OK;
}

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

@ -0,0 +1,52 @@
/* -*- 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 nsDateTimeFormatMac_h__
#define nsDateTimeFormatMac_h__
#include "nsIDateTimeFormat.h"
class nsDateTimeFormatMac : public nsIDateTimeFormat {
public:
NS_DECL_ISUPPORTS
// performs a locale sensitive date formatting operation on the time_t parameter
// locale RFC1766 (e.g. "en-US"), caller should allocate the buffer, outLen is in/out
NS_IMETHOD FormatTime(const nsString& locale,
const nsDateFormatSelector dateFormatSelector,
const nsTimeFormatSelector timeFormatSelector,
const time_t timetTime,
PRUnichar *stringOut,
PRUint32 *outLen);
// performs a locale sensitive date formatting operation on the struct tm parameter
// locale RFC1766 (e.g. "en-US"), caller should allocate the buffer, outLen is in/out
NS_IMETHOD FormatTMTime(const nsString& locale,
const nsDateFormatSelector dateFormatSelector,
const nsTimeFormatSelector timeFormatSelector,
const struct tm* tmTime,
PRUnichar *stringOut,
PRUint32 *outLen);
nsDateTimeFormatMac() {NS_INIT_REFCNT();};
};
#endif /* nsDateTimeFormatMac_h__ */

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

@ -0,0 +1,173 @@
/* -*- 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 "nscore.h"
#include "nsISupports.h"
#include "nsIFactory.h"
#include "nsCollationMac.h"
#include "nsDateTimeFormatMac.h"
NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
NS_DEFINE_IID(kICollationFactoryIID, NS_ICOLLATIONFACTORY_IID);
NS_DEFINE_IID(kICollationIID, NS_ICOLLATION_IID);
NS_DEFINE_IID(kIDateTimeFormatIID, NS_IDATETIMEFORMAT_IID);
class nsLocaleMacFactory : public nsIFactory
{
public:
// nsISupports methods
NS_IMETHOD QueryInterface(const nsIID &aIID,
void **aResult);
NS_IMETHOD_(nsrefcnt) AddRef(void);
NS_IMETHOD_(nsrefcnt) Release(void);
// nsIFactory methods
NS_IMETHOD CreateInstance(nsISupports *aOuter,
const nsIID &aIID,
void **aResult);
NS_IMETHOD LockFactory(PRBool aLock);
nsLocaleMacFactory(const nsCID &aClass);
~nsLocaleMacFactory();
private:
nsrefcnt mRefCnt;
nsCID mClassID;
};
nsLocaleMacFactory::nsLocaleMacFactory(const nsCID &aClass)
{
mRefCnt = 0;
mClassID = aClass;
}
nsLocaleMacFactory::~nsLocaleMacFactory()
{
NS_ASSERTION(mRefCnt == 0, "non-zero refcnt at destruction");
}
nsresult nsLocaleMacFactory::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;
}
nsrefcnt nsLocaleMacFactory::AddRef()
{
return ++mRefCnt;
}
nsrefcnt nsLocaleMacFactory::Release()
{
if (--mRefCnt == 0) {
delete this;
return 0; // Don't access mRefCnt after deleting!
}
return mRefCnt;
}
nsresult nsLocaleMacFactory::CreateInstance(nsISupports *aOuter,
const nsIID &aIID,
void **aResult)
{
if (aResult == NULL) {
return NS_ERROR_NULL_POINTER;
}
*aResult = NULL;
nsISupports *inst = NULL;
if (aIID.Equals(kICollationFactoryIID)) {
NS_NEWXPCOM(inst, nsCollationFactory);
}
else if (aIID.Equals(kICollationIID)) {
NS_NEWXPCOM(inst, nsCollationMac);
}
else if (aIID.Equals(kIDateTimeFormatIID)) {
NS_NEWXPCOM(inst, nsDateTimeFormatMac);
}
else
{
return NS_NOINTERFACE;
}
if (NULL == inst) {
return NS_ERROR_OUT_OF_MEMORY;
}
nsresult res = inst->QueryInterface(aIID, aResult);
if(NS_FAILED(res)) {
delete inst;
}
return res;
}
nsresult nsLocaleMacFactory::LockFactory(PRBool aLock)
{
// Not implemented in simplest case.
return NS_OK;
}
// return the proper factory to the caller
//
extern "C" NS_EXPORT nsresult NSGetFactory(const nsCID &aCID, nsIFactory **aFactory)
{
if (NULL == aFactory) {
return NS_ERROR_NULL_POINTER;
}
nsIFactory *inst = NULL;
inst = new nsLocaleMacFactory(aCID);
if(NULL == inst) {
return NS_ERROR_OUT_OF_MEMORY;
}
nsresult res = inst->QueryInterface(kIFactoryIID, (void**)aFactory);
if (NS_FAILED(res)) {
*aFactory = NULL;
delete inst;
}
return res;
}

Двоичные данные
intl/locale/tests/macbuild/LocaleSelfTest.mcp Normal file

Двоичный файл не отображается.