diff --git a/content/xul/templates/src/nsXULSortService.cpp b/content/xul/templates/src/nsXULSortService.cpp index b7607ee40179..58cc9f2c6e45 100644 --- a/content/xul/templates/src/nsXULSortService.cpp +++ b/content/xul/templates/src/nsXULSortService.cpp @@ -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; diff --git a/content/xul/templates/src/nsXULTreeBuilder.cpp b/content/xul/templates/src/nsXULTreeBuilder.cpp index 8fb10234f8e7..9d898eb5940a 100644 --- a/content/xul/templates/src/nsXULTreeBuilder.cpp +++ b/content/xul/templates/src/nsXULTreeBuilder.cpp @@ -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); diff --git a/dom/src/base/nsJSEnvironment.cpp b/dom/src/base/nsJSEnvironment.cpp index 921b4008f0f9..e436e99115b4 100644 --- a/dom/src/base/nsJSEnvironment.cpp +++ b/dom/src/base/nsJSEnvironment.cpp @@ -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); diff --git a/extensions/transformiix/source/xslt/util/txXPathResultComparator.cpp b/extensions/transformiix/source/xslt/util/txXPathResultComparator.cpp index ba1904d5c965..b4fcc3f61463 100644 --- a/extensions/transformiix/source/xslt/util/txXPathResultComparator.cpp +++ b/extensions/transformiix/source/xslt/util/txXPathResultComparator.cpp @@ -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); diff --git a/extensions/transformiix/source/xslt/util/txXPathResultComparator.h b/extensions/transformiix/source/xslt/util/txXPathResultComparator.h index bff621b99029..80a8f36b10df 100644 --- a/extensions/transformiix/source/xslt/util/txXPathResultComparator.h +++ b/extensions/transformiix/source/xslt/util/txXPathResultComparator.h @@ -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 mCollation; nsresult init(const nsAFlatString& aLanguage); - nsresult createRawSortKey(const nsCollationStrength aStrength, + nsresult createRawSortKey(const PRInt32 aStrength, const nsString& aString, PRUint8** aKey, PRUint32* aLength); diff --git a/intl/build/nsI18nModule.cpp b/intl/build/nsI18nModule.cpp index 5a432ec3ce5e..28783592180e 100644 --- a/intl/build/nsI18nModule.cpp +++ b/intl/build/nsI18nModule.cpp @@ -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, diff --git a/intl/locale/idl/Makefile.in b/intl/locale/idl/Makefile.in index 53dadfa39fd0..af7a46206554 100644 --- a/intl/locale/idl/Makefile.in +++ b/intl/locale/idl/Makefile.in @@ -52,6 +52,7 @@ XPIDLSRCS = \ nsILocale.idl \ nsILocaleService.idl \ nsIScriptableDateFormat.idl \ + nsICollation.idl \ $(NULL) include $(topsrcdir)/config/rules.mk diff --git a/intl/locale/idl/nsICollation.idl b/intl/locale/idl/nsICollation.idl new file mode 100644 index 000000000000..3b5155425042 --- /dev/null +++ b/intl/locale/idl/nsICollation.idl @@ -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); + +}; diff --git a/intl/locale/public/Makefile.in b/intl/locale/public/Makefile.in index 6d9a9931dd75..c126223e16a2 100644 --- a/intl/locale/public/Makefile.in +++ b/intl/locale/public/Makefile.in @@ -47,7 +47,6 @@ MODULE = locale EXPORTS = \ nsCollationCID.h \ nsDateTimeFormatCID.h \ - nsICollation.h \ nsIDateTimeFormat.h \ nsILanguageAtomService.h \ nsIMacLocale.h \ diff --git a/intl/locale/public/nsCollationCID.h b/intl/locale/public/nsCollationCID.h index df40ad9b2995..b83406b1d85b 100644 --- a/intl/locale/public/nsCollationCID.h +++ b/intl/locale/public/nsCollationCID.h @@ -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__ diff --git a/intl/locale/public/nsICollation.h b/intl/locale/public/nsICollation.h deleted file mode 100644 index 2c10075cd9af..000000000000 --- a/intl/locale/public/nsICollation.h +++ /dev/null @@ -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__ */ diff --git a/intl/locale/src/mac/nsCollationMac.cpp b/intl/locale/src/mac/nsCollationMac.cpp index 629975b7d508..211b1df23e33 100644 --- a/intl/locale/src/mac/nsCollationMac.cpp +++ b/intl/locale/src/mac/nsCollationMac.cpp @@ -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; +} diff --git a/intl/locale/src/mac/nsCollationMac.h b/intl/locale/src/mac/nsCollationMac.h index f295d70958f4..805316a46479 100644 --- a/intl/locale/src/mac/nsCollationMac.h +++ b/intl/locale/src/mac/nsCollationMac.h @@ -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 }; diff --git a/intl/locale/src/mac/nsCollationMacUC.cpp b/intl/locale/src/mac/nsCollationMacUC.cpp index bb7bd31dacb0..c67c1739e4a2 100644 --- a/intl/locale/src/mac/nsCollationMacUC.cpp +++ b/intl/locale/src/mac/nsCollationMacUC.cpp @@ -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); diff --git a/intl/locale/src/mac/nsCollationMacUC.h b/intl/locale/src/mac/nsCollationMacUC.h index 05b1a76ea39d..3ae5c8cb9a04 100644 --- a/intl/locale/src/mac/nsCollationMacUC.h +++ b/intl/locale/src/mac/nsCollationMacUC.h @@ -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 diff --git a/intl/locale/src/os2/nsCollationOS2.cpp b/intl/locale/src/os2/nsCollationOS2.cpp index 9ed2aac3a6a0..0335dfaa24ed 100644 --- a/intl/locale/src/os2/nsCollationOS2.cpp +++ b/intl/locale/src/os2/nsCollationOS2.cpp @@ -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; +} diff --git a/intl/locale/src/os2/nsCollationOS2.h b/intl/locale/src/os2/nsCollationOS2.h index a00ca2215228..857a2fa1d5a4 100644 --- a/intl/locale/src/os2/nsCollationOS2.h +++ b/intl/locale/src/os2/nsCollationOS2.h @@ -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__ */ diff --git a/intl/locale/src/unix/nsCollationUnix.cpp b/intl/locale/src/unix/nsCollationUnix.cpp index 8608a315174f..4bf1f9eab2b4 100644 --- a/intl/locale/src/unix/nsCollationUnix.cpp +++ b/intl/locale/src/unix/nsCollationUnix.cpp @@ -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; +} diff --git a/intl/locale/src/unix/nsCollationUnix.h b/intl/locale/src/unix/nsCollationUnix.h index adf06cd4995a..da55dc7736b5 100644 --- a/intl/locale/src/unix/nsCollationUnix.h +++ b/intl/locale/src/unix/nsCollationUnix.h @@ -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__ */ diff --git a/intl/locale/src/windows/nsCollationWin.cpp b/intl/locale/src/windows/nsCollationWin.cpp index 038c6ca7cbfb..40392d2c3181 100644 --- a/intl/locale/src/windows/nsCollationWin.cpp +++ b/intl/locale/src/windows/nsCollationWin.cpp @@ -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; +} diff --git a/intl/locale/src/windows/nsCollationWin.h b/intl/locale/src/windows/nsCollationWin.h index 2e574804f0e7..865232abec80 100644 --- a/intl/locale/src/windows/nsCollationWin.h +++ b/intl/locale/src/windows/nsCollationWin.h @@ -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 }; diff --git a/intl/locale/tests/LocaleSelfTest.cpp b/intl/locale/tests/LocaleSelfTest.cpp index b6cbbf4647c8..428fadfb5d86 100644 --- a/intl/locale/tests/LocaleSelfTest.cpp +++ b/intl/locale/tests/LocaleSelfTest.cpp @@ -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) { diff --git a/mailnews/addrbook/src/nsAbView.cpp b/mailnews/addrbook/src/nsAbView.cpp index 25bf20d9132a..c198c56894ce 100644 --- a/mailnews/addrbook/src/nsAbView.cpp +++ b/mailnews/addrbook/src/nsAbView.cpp @@ -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; diff --git a/mailnews/addrbook/src/nsDirectoryDataSource.cpp b/mailnews/addrbook/src/nsDirectoryDataSource.cpp index 48c562c03e5e..de612a893e0d 100644 --- a/mailnews/addrbook/src/nsDirectoryDataSource.cpp +++ b/mailnews/addrbook/src/nsDirectoryDataSource.cpp @@ -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) diff --git a/mailnews/base/src/nsMsgDBView.cpp b/mailnews/base/src/nsMsgDBView.cpp index b4ee4911da6e..749343c63acf 100644 --- a/mailnews/base/src/nsMsgDBView.cpp +++ b/mailnews/base/src/nsMsgDBView.cpp @@ -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 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); diff --git a/mailnews/base/src/nsMsgDBView.h b/mailnews/base/src/nsMsgDBView.h index 73b6bef2ca15..93f511f233a5 100644 --- a/mailnews/base/src/nsMsgDBView.h +++ b/mailnews/base/src/nsMsgDBView.h @@ -68,7 +68,7 @@ #define MESSENGER_STRING_URL "chrome://messenger/locale/messenger.properties" enum eFieldType { - kCollationKey, + nsICollation::kCollationKey, kU32 }; diff --git a/mailnews/base/util/nsMsgDBFolder.cpp b/mailnews/base/util/nsMsgDBFolder.cpp index 19de522b76f6..2ddfafd914a7 100644 --- a/mailnews/base/util/nsMsgDBFolder.cpp +++ b/mailnews/base/util/nsMsgDBFolder.cpp @@ -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) diff --git a/mailnews/db/msgdb/src/nsMsgDatabase.cpp b/mailnews/db/msgdb/src/nsMsgDatabase.cpp index ed6911a22311..901ba1ced715 100644 --- a/mailnews/db/msgdb/src/nsMsgDatabase.cpp +++ b/mailnews/db/msgdb/src/nsMsgDatabase.cpp @@ -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; } diff --git a/netwerk/base/src/nsDirectoryIndexStream.cpp b/netwerk/base/src/nsDirectoryIndexStream.cpp index 004938a2874d..fb7236358dfd 100644 --- a/netwerk/base/src/nsDirectoryIndexStream.cpp +++ b/netwerk/base/src/nsDirectoryIndexStream.cpp @@ -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; diff --git a/xpfe/components/bookmarks/src/nsBookmarksService.cpp b/xpfe/components/bookmarks/src/nsBookmarksService.cpp index 92e214a7be13..9589a2a9aff3 100644 --- a/xpfe/components/bookmarks/src/nsBookmarksService.cpp +++ b/xpfe/components/bookmarks/src/nsBookmarksService.cpp @@ -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);