diff --git a/intl/build/nsI18nModule.cpp b/intl/build/nsI18nModule.cpp index 8cd517478e344c92f8555d32d786f345a0e92c86..9be18774107f12be43f93b7ca6ae1db2bfcdc129 100644 --- a/intl/build/nsI18nModule.cpp +++ b/intl/build/nsI18nModule.cpp @@ -61,15 +61,7 @@ NS_DEFINE_NAMED_CID(NS_COLLATIONFACTORY_CID); NS_DEFINE_NAMED_CID(NS_SCRIPTABLEDATEFORMAT_CID); NS_DEFINE_NAMED_CID(NS_LANGUAGEATOMSERVICE_CID); NS_DEFINE_NAMED_CID(NS_PLATFORMCHARSET_CID); -#ifdef XP_WIN NS_DEFINE_NAMED_CID(NS_COLLATION_CID); -#endif -#ifdef USE_UNIX_LOCALE -NS_DEFINE_NAMED_CID(NS_COLLATION_CID); -#endif -#ifdef USE_MAC_LOCALE -NS_DEFINE_NAMED_CID(NS_COLLATION_CID); -#endif static const mozilla::Module::CIDEntry kIntlCIDs[] = { { &kMOZ_LOCALESERVICE_CID, false, nullptr, mozilla::intl::LocaleServiceConstructor }, @@ -89,15 +81,7 @@ static const mozilla::Module::CIDEntry kIntlCIDs[] = { { &kNS_SCRIPTABLEDATEFORMAT_CID, false, nullptr, NS_NewScriptableDateFormat }, { &kNS_LANGUAGEATOMSERVICE_CID, false, nullptr, nsLanguageAtomServiceConstructor }, { &kNS_PLATFORMCHARSET_CID, false, nullptr, nsPlatformCharsetConstructor }, -#ifdef XP_WIN - { &kNS_COLLATION_CID, false, nullptr, nsCollationWinConstructor }, -#endif -#ifdef USE_UNIX_LOCALE - { &kNS_COLLATION_CID, false, nullptr, nsCollationUnixConstructor }, -#endif -#ifdef USE_MAC_LOCALE - { &kNS_COLLATION_CID, false, nullptr, nsCollationMacUCConstructor }, -#endif + { &kNS_COLLATION_CID, false, nullptr, nsCollationConstructor }, { nullptr } }; @@ -119,15 +103,7 @@ static const mozilla::Module::ContractIDEntry kIntlContracts[] = { { NS_SCRIPTABLEDATEFORMAT_CONTRACTID, &kNS_SCRIPTABLEDATEFORMAT_CID }, { NS_LANGUAGEATOMSERVICE_CONTRACTID, &kNS_LANGUAGEATOMSERVICE_CID }, { NS_PLATFORMCHARSET_CONTRACTID, &kNS_PLATFORMCHARSET_CID }, -#ifdef XP_WIN - { NS_COLLATION_CONTRACTID, &kNS_COLLATION_CID }, -#endif -#ifdef USE_UNIX_LOCALE - { NS_COLLATION_CONTRACTID, &kNS_COLLATION_CID }, -#endif -#ifdef USE_MAC_LOCALE { NS_COLLATION_CONTRACTID, &kNS_COLLATION_CID }, -#endif { nullptr } }; diff --git a/intl/locale/mac/moz.build b/intl/locale/mac/moz.build index a7bad24d193ca9a911039793fa29f6794b444100..8f76d2d2a4227e6f5953dfd6df4da18afe772d05 100644 --- a/intl/locale/mac/moz.build +++ b/intl/locale/mac/moz.build @@ -5,7 +5,6 @@ # file, You can obtain one at http://mozilla.org/MPL/2.0/. UNIFIED_SOURCES += [ - 'nsCollationMacUC.cpp', 'nsMacCharset.cpp', ] diff --git a/intl/locale/moz.build b/intl/locale/moz.build index 85bae150935fac8881a9387c8140d5f9432b0228..b1806f816089ad963ae7166a6ccad1b0fccc7776 100644 --- a/intl/locale/moz.build +++ b/intl/locale/moz.build @@ -33,7 +33,6 @@ XPIDL_MODULE = 'locale' EXPORTS += [ 'DateTimeFormat.h', 'nsCollationCID.h', - 'nsCollationFactory.h', 'nsILanguageAtomService.h', 'nsIPlatformCharset.h', 'nsPosixLocale.h', @@ -48,6 +47,7 @@ EXPORTS.mozilla.intl += [ UNIFIED_SOURCES += [ 'LocaleService.cpp', + 'nsCollation.cpp', 'nsCollationFactory.cpp', 'nsLanguageAtomService.cpp', 'nsLocale.cpp', diff --git a/intl/locale/mac/nsCollationMacUC.cpp b/intl/locale/nsCollation.cpp similarity index 79% rename from intl/locale/mac/nsCollationMacUC.cpp rename to intl/locale/nsCollation.cpp index b32154453a693d2e197d9bdce5dd6774f5c7f032..b4d6837a2949ca1ac9c7ad146c860f4ffcf7a6df 100644 --- a/intl/locale/mac/nsCollationMacUC.cpp +++ b/intl/locale/nsCollation.cpp @@ -3,23 +3,21 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "nsCollationMacUC.h" -#include "nsIPrefBranch.h" -#include "nsIPrefService.h" +#include "nsCollation.h" #include "nsIServiceManager.h" #include "prmem.h" #include "nsString.h" -NS_IMPL_ISUPPORTS(nsCollationMacUC, nsICollation) +NS_IMPL_ISUPPORTS(nsCollation, nsICollation) -nsCollationMacUC::nsCollationMacUC() +nsCollation::nsCollation() : mInit(false) , mHasCollator(false) , mLastStrength(-1) , mCollatorICU(nullptr) { } -nsCollationMacUC::~nsCollationMacUC() +nsCollation::~nsCollation() { #ifdef DEBUG nsresult res = @@ -28,9 +26,10 @@ nsCollationMacUC::~nsCollationMacUC() NS_ASSERTION(NS_SUCCEEDED(res), "CleanUpCollator failed"); } -nsresult nsCollationMacUC::ConvertStrength(const int32_t aNSStrength, - UCollationStrength* aICUStrength, - UColAttributeValue* aCaseLevelOut) +nsresult +nsCollation::ConvertStrength(const int32_t aNSStrength, + UCollationStrength* aICUStrength, + UColAttributeValue* aCaseLevelOut) { NS_ENSURE_ARG_POINTER(aICUStrength); NS_ENSURE_TRUE((aNSStrength < 4), NS_ERROR_FAILURE); @@ -62,7 +61,8 @@ nsresult nsCollationMacUC::ConvertStrength(const int32_t aNSStrength, return NS_OK; } -nsresult nsCollationMacUC::EnsureCollator(const int32_t newStrength) +nsresult +nsCollation::EnsureCollator(const int32_t newStrength) { NS_ENSURE_TRUE(mInit, NS_ERROR_NOT_INITIALIZED); if (mHasCollator && (mLastStrength == newStrength)) @@ -102,7 +102,8 @@ nsresult nsCollationMacUC::EnsureCollator(const int32_t newStrength) return NS_OK; } -nsresult nsCollationMacUC::CleanUpCollator(void) +nsresult +nsCollation::CleanUpCollator(void) { if (mHasCollator) { ucol_close(mCollatorICU); @@ -112,10 +113,10 @@ nsresult nsCollationMacUC::CleanUpCollator(void) return NS_OK; } -NS_IMETHODIMP nsCollationMacUC::Initialize(const nsACString& locale) +NS_IMETHODIMP +nsCollation::Initialize(const nsACString& locale) { NS_ENSURE_TRUE((!mInit), NS_ERROR_ALREADY_INITIALIZED); - nsCOMPtr<nsILocale> appLocale; mLocale = locale; @@ -123,8 +124,9 @@ NS_IMETHODIMP nsCollationMacUC::Initialize(const nsACString& locale) return NS_OK; } -NS_IMETHODIMP nsCollationMacUC::AllocateRawSortKey(int32_t strength, const nsAString& stringIn, - uint8_t** key, uint32_t* outLen) +NS_IMETHODIMP +nsCollation::AllocateRawSortKey(int32_t strength, const nsAString& stringIn, + uint8_t** key, uint32_t* outLen) { NS_ENSURE_TRUE(mInit, NS_ERROR_NOT_INITIALIZED); NS_ENSURE_ARG_POINTER(key); @@ -155,8 +157,9 @@ NS_IMETHODIMP nsCollationMacUC::AllocateRawSortKey(int32_t strength, const nsASt return NS_OK; } -NS_IMETHODIMP nsCollationMacUC::CompareString(int32_t strength, const nsAString& string1, - const nsAString& string2, int32_t* result) +NS_IMETHODIMP +nsCollation::CompareString(int32_t strength, const nsAString& string1, + const nsAString& string2, int32_t* result) { NS_ENSURE_TRUE(mInit, NS_ERROR_NOT_INITIALIZED); NS_ENSURE_ARG_POINTER(result); @@ -189,9 +192,10 @@ NS_IMETHODIMP nsCollationMacUC::CompareString(int32_t strength, const nsAString& return NS_OK; } -NS_IMETHODIMP nsCollationMacUC::CompareRawSortKey(const uint8_t* key1, uint32_t len1, - const uint8_t* key2, uint32_t len2, - int32_t* result) +NS_IMETHODIMP +nsCollation::CompareRawSortKey(const uint8_t* key1, uint32_t len1, + const uint8_t* key2, uint32_t len2, + int32_t* result) { NS_ENSURE_TRUE(mInit, NS_ERROR_NOT_INITIALIZED); NS_ENSURE_ARG_POINTER(key1); diff --git a/intl/locale/mac/nsCollationMacUC.h b/intl/locale/nsCollation.h similarity index 83% rename from intl/locale/mac/nsCollationMacUC.h rename to intl/locale/nsCollation.h index ec6f06e564e6393249480156ceeea561941e3351..9ef29194ec15d74607a84d546b6f0513af4c78de 100644 --- a/intl/locale/mac/nsCollationMacUC.h +++ b/intl/locale/nsCollation.h @@ -3,8 +3,8 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#ifndef nsCollationMacUC_h_ -#define nsCollationMacUC_h_ +#ifndef nsCollation_h_ +#define nsCollation_h_ #include "mozilla/Attributes.h" #include "nsICollation.h" @@ -13,10 +13,10 @@ #include "unicode/ucol.h" -class nsCollationMacUC final : public nsICollation { +class nsCollation final : public nsICollation { public: - nsCollationMacUC(); + nsCollation(); // nsISupports interface NS_DECL_ISUPPORTS @@ -25,7 +25,7 @@ public: NS_DECL_NSICOLLATION protected: - ~nsCollationMacUC(); + ~nsCollation(); nsresult ConvertStrength(const int32_t aStrength, UCollationStrength* aStrengthOut, @@ -41,4 +41,4 @@ private: UCollator* mCollatorICU; }; -#endif /* nsCollationMacUC_h_ */ +#endif /* nsCollation_h_ */ diff --git a/intl/locale/nsCollationFactory.cpp b/intl/locale/nsCollationFactory.cpp index 0e46011b91da9cbff0b3d52fb1f6f273ebde97aa..ba800da3ab0a02fd777aca1ede5659c34ae7444b 100644 --- a/intl/locale/nsCollationFactory.cpp +++ b/intl/locale/nsCollationFactory.cpp @@ -5,15 +5,9 @@ #include "nsCollationFactory.h" #include "nsCollationCID.h" -#include "nsUnicharUtils.h" -#include "prmem.h" -#include "nsIUnicodeEncoder.h" #include "nsServiceManagerUtils.h" -#include "mozilla/dom/EncodingUtils.h" #include "mozilla/intl/LocaleService.h" -using mozilla::dom::EncodingUtils; - //////////////////////////////////////////////////////////////////////////////// NS_DEFINE_CID(kCollationCID, NS_COLLATION_CID); @@ -47,99 +41,3 @@ nsCollationFactory::CreateCollationForLocale(const nsACString& locale, nsICollat return res; } - -//////////////////////////////////////////////////////////////////////////////// - -nsCollation::nsCollation() -{ - MOZ_COUNT_CTOR(nsCollation); -} - -nsCollation::~nsCollation() -{ - MOZ_COUNT_DTOR(nsCollation); -} - -nsresult nsCollation::NormalizeString(const nsAString& stringIn, nsAString& stringOut) -{ - int32_t aLength = stringIn.Length(); - - if (aLength <= 64) { - char16_t conversionBuffer[64]; - ToLowerCase(PromiseFlatString(stringIn).get(), conversionBuffer, aLength); - stringOut.Assign(conversionBuffer, aLength); - } - else { - char16_t* conversionBuffer; - conversionBuffer = new char16_t[aLength]; - if (!conversionBuffer) { - return NS_ERROR_OUT_OF_MEMORY; - } - ToLowerCase(PromiseFlatString(stringIn).get(), conversionBuffer, aLength); - stringOut.Assign(conversionBuffer, aLength); - delete [] conversionBuffer; - } - return NS_OK; -} - -nsresult nsCollation::SetCharset(const char* aCharset) -{ - NS_ENSURE_ARG_POINTER(aCharset); - - nsDependentCString label(aCharset); - nsAutoCString encoding; - if (!EncodingUtils::FindEncodingForLabelNoReplacement(label, encoding)) { - return NS_ERROR_UCONV_NOCONV; - } - mEncoder = EncodingUtils::EncoderForEncoding(encoding); - return NS_OK; -} - -nsresult nsCollation::UnicodeToChar(const nsAString& aSrc, char** dst) -{ - NS_ENSURE_ARG_POINTER(dst); - - nsresult res = NS_OK; - if (!mEncoder) - res = SetCharset("ISO-8859-1"); - - if (NS_SUCCEEDED(res)) { - const nsPromiseFlatString& src = PromiseFlatString(aSrc); - const char16_t *unichars = src.get(); - int32_t unicharLength = src.Length(); - int32_t dstLength; - res = mEncoder->GetMaxLength(unichars, unicharLength, &dstLength); - if (NS_SUCCEEDED(res)) { - int32_t bufLength = dstLength + 1 + 32; // extra 32 bytes for Finish() call - *dst = (char *) PR_Malloc(bufLength); - if (*dst) { - **dst = '\0'; - res = mEncoder->Convert(unichars, &unicharLength, *dst, &dstLength); - - if (NS_SUCCEEDED(res) || (NS_ERROR_UENC_NOMAPPING == res)) { - // Finishes the conversion. The converter has the possibility to write some - // extra data and flush its final state. - int32_t finishLength = bufLength - dstLength; // remaining unused buffer length - if (finishLength > 0) { - res = mEncoder->Finish((*dst + dstLength), &finishLength); - if (NS_SUCCEEDED(res)) { - (*dst)[dstLength + finishLength] = '\0'; - } - } - } - if (NS_FAILED(res)) { - PR_Free(*dst); - *dst = nullptr; - } - } - else { - res = NS_ERROR_OUT_OF_MEMORY; - } - } - } - - return res; -} - - - diff --git a/intl/locale/nsCollationFactory.h b/intl/locale/nsCollationFactory.h index 7f3e1769742bf7a1160f95e2ac6f6c0784ffbf22..3d99c1a71ab08df9253efff68e31c4692bc9a1bb 100644 --- a/intl/locale/nsCollationFactory.h +++ b/intl/locale/nsCollationFactory.h @@ -12,8 +12,6 @@ #include "nsCOMPtr.h" #include "mozilla/Attributes.h" -class nsIUnicodeEncoder; - // Create a collation interface for the current app's locale. // class nsCollationFactory final : public nsICollationFactory { @@ -27,24 +25,4 @@ public: nsCollationFactory() {} }; - -struct nsCollation { - -public: - - nsCollation(); - - ~nsCollation(); - - // normalize string before collation key generation - nsresult NormalizeString(const nsAString& stringIn, nsAString& stringOut); - - // charset conversion util, C string buffer is allocate by PR_Malloc, caller should call PR_Free - nsresult SetCharset(const char* aCharset); - nsresult UnicodeToChar(const nsAString& aSrc, char** dst); - -protected: - nsCOMPtr <nsIUnicodeEncoder> mEncoder; -}; - #endif /* nsCollationFactory_h__ */ diff --git a/intl/locale/nsLocaleConstructors.h b/intl/locale/nsLocaleConstructors.h index 39dff6c7816710767788776d7ddf593f21d95972..5161e19a41f5efd132f0417a50b16ddf3f446b15 100644 --- a/intl/locale/nsLocaleConstructors.h +++ b/intl/locale/nsLocaleConstructors.h @@ -6,6 +6,7 @@ #ifndef nsLocaleConstructors_h__ #define nsLocaleConstructors_h__ +#include "nsCollation.h" #include "nsCollationCID.h" #include "mozilla/ModuleUtils.h" #include "nsILocaleService.h" @@ -16,26 +17,6 @@ #include "LocaleService.h" #include "OSPreferences.h" -#if defined(XP_MACOSX) -#define USE_MAC_LOCALE -#endif - -#if defined(XP_UNIX) && !defined(XP_MACOSX) -#define USE_UNIX_LOCALE -#endif - -#ifdef XP_WIN -#include "windows/nsCollationWin.h" -#endif - -#ifdef USE_MAC_LOCALE -#include "mac/nsCollationMacUC.h" -#endif - -#ifdef USE_UNIX_LOCALE -#include "unix/nsCollationUnix.h" -#endif - #define NSLOCALE_MAKE_CTOR(ctor_, iface_, func_) \ static nsresult \ ctor_(nsISupports* aOuter, REFNSIID aIID, void** aResult) \ @@ -54,6 +35,7 @@ ctor_(nsISupports* aOuter, REFNSIID aIID, void** aResult) \ NSLOCALE_MAKE_CTOR(CreateLocaleService, nsILocaleService, NS_NewLocaleService) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsCollation) NS_GENERIC_FACTORY_CONSTRUCTOR(nsCollationFactory) //NS_GENERIC_FACTORY_CONSTRUCTOR(nsScriptableDateTimeFormat) NS_GENERIC_FACTORY_CONSTRUCTOR(nsLanguageAtomService) @@ -68,16 +50,4 @@ NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(OSPreferences, } } -#ifdef XP_WIN -NS_GENERIC_FACTORY_CONSTRUCTOR(nsCollationWin) -#endif - -#ifdef USE_UNIX_LOCALE -NS_GENERIC_FACTORY_CONSTRUCTOR(nsCollationUnix) -#endif - -#ifdef USE_MAC_LOCALE -NS_GENERIC_FACTORY_CONSTRUCTOR(nsCollationMacUC) -#endif - #endif diff --git a/intl/locale/tests/unit/test_collation_mac_icu.js b/intl/locale/tests/unit/test_collation.js similarity index 100% rename from intl/locale/tests/unit/test_collation_mac_icu.js rename to intl/locale/tests/unit/test_collation.js diff --git a/intl/locale/tests/unit/xpcshell.ini b/intl/locale/tests/unit/xpcshell.ini index 5e72c860e3822ebb507a4a7a9c529f68561b1e9c..74173782e34e7d831f8b6a7ee49bbb0664277a3c 100644 --- a/intl/locale/tests/unit/xpcshell.ini +++ b/intl/locale/tests/unit/xpcshell.ini @@ -11,9 +11,7 @@ skip-if = toolkit != "windows" && toolkit != "cocoa" [test_bug374040.js] skip-if = toolkit == "windows" || toolkit == "cocoa" -[test_collation_mac_icu.js] -skip-if = toolkit != "cocoa" - +[test_collation.js] [test_bug1086527.js] [test_intl_on_workers.js] skip-if = toolkit == "android" # bug 1309447 diff --git a/intl/locale/unix/moz.build b/intl/locale/unix/moz.build index 633047ed1887f5e06bff46fd00da7cb1e2214d97..fcf87eb661de76ef1de8f5e1c105f47014c946b2 100644 --- a/intl/locale/unix/moz.build +++ b/intl/locale/unix/moz.build @@ -5,7 +5,6 @@ # file, You can obtain one at http://mozilla.org/MPL/2.0/. SOURCES += [ - 'nsCollationUnix.cpp', 'nsPosixLocale.cpp', ] diff --git a/intl/locale/unix/nsCollationUnix.h b/intl/locale/unix/nsCollationUnix.h deleted file mode 100644 index 92be2934f16c49fa718205a5ea4267159457a3e2..0000000000000000000000000000000000000000 --- a/intl/locale/unix/nsCollationUnix.h +++ /dev/null @@ -1,43 +0,0 @@ - -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#ifndef nsCollationUnix_h__ -#define nsCollationUnix_h__ - - -#include "nsICollation.h" -#include "nsCollationFactory.h" // static library -#include "plstr.h" -#include "mozilla/Attributes.h" -#include "nsString.h" - - - -class nsCollationUnix final : public nsICollation { - -protected: - nsCollation *mCollation; - nsCString mLocale; - nsCString mSavedLocale; - bool mUseCodePointOrder; - - void DoSetLocale(); - void DoRestoreLocale(); - - ~nsCollationUnix(); - -public: - nsCollationUnix(); - - // nsISupports interface - NS_DECL_ISUPPORTS - - // nsICollation interface - NS_DECL_NSICOLLATION - -}; - -#endif /* nsCollationUnix_h__ */ diff --git a/intl/locale/windows/moz.build b/intl/locale/windows/moz.build index 555b6cc2619eb474204d73df2c133992ddb04d0d..c2f28c21149e55c34b6c972eefcf9e696e232dd8 100644 --- a/intl/locale/windows/moz.build +++ b/intl/locale/windows/moz.build @@ -5,7 +5,6 @@ # file, You can obtain one at http://mozilla.org/MPL/2.0/. SOURCES += [ - 'nsCollationWin.cpp', 'nsWin32Locale.cpp', 'nsWinCharset.cpp', ] diff --git a/intl/locale/windows/nsCollationWin.cpp b/intl/locale/windows/nsCollationWin.cpp deleted file mode 100644 index 76bc8a2d48c88641213741f13f615ef7c8582eff..0000000000000000000000000000000000000000 --- a/intl/locale/windows/nsCollationWin.cpp +++ /dev/null @@ -1,127 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - - -#include "nsCollationWin.h" -#include "nsIServiceManager.h" -#include "nsIComponentManager.h" -#include "nsIPlatformCharset.h" -#include "nsWin32Locale.h" -#include "nsCOMPtr.h" -#include "prmem.h" -#include "plstr.h" -#include <windows.h> - -#undef CompareString - -NS_IMPL_ISUPPORTS(nsCollationWin, nsICollation) - - -nsCollationWin::nsCollationWin() : mCollation(nullptr) -{ -} - -nsCollationWin::~nsCollationWin() -{ - if (mCollation) - delete mCollation; -} - -nsresult nsCollationWin::Initialize(const nsACString& locale) -{ - NS_ASSERTION(!mCollation, "Should only be initialized once."); - - nsresult res; - - mCollation = new nsCollation; - - NS_ConvertASCIItoUTF16 wideLocale(locale); - - // default LCID (en-US) - mLCID = 1033; - - // Get LCID and charset name from locale, if available - LCID lcid; - res = nsWin32Locale::GetPlatformLocale(wideLocale, &lcid); - if (NS_SUCCEEDED(res)) { - mLCID = lcid; - } - - nsCOMPtr <nsIPlatformCharset> platformCharset = - do_GetService(NS_PLATFORMCHARSET_CONTRACTID); - if (platformCharset) { - nsAutoCString mappedCharset; - res = platformCharset->GetDefaultCharsetForLocale(wideLocale, mappedCharset); - if (NS_SUCCEEDED(res)) { - mCollation->SetCharset(mappedCharset.get()); - } - } - - return NS_OK; -} - - -NS_IMETHODIMP nsCollationWin::CompareString(int32_t strength, - const nsAString & string1, - const nsAString & string2, - int32_t *result) -{ - int retval; - nsresult res; - DWORD dwMapFlags = 0; - - if (strength == kCollationCaseInSensitive) - dwMapFlags |= NORM_IGNORECASE; - - retval = ::CompareStringW(mLCID, - dwMapFlags, - (LPCWSTR) PromiseFlatString(string1).get(), - -1, - (LPCWSTR) PromiseFlatString(string2).get(), - -1); - if (retval) { - res = NS_OK; - *result = retval - 2; - } else { - res = NS_ERROR_FAILURE; - } - - return res; -} - - -nsresult nsCollationWin::AllocateRawSortKey(int32_t strength, - const nsAString& stringIn, uint8_t** key, uint32_t* outLen) -{ - int byteLen; - void *buffer; - nsresult res = NS_OK; - DWORD dwMapFlags = LCMAP_SORTKEY; - - if (strength == kCollationCaseInSensitive) - dwMapFlags |= NORM_IGNORECASE; - - byteLen = LCMapStringW(mLCID, dwMapFlags, - (LPCWSTR) PromiseFlatString(stringIn).get(), - -1, nullptr, 0); - buffer = PR_Malloc(byteLen); - if (!buffer) { - res = NS_ERROR_OUT_OF_MEMORY; - } else { - *key = (uint8_t *)buffer; - *outLen = LCMapStringW(mLCID, dwMapFlags, - (LPCWSTR) PromiseFlatString(stringIn).get(), - -1, (LPWSTR) buffer, byteLen); - } - return res; -} - -nsresult nsCollationWin::CompareRawSortKey(const uint8_t* key1, uint32_t len1, - const uint8_t* key2, uint32_t len2, - int32_t* result) -{ - *result = PL_strcmp((const char *)key1, (const char *)key2); - return NS_OK; -} diff --git a/intl/locale/windows/nsCollationWin.h b/intl/locale/windows/nsCollationWin.h deleted file mode 100644 index 4ca1aff08de6e594e797d8b52840a1e2d37ed7bd..0000000000000000000000000000000000000000 --- a/intl/locale/windows/nsCollationWin.h +++ /dev/null @@ -1,35 +0,0 @@ - -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#ifndef nsCollationWin_h__ -#define nsCollationWin_h__ - - -#include "nsICollation.h" -#include "nsCollationFactory.h" // static library -#include "plstr.h" - - - -class nsCollationWin final : public nsICollation { - ~nsCollationWin(); - -protected: - nsCollation *mCollation; // XP collation class - uint32_t mLCID; // Windows platform locale ID - -public: - nsCollationWin(); - - // nsISupports interface - NS_DECL_ISUPPORTS - - // nsICollation interface - NS_DECL_NSICOLLATION - -}; - -#endif /* nsCollationWin_h__ */