b=255134, make nsICollation scriptable, r=jshin,sr=brendan

This commit is contained in:
vladimir%pobox.com 2004-08-24 22:50:33 +00:00
parent 8c51b0df75
commit 0b8d1522a5
30 changed files with 208 additions and 281 deletions

View File

@ -524,7 +524,7 @@ XULSortServiceImpl::CompareNodes(nsIRDFNode *cellNode1, PRBool isCollationKey1,
nsresult rv = NS_ERROR_FAILURE;
nsDependentString lstr(luni), rstr(runi);
if (gCollation)
rv = gCollation->CompareString(kCollationCaseInSensitive, lstr, rstr, &sortOrder);
rv = gCollation->CompareString(nsICollation::kCollationCaseInSensitive, lstr, rstr, &sortOrder);
if (NS_FAILED(rv))
sortOrder = Compare(lstr, rstr, nsCaseInsensitiveStringComparator());
return NS_OK;

View File

@ -1915,7 +1915,7 @@ nsXULTreeBuilder::CompareMatches(nsTemplateMatch* aLeft, nsTemplateMatch* aRight
r->GetValueConst(&rstr);
if (mCollation) {
mCollation->CompareString(kCollationCaseInSensitive,
mCollation->CompareString(nsICollation::kCollationCaseInSensitive,
nsDependentString(lstr),
nsDependentString(rstr),
&result);

View File

@ -429,7 +429,7 @@ LocaleCompare(JSContext *cx, JSString *src1, JSString *src2, jsval *rval)
}
PRInt32 result;
rv = gCollation->CompareString(kCollationStrengthDefault,
rv = gCollation->CompareString(nsICollation::kCollationStrengthDefault,
nsDependentJSString(src1),
nsDependentJSString(src2),
&result);

View File

@ -133,7 +133,7 @@ TxObject* txResultStringComparator::createSortableValue(txAExprResult* aExprRes)
if (nsCaseKey.IsEmpty()) {
return val;
}
nsresult rv = mCollation->AllocateRawSortKey(kCollationCaseInSensitive,
nsresult rv = mCollation->AllocateRawSortKey(nsICollation::kCollationCaseInSensitive,
nsCaseKey,
&val->mKey,
&val->mLength);
@ -198,7 +198,7 @@ int txResultStringComparator::compareValues(TxObject* aVal1, TxObject* aVal2)
if ((strval1->mCaseLength == 0) && (strval1->mLength != 0)) {
nsString* caseString = (nsString *)strval1->mCaseKey;
rv = mCollation->AllocateRawSortKey(kCollationCaseSensitive,
rv = mCollation->AllocateRawSortKey(nsICollation::kCollationCaseSensitive,
*caseString,
(PRUint8**)&strval1->mCaseKey,
&strval1->mCaseLength);
@ -212,7 +212,7 @@ int txResultStringComparator::compareValues(TxObject* aVal1, TxObject* aVal2)
}
if ((strval2->mCaseLength == 0) && (strval2->mLength != 0)) {
nsString* caseString = (nsString *)strval2->mCaseKey;
rv = mCollation->AllocateRawSortKey(kCollationCaseSensitive,
rv = mCollation->AllocateRawSortKey(nsICollation::kCollationCaseSensitive,
*caseString,
(PRUint8**)&strval2->mCaseKey,
&strval2->mCaseLength);

View File

@ -44,9 +44,8 @@
#ifndef TX_EXE
#include "nsCOMPtr.h"
#include "nsICollation.h"
#else
#include "nsString.h"
#endif
#include "nsString.h"
class txAExprResult;
@ -88,7 +87,7 @@ private:
#ifndef TX_EXE
nsCOMPtr<nsICollation> mCollation;
nsresult init(const nsAFlatString& aLanguage);
nsresult createRawSortKey(const nsCollationStrength aStrength,
nsresult createRawSortKey(const PRInt32 aStrength,
const nsString& aString,
PRUint8** aKey,
PRUint32* aLength);

View File

@ -323,7 +323,7 @@ static nsModuleComponentInfo components[] =
CreateLocaleService },
{ "Collation factory",
NS_COLLATIONFACTORY_CID,
NULL,
NS_COLLATIONFACTORY_CONTRACTID,
nsCollationFactoryConstructor },
{ "Scriptable Date Format",
NS_SCRIPTABLEDATEFORMAT_CID,
@ -345,7 +345,7 @@ static nsModuleComponentInfo components[] =
nsIWin32LocaleImplConstructor },
{ "Collation",
NS_COLLATION_CID,
NULL,
NS_COLLATION_CONTRACTID,
nsCollationWinConstructor },
{ "Date/Time formatter",
NS_DATETIMEFORMAT_CID,
@ -361,7 +361,7 @@ static nsModuleComponentInfo components[] =
{ "Collation",
NS_COLLATION_CID,
NULL,
NS_COLLATION_CONTRACTID,
nsCollationUnixConstructor },
{ "Date/Time formatter",
@ -377,7 +377,7 @@ static nsModuleComponentInfo components[] =
nsMacLocaleConstructor },
{ "Collation",
NS_COLLATION_CID,
NULL,
NS_COLLATION_CONTRACTID,
#ifdef USE_UCCOLLATIONKEY
nsCollationMacUCConstructor },
#else
@ -396,7 +396,7 @@ static nsModuleComponentInfo components[] =
nsOS2LocaleConstructor },
{ "Collation",
NS_COLLATION_CID,
NULL,
NS_COLLATION_CONTRACTID,
nsCollationOS2Constructor },
{ "Date/Time formatter",
NS_DATETIMEFORMAT_CID,

View File

@ -52,6 +52,7 @@ XPIDLSRCS = \
nsILocale.idl \
nsILocaleService.idl \
nsIScriptableDateFormat.idl \
nsICollation.idl \
$(NULL)
include $(topsrcdir)/config/rules.mk

View File

@ -0,0 +1,84 @@
/* -*- Mode: idl; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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 mozilla.org code.
*
* The Initial Developer of the Original Code is
* mozilla.org
* Portions created by the Initial Developer are Copyright (C) 2004
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsILocale.idl"
interface nsICollation;
[scriptable, uuid(D4CF2F80-A98B-11d2-9119-006008A6EDF6)]
interface nsICollationFactory : nsISupports {
nsICollation CreateCollation(in nsILocale locale);
};
[scriptable, uuid(CDBFD3F0-A4FE-11d2-9119-006008A6EDF6)]
interface nsICollation : nsISupports {
// use the primary comparison for the given local - no flags
const long kCollationStrengthDefault = 0;
// do not consider case differences when doing the comparison i.e. A=a)
const long kCollationCaseInsensitiveAscii = 1;
// do not consider accent differences when doing the comparison a=á)
const long kCollationAccentInsenstive = 2;
// case sensitive collation (default)
const long kCollationCaseSensitive = kCollationStrengthDefault;
// case insensitive collation
const long kCollationCaseInSensitive = (kCollationCaseInsensitiveAscii | kCollationAccentInsenstive);
// init this interface to a specified locale (should only be called by collation factory)
void initialize(in nsILocale locale);
// compare two strings
// result is same as strcmp
long compareString(in long strength, in AString string1, in AString string2);
// allocate sort key from input string
// returns newly allocated key, and its band its byte length
[noscript] void allocateRawSortKey(in long strength,
in AString stringIn,
[array,size_is(outLen)] out octet key,
out unsigned long outLen);
// compare two sort keys
// length is a byte length, result is same as strcmp
[noscript] long compareRawSortKey([const,array,size_is(len1)] in octet key1, in unsigned long len1,
[const,array,size_is(len2)] in octet key2, in unsigned long len2);
};

View File

@ -47,7 +47,6 @@ MODULE = locale
EXPORTS = \
nsCollationCID.h \
nsDateTimeFormatCID.h \
nsICollation.h \
nsIDateTimeFormat.h \
nsILanguageAtomService.h \
nsIMacLocale.h \

View File

@ -46,10 +46,14 @@
{ 0xaa13e4a0, 0xa5ac, 0x11d2, \
{ 0x91, 0x19, 0x0, 0x60, 0x8, 0xa6, 0xed, 0xf6 } }
#define NS_COLLATION_CONTRACTID "@mozilla.org/intl/collation;1"
// {A1B72850-A999-11d2-9119-006008A6EDF6}
#define NS_COLLATIONFACTORY_CID \
{ 0xa1b72850, 0xa999, 0x11d2, \
{ 0x91, 0x19, 0x0, 0x60, 0x8, 0xa6, 0xed, 0xf6 } }
#define NS_COLLATIONFACTORY_CONTRACTID "@mozilla.org/intl/collation-factory;1"
#endif // nsCollationCID_h__

View File

@ -1,107 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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 mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsICollation_h__
#define nsICollation_h__
#include "nsISupports.h"
#include "nscore.h"
#include "nsString.h"
#include "nsILocale.h"
// {D4CF2F80-A98B-11d2-9119-006008A6EDF6}
#define NS_ICOLLATIONFACTORY_IID \
{ 0xd4cf2f80, 0xa98b, 0x11d2, \
{ 0x91, 0x19, 0x0, 0x60, 0x8, 0xa6, 0xed, 0xf6 } }
// {CDBFD3F0-A4FE-11d2-9119-006008A6EDF6}
#define NS_ICOLLATION_IID \
{ 0xcdbfd3f0, 0xa4fe, 0x11d2, \
{ 0x91, 0x19, 0x0, 0x60, 0x8, 0xa6, 0xed, 0xf6 } }
typedef enum {
kCollationStrengthDefault = 0, // use the primary comparison for the given local - no flags)
kCollationCaseInsensitiveAscii = 1, // do not consider case differences when doing the comparison i.e. A=a)
kCollationAccentInsenstive = 2, // do not consider accent differences when doing the comparison a=á)
kCollationCaseSensitive = kCollationStrengthDefault,
kCollationCaseInSensitive = (kCollationCaseInsensitiveAscii | kCollationAccentInsenstive)
} nsCollationStrength;
class nsICollation;
// Create a collation interface for an input locale.
//
class nsICollationFactory : public nsISupports {
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_ICOLLATIONFACTORY_IID)
NS_IMETHOD CreateCollation(nsILocale* locale, nsICollation** instancePtr) = 0;
};
// Locale sensitive collation interface
//
class nsICollation : public nsISupports {
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_ICOLLATION_IID)
// compare two strings
// result is same as strcmp
NS_IMETHOD CompareString(const nsCollationStrength strength,
const nsAString& string1, const nsAString& string2, PRInt32* result) = 0;
// allocate sort key from input string
// returns newly allocated key and its byte length
NS_IMETHOD AllocateRawSortKey(const nsCollationStrength strength,
const nsAString& stringIn, PRUint8** key, PRUint32 *outLen) = 0;
// compare two sort keys
// length is a byte length, result is same as strcmp
NS_IMETHOD CompareRawSortKey(const PRUint8* key1, const PRUint32 len1,
const PRUint8* key2, const PRUint32 len2,
PRInt32* result) = 0;
// init this interface to a specified locale (should only be called by collation factory)
//
NS_IMETHOD Initialize(nsILocale* locale) = 0;
};
#endif /* nsICollation_h__ */

View File

@ -198,7 +198,7 @@ nsresult nsCollationMac::Initialize(nsILocale* locale)
};
nsresult nsCollationMac::CompareString(const nsCollationStrength strength,
nsresult nsCollationMac::CompareString(PRInt32 strength,
const nsAString& string1, const nsAString& string2, PRInt32* result)
{
PRUint32 aLength1, aLength2;
@ -220,7 +220,7 @@ nsresult nsCollationMac::CompareString(const nsCollationStrength strength,
}
nsresult nsCollationMac::AllocateRawSortKey(const nsCollationStrength strength,
nsresult nsCollationMac::AllocateRawSortKey(PRInt32 strength,
const nsAString& stringIn, PRUint8** key, PRUint32* outLen)
{
nsresult res = NS_OK;
@ -274,3 +274,10 @@ nsresult nsCollationMac::AllocateRawSortKey(const nsCollationStrength strength,
return NS_OK;
}
nsresult nsCollationMac::CompareRawSortKey(const PRUint8* key1, PRUint32 len1,
const PRUint8* key2, PRUint32 len2,
PRInt32* result)
{
*result = PL_strcmp((const char *)key1, (const char *)key2);
return NS_OK;
}

View File

@ -55,32 +55,14 @@ protected:
unsigned char m_mac_sort_tbl[256]; // Mapping table from a character code to a collation key value.
public:
NS_DECL_ISUPPORTS
// compare two strings
// result is same as strcmp
NS_IMETHOD CompareString(const nsCollationStrength strength,
const nsAString& string1, const nsAString& string2, PRInt32* result);
// allocate sort key from input string
// returns newly allocated key and its byte length
NS_IMETHOD AllocateRawSortKey(const nsCollationStrength strength,
const nsAString& stringIn, PRUint8** key, PRUint32 *outLen);
// 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 = PL_strcmp((const char *)key1, (const char *)key2); return NS_OK;}
// init this interface to a specified locale (should only be called by collation factory)
//
NS_IMETHOD Initialize(nsILocale* locale);
nsCollationMac();
~nsCollationMac();
virtual ~nsCollationMac();
// nsISupports interface
NS_DECL_ISUPPORTS
// nsICollation interface
NS_DECL_NSICOLLATION
};

View File

@ -68,7 +68,7 @@ nsCollationMacUC::~nsCollationMacUC()
}
nsresult nsCollationMacUC::StrengthToOptions(
const nsCollationStrength aStrength,
const PRInt32 aStrength,
UCCollateOptions* aOptions)
{
NS_ENSURE_ARG_POINTER(aOptions);
@ -102,7 +102,7 @@ nsresult nsCollationMacUC::ConvertLocale(
}
nsresult nsCollationMacUC::EnsureCollator(
const nsCollationStrength newStrength)
const PRInt32 newStrength)
{
NS_ENSURE_TRUE(mInit, NS_ERROR_NOT_INITIALIZED);
if (mHasCollator && (mLastStrength == newStrength))
@ -154,7 +154,7 @@ NS_IMETHODIMP nsCollationMacUC::Initialize(
NS_IMETHODIMP nsCollationMacUC::AllocateRawSortKey(
const nsCollationStrength strength,
PRInt32 strength,
const nsAString& stringIn,
PRUint8** key,
PRUint32* outLen)
@ -202,7 +202,7 @@ NS_IMETHODIMP nsCollationMacUC::AllocateRawSortKey(
NS_IMETHODIMP nsCollationMacUC::CompareString(
const nsCollationStrength strength,
PRInt32 strength,
const nsAString& string1,
const nsAString& string2,
PRInt32* result)
@ -227,8 +227,8 @@ NS_IMETHODIMP nsCollationMacUC::CompareString(
NS_IMETHODIMP nsCollationMacUC::CompareRawSortKey(
const PRUint8* key1, const PRUint32 len1,
const PRUint8* key2, const PRUint32 len2,
const PRUint8* key1, PRUint32 len1,
const PRUint8* key2, PRUint32 len2,
PRInt32* result)
{
NS_ENSURE_TRUE(mInit, NS_ERROR_NOT_INITIALIZED);

View File

@ -54,38 +54,26 @@ const PRUint32 kCollationValueSizeFactor = 5;
class nsCollationMacUC : public nsICollation {
public:
nsCollationMacUC();
~nsCollationMacUC();
// nsISupports interface
NS_DECL_ISUPPORTS
nsCollationMacUC();
virtual ~nsCollationMacUC();
NS_IMETHOD CompareString(const nsCollationStrength strength,
const nsAString& string1,
const nsAString& string2,
PRInt32* result) ;
NS_IMETHOD AllocateRawSortKey(const nsCollationStrength strength,
const nsAString& stringIn,
PRUint8** key, PRUint32* outLen);
NS_IMETHOD CompareRawSortKey(const PRUint8* key1, const PRUint32 len1,
const PRUint8* key2, const PRUint32 len2,
PRInt32* result);
NS_IMETHOD Initialize(nsILocale* locale);
// nsICollation interface
NS_DECL_NSICOLLATION
protected:
nsresult ConvertLocale(nsILocale* aNSLocale, LocaleRef* aMacLocale);
nsresult StrengthToOptions(const nsCollationStrength aStrength,
nsresult StrengthToOptions(const PRInt32 aStrength,
UCCollateOptions* aOptions);
nsresult EnsureCollator(const nsCollationStrength newStrength);
nsresult EnsureCollator(const PRInt32 newStrength);
private:
PRPackedBool mInit;
PRPackedBool mHasCollator;
LocaleRef mLocale;
nsCollationStrength mLastStrength;
PRInt32 mLastStrength;
CollatorRef mCollator;
void *mBuffer; // temporary buffer to generate collation keys
PRUint32 mBufferLen; // byte length of buffer

View File

@ -92,7 +92,7 @@ nsresult nsCollationOS2::Initialize(nsILocale *locale)
}
nsresult nsCollationOS2::CompareString(const nsCollationStrength strength,
nsresult nsCollationOS2::CompareString(PRInt32 strength,
const nsAString& string1, const nsAString& string2, PRInt32* result)
{
nsAutoString stringNormalized1, stringNormalized2;
@ -124,7 +124,7 @@ nsresult nsCollationOS2::CompareString(const nsCollationStrength strength,
}
nsresult nsCollationOS2::AllocateRawSortKey(const nsCollationStrength strength,
nsresult nsCollationOS2::AllocateRawSortKey(PRInt32 strength,
const nsAString& stringIn, PRUint8** key, PRUint32* outLen)
{
nsresult res = NS_OK;
@ -182,3 +182,10 @@ nsresult nsCollationOS2::AllocateRawSortKey(const nsCollationStrength strength,
return res;
}
nsresult nsCollationOS2::CompareRawSortKey(const PRUint8* key1, PRUint32 len1,
const PRUint8* key2, PRUint32 len2,
PRInt32* result)
{
*result = PL_strcmp((const char *)key1, (const char *)key2);
return NS_OK;
}

View File

@ -51,32 +51,15 @@ protected:
nsString mSavedLocale;
public:
nsCollationOS2();
~nsCollationOS2();
// nsISupports interface
NS_DECL_ISUPPORTS
// compare two strings
// result is same as strcmp
NS_IMETHOD CompareString(const nsCollationStrength strength,
const nsAString& string1, const nsAString& string2, PRInt32* result);
// nsICollation interface
NS_DECL_NSICOLLATION
// allocate sort key from input string
// returns newly allocated key and its byte length
NS_IMETHOD AllocateRawSortKey(const nsCollationStrength strength,
const nsAString& stringIn, PRUint8** key, PRUint32 *outLen);
// 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 = nsCRT::strcmp((PRUnichar *)key1, (PRUnichar *)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();
};
#endif /* nsCollationOS2_h__ */

View File

@ -160,7 +160,7 @@ nsresult nsCollationUnix::Initialize(nsILocale* locale)
}
nsresult nsCollationUnix::CompareString(const nsCollationStrength strength,
nsresult nsCollationUnix::CompareString(PRInt32 strength,
const nsAString& string1,
const nsAString& string2,
PRInt32* result)
@ -206,7 +206,7 @@ nsresult nsCollationUnix::CompareString(const nsCollationStrength strength,
}
nsresult nsCollationUnix::AllocateRawSortKey(const nsCollationStrength strength,
nsresult nsCollationUnix::AllocateRawSortKey(PRInt32 strength,
const nsAString& stringIn,
PRUint8** key, PRUint32* outLen)
{
@ -250,3 +250,10 @@ nsresult nsCollationUnix::AllocateRawSortKey(const nsCollationStrength strength,
return res;
}
nsresult nsCollationUnix::CompareRawSortKey(const PRUint8* key1, PRUint32 len1,
const PRUint8* key2, PRUint32 len2,
PRInt32* result)
{
*result = PL_strcmp((const char *)key1, (const char *)key2);
return NS_OK;
}

View File

@ -59,31 +59,14 @@ protected:
public:
nsCollationUnix();
~nsCollationUnix();
virtual ~nsCollationUnix();
// nsISupports interface
NS_DECL_ISUPPORTS
// compare two strings
// result is same as strcmp
NS_IMETHOD CompareString(const nsCollationStrength strength,
const nsAString& string1, const nsAString& string2, PRInt32* result);
// allocate sort key from input string
// returns newly allocated key and its byte length
NS_IMETHOD AllocateRawSortKey(const nsCollationStrength strength,
const nsAString& stringIn, PRUint8** key, PRUint32 *outLen);
// nsICollation interface
NS_DECL_NSICOLLATION
// 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 = PL_strcmp((const char *)key1, (const char *)key2); return NS_OK;}
// init this interface to a specified locale (should only be called by collation factory)
//
NS_IMETHOD Initialize(nsILocale* locale);
};
#endif /* nsCollationUnix_h__ */

View File

@ -133,7 +133,7 @@ nsresult nsCollationWin::Initialize(nsILocale* locale)
}
nsresult nsCollationWin::CompareString(const nsCollationStrength strength,
nsresult nsCollationWin::CompareString(PRInt32 strength,
const nsAString& string1, const nsAString& string2, PRInt32* result)
{
int retval;
@ -174,7 +174,7 @@ nsresult nsCollationWin::CompareString(const nsCollationStrength strength,
}
nsresult nsCollationWin::AllocateRawSortKey(const nsCollationStrength strength,
nsresult nsCollationWin::AllocateRawSortKey(PRInt32 strength,
const nsAString& stringIn, PRUint8** key, PRUint32* outLen)
{
int byteLen;
@ -217,3 +217,11 @@ nsresult nsCollationWin::AllocateRawSortKey(const nsCollationStrength strength,
return res;
}
nsresult nsCollationWin::CompareRawSortKey(const PRUint8* key1, PRUint32 len1,
const PRUint8* key2, PRUint32 len2,
PRInt32* result)
{
*result = PL_strcmp((const char *)key1, (const char *)key2);
return NS_OK;
}

View File

@ -54,32 +54,14 @@ protected:
PRUint32 mLCID; // Windows platform locale ID
public:
NS_DECL_ISUPPORTS
// compare two strings
// result is same as strcmp
NS_IMETHOD CompareString(const nsCollationStrength strength,
const nsAString& string1, const nsAString& string2, PRInt32* result);
// allocate sort key from input string
// returns newly allocated key and its byte length
NS_IMETHOD AllocateRawSortKey(const nsCollationStrength strength,
const nsAString& stringIn, PRUint8** key, PRUint32 *outLen);
// compare two sort keys
// length is a 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 = PL_strcmp((const char *)key1, (const char *)key2); return NS_OK;}
// init this interface to a specified locale (should only be called by collation factory)
//
NS_IMETHOD Initialize(nsILocale* locale);
nsCollationWin();
~nsCollationWin();
virtual ~nsCollationWin();
// nsISupports interface
NS_DECL_ISUPPORTS
// nsICollation interface
NS_DECL_NSICOLLATION
};

View File

@ -106,7 +106,7 @@ static char g_usage[] = " usage:\n-date\tdate time format test\n-col\tcollation
// Create a collation key, the memory is allocated using new which need to be deleted by a caller.
//
static nsresult CreateCollationKey(nsICollation *t, nsCollationStrength strength,
static nsresult CreateCollationKey(nsICollation *t, PRInt32 strength,
nsString& stringIn, PRUint8 **aKey, PRUint32 *keyLength)
{
nsresult res;
@ -232,20 +232,20 @@ static void TestCollation(nsILocale *locale)
DebugDump(string4);
printf("Test 2 - CompareString():\n");
res = t->CompareString(kCollationCaseInSensitive, string1, string2, &result);
res = t->CompareString(nsICollation::kCollationCaseInSensitive, string1, string2, &result);
if(NS_FAILED(res)) {
printf("\tFailed!! return value != NS_OK\n");
}
printf("case insensitive comparison (string1 vs string2): %d\n", result);
res = t->CompareString(kCollationCaseSensitive, string1, string2, &result);
res = t->CompareString(nsICollation::kCollationCaseSensitive, string1, string2, &result);
if(NS_FAILED(res)) {
printf("\tFailed!! return value != NS_OK\n");
}
printf("case sensitive comparison (string1 vs string2): %d\n", result);
printf("Test 3 - GetSortKeyLen():\n");
res = t->GetSortKeyLen(kCollationCaseSensitive, string2, &keyLength1);
res = t->GetSortKeyLen(nsICollation::kCollationCaseSensitive, string2, &keyLength1);
if(NS_FAILED(res)) {
printf("\tFailed!! return value != NS_OK\n");
}
@ -256,7 +256,7 @@ static void TestCollation(nsILocale *locale)
if (NULL == aKey1) {
printf("\tFailed!! memory allocation failed.\n");
}
res = t->CreateRawSortKey(kCollationCaseSensitive, string2, aKey1, &keyLength1);
res = t->CreateRawSortKey(nsICollation::kCollationCaseSensitive, string2, aKey1, &keyLength1);
if(NS_FAILED(res)) {
printf("\tFailed!! return value != NS_OK\n");
}
@ -271,7 +271,7 @@ static void TestCollation(nsILocale *locale)
}
printf("\n");
res = CreateCollationKey(t, kCollationCaseInSensitive, string2, &aKey2, &keyLength2);
res = CreateCollationKey(t, nsICollation::kCollationCaseInSensitive, string2, &aKey2, &keyLength2);
if(NS_FAILED(res)) {
printf("\tFailed!! return value != NS_OK\n");
}
@ -287,7 +287,7 @@ static void TestCollation(nsILocale *locale)
printf("\n");
printf("Test 5 - CompareRawSortKey():\n");
res = CreateCollationKey(t, kCollationCaseSensitive, string1, &aKey3, &keyLength3);
res = CreateCollationKey(t, nsICollation::kCollationCaseSensitive, string1, &aKey3, &keyLength3);
if(NS_FAILED(res)) {
printf("\tFailed!! return value != NS_OK\n");
}
@ -316,15 +316,15 @@ static void TestCollation(nsILocale *locale)
if (NULL != aKey3)
delete[] aKey3;
res = CreateCollationKey(t, kCollationCaseSensitive, string1, &aKey1, &keyLength1);
res = CreateCollationKey(t, nsICollation::kCollationCaseSensitive, string1, &aKey1, &keyLength1);
if(NS_FAILED(res)) {
printf("\tFailed!! return value != NS_OK\n");
}
res = CreateCollationKey(t, kCollationCaseSensitive, string3, &aKey2, &keyLength2);
res = CreateCollationKey(t, nsICollation::kCollationCaseSensitive, string3, &aKey2, &keyLength2);
if(NS_FAILED(res)) {
printf("\tFailed!! return value != NS_OK\n");
}
res = CreateCollationKey(t, kCollationCaseSensitive, string4, &aKey3, &keyLength3);
res = CreateCollationKey(t, nsICollation::kCollationCaseSensitive, string4, &aKey3, &keyLength3);
if(NS_FAILED(res)) {
printf("\tFailed!! return value != NS_OK\n");
}
@ -360,7 +360,7 @@ static void TestCollation(nsILocale *locale)
//
static nsICollation *g_collationInst = NULL;
static nsCollationStrength g_CollationStrength= kCollationCaseInSensitive;
static PRInt32 g_CollationStrength= nsICollation::kCollationCaseInSensitive;
static void TestSortPrint1(nsString *string_array, int len)
@ -555,12 +555,12 @@ static void SortTestFile(nsICollation* collationInst, FILE* fp)
// Use nsICollation for qsort.
//
static void TestSort(nsILocale *locale, nsCollationStrength collationStrength, FILE *fp)
static void TestSort(nsILocale *locale, PRInt32 collationStrength, FILE *fp)
{
nsresult res;
nsICollationFactory *factoryInst;
nsICollation *collationInst;
nsCollationStrength strength;
PRInt32 strength;
collation_rec key_array[5];
PRUint8 *aKey;
PRUint32 aLength;
@ -1028,12 +1028,12 @@ int main(int argc, char** argv) {
if (NS_FAILED(res) || locale == nsnull) printf("GetApplicationLocale failed\n");
// --------------------------------------------
nsCollationStrength strength = kCollationCaseInSensitive;
PRInt32 strength = nsICollation::kCollationCaseInSensitive;
FILE *fp = NULL;
if (argc == 1) {
TestCollation(locale);
TestSort(locale, kCollationCaseInSensitive, NULL);
TestSort(locale, nsICollation::kCollationCaseInSensitive, NULL);
TestDateTimeFormat(locale);
}
else {
@ -1059,7 +1059,7 @@ int main(int argc, char** argv) {
}
s = find_option(argc, argv, "-case");
if (s) {
strength = kCollationCaseSensitive;
strength = nsICollation::kCollationCaseSensitive;
}
s = get_option(argc, argv, "-locale");
if (s) {

View File

@ -784,7 +784,7 @@ nsresult nsAbView::GenerateCollationKeysForCard(const PRUnichar *colID, AbCard *
NS_ENSURE_SUCCESS(rv,rv);
PR_FREEIF(abcard->primaryCollationKey);
rv = mCollationKeyGenerator->AllocateRawSortKey(kCollationCaseInSensitive,
rv = mCollationKeyGenerator->AllocateRawSortKey(nsICollation::kCollationCaseInSensitive,
value, &(abcard->primaryCollationKey), &(abcard->primaryCollationKeyLen));
NS_ENSURE_SUCCESS(rv,rv);
@ -796,7 +796,7 @@ nsresult nsAbView::GenerateCollationKeysForCard(const PRUnichar *colID, AbCard *
NS_ENSURE_SUCCESS(rv,rv);
PR_FREEIF(abcard->secondaryCollationKey);
rv = mCollationKeyGenerator->AllocateRawSortKey(kCollationCaseInSensitive,
rv = mCollationKeyGenerator->AllocateRawSortKey(nsICollation::kCollationCaseInSensitive,
value, &(abcard->secondaryCollationKey), &(abcard->secondaryCollationKeyLen));
NS_ENSURE_SUCCESS(rv,rv);
return rv;

View File

@ -774,7 +774,7 @@ nsresult nsAbDirectoryDataSource::CreateCollationKey(const nsString &aSource, P
NS_ENSURE_SUCCESS(rv, rv);
}
return mCollationKeyGenerator->AllocateRawSortKey(kCollationCaseInSensitive, aSource, aKey, aLength);
return mCollationKeyGenerator->AllocateRawSortKey(nsICollation::kCollationCaseInSensitive, aSource, aKey, aLength);
}
nsresult nsAbDirectoryDataSource::DoDeleteFromDirectory(nsISupportsArray *parentDirs, nsISupportsArray *delDirs)

View File

@ -3202,20 +3202,20 @@ nsresult nsMsgDBView::GetFieldTypeAndLenForSort(nsMsgViewSortTypeValue sortType,
switch (sortType) {
case nsMsgViewSortType::bySubject:
*pFieldType = kCollationKey;
*pFieldType = nsICollation::kCollationKey;
*pMaxLen = kMaxSubjectKey;
break;
case nsMsgViewSortType::byAccount:
case nsMsgViewSortType::byLocation:
*pFieldType = kCollationKey;
*pFieldType = nsICollation::kCollationKey;
*pMaxLen = kMaxLocationKey;
break;
case nsMsgViewSortType::byRecipient:
*pFieldType = kCollationKey;
*pFieldType = nsICollation::kCollationKey;
*pMaxLen = kMaxRecipientKey;
break;
case nsMsgViewSortType::byAuthor:
*pFieldType = kCollationKey;
*pFieldType = nsICollation::kCollationKey;
*pMaxLen = kMaxAuthorKey;
break;
case nsMsgViewSortType::byDate:
@ -3555,7 +3555,7 @@ NS_IMETHODIMP nsMsgDBView::Sort(nsMsgViewSortTypeValue sortType, nsMsgViewSortOr
// could be a problem here if the ones that appear here are different than the ones already in the array
PRUint32 actualFieldLen = 0;
if (fieldType == kCollationKey)
if (fieldType == nsICollation::kCollationKey)
{
rv = GetCollationKey(msgHdr, sortType, &keyValue, &actualFieldLen);
NS_ENSURE_SUCCESS(rv,rv);
@ -3625,7 +3625,7 @@ NS_IMETHODIMP nsMsgDBView::Sort(nsMsgViewSortTypeValue sortType, nsMsgViewSortOr
// do the sort
switch (fieldType)
{
case kCollationKey:
case nsICollation::kCollationKey:
{
nsCOMPtr <nsIMsgDatabase> dbToUse = m_db;
@ -4208,7 +4208,7 @@ nsMsgViewIndex nsMsgDBView::GetInsertIndex(nsIMsgDBHdr *msgHdr)
msgHdr->GetMessageKey(&EntryInfo1.id);
switch (fieldType)
{
case kCollationKey:
case nsICollation::kCollationKey:
rv = GetCollationKey(msgHdr, m_sortType, &EntryInfo1.key, &EntryInfo1.dword);
NS_ASSERTION(NS_SUCCEEDED(rv),"failed to create collation key");
comparisonFun = FnSortIdKeyPtr;
@ -4234,7 +4234,7 @@ nsMsgViewIndex nsMsgDBView::GetInsertIndex(nsIMsgDBHdr *msgHdr)
rv = m_db->GetMsgHdrForKey(EntryInfo2.id, getter_AddRefs(tryHdr));
if (!tryHdr)
break;
if (fieldType == kCollationKey)
if (fieldType == nsICollation::kCollationKey)
{
PR_FREEIF(EntryInfo2.key);
rv = GetCollationKey(tryHdr, m_sortType, &EntryInfo2.key, &EntryInfo2.dword);

View File

@ -68,7 +68,7 @@
#define MESSENGER_STRING_URL "chrome://messenger/locale/messenger.properties"
enum eFieldType {
kCollationKey,
nsICollation::kCollationKey,
kU32
};

View File

@ -4636,7 +4636,7 @@ nsMsgDBFolder::CreateCollationKey(const nsString &aSource, PRUint8 **aKey, PRUi
if (!gCollationKeyGenerator)
return NS_ERROR_NULL_POINTER;
return gCollationKeyGenerator->AllocateRawSortKey(kCollationCaseInSensitive, aSource, aKey, aLength);
return gCollationKeyGenerator->AllocateRawSortKey(nsICollation::kCollationCaseInSensitive, aSource, aKey, aLength);
}
NS_IMETHODIMP nsMsgDBFolder::CompareSortKeys(nsIMsgFolder *aFolder, PRInt32 *sortOrder)

View File

@ -3201,7 +3201,7 @@ nsMsgDatabase::CreateCollationKey(const nsAString& sourceString, PRUint8 **resul
NS_ENSURE_SUCCESS(err,err);
if (!m_collationKeyGenerator) return NS_ERROR_FAILURE;
err = m_collationKeyGenerator->AllocateRawSortKey(kCollationCaseInSensitive, sourceString, result, len);
err = m_collationKeyGenerator->AllocateRawSortKey(nsICollation::kCollationCaseInSensitive, sourceString, result, len);
NS_ENSURE_SUCCESS(err,err);
return err;
}

View File

@ -127,7 +127,7 @@ static int PR_CALLBACK compare(const void* aElement1,
nsString str2(name2);
nsICollation* coll = (nsICollation*)aData;
coll->CompareString(kCollationStrengthDefault, str1, str2, &res);
coll->CompareString(nsICollation::kCollationStrengthDefault, str1, str2, &res);
return res;*/
#else
nsCAutoString name1, name2;

View File

@ -2726,7 +2726,7 @@ nsBookmarksService::Compare(const void* aElement1, const void* aElement2, void*
literal2->GetValueConst(&value2);
if (gCollation) {
gCollation->CompareString(kCollationCaseInSensitive,
gCollation->CompareString(nsICollation::kCollationCaseInSensitive,
nsDependentString(value1),
nsDependentString(value2),
&result);