2001-10-16 16:30:44 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* 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/. */
|
2001-10-16 16:30:44 +04:00
|
|
|
|
2009-05-02 02:57:08 +04:00
|
|
|
#ifndef nsCollationMacUC_h_
|
|
|
|
#define nsCollationMacUC_h_
|
2001-10-16 16:30:44 +04:00
|
|
|
|
|
|
|
#include "nsICollation.h"
|
2009-05-02 02:57:08 +04:00
|
|
|
#include "nsCollation.h"
|
2012-06-06 06:14:46 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2014-10-08 18:43:47 +04:00
|
|
|
|
|
|
|
#include "unicode/ucol.h"
|
2009-05-02 02:57:08 +04:00
|
|
|
#include <Carbon/Carbon.h>
|
2001-10-16 16:30:44 +04:00
|
|
|
|
2002-02-13 01:17:19 +03:00
|
|
|
// Maximum number of characters for a buffer to remember
|
|
|
|
// the generated collation key.
|
2012-08-22 19:56:38 +04:00
|
|
|
const uint32_t kCacheSize = 128;
|
2002-02-15 03:15:32 +03:00
|
|
|
// According to the documentation, the length of the key should typically be
|
2010-10-14 22:51:31 +04:00
|
|
|
// at least 5 * textLength, but 6* would be safer.
|
2012-08-22 19:56:38 +04:00
|
|
|
const uint32_t kCollationValueSizeFactor = 6;
|
2002-02-13 01:17:19 +03:00
|
|
|
|
2012-06-06 06:14:46 +04:00
|
|
|
class nsCollationMacUC MOZ_FINAL : public nsICollation {
|
2001-10-16 16:30:44 +04:00
|
|
|
|
|
|
|
public:
|
|
|
|
nsCollationMacUC();
|
|
|
|
|
2004-08-25 02:50:33 +04:00
|
|
|
// nsISupports interface
|
|
|
|
NS_DECL_ISUPPORTS
|
2001-10-16 16:30:44 +04:00
|
|
|
|
2004-08-25 02:50:33 +04:00
|
|
|
// nsICollation interface
|
|
|
|
NS_DECL_NSICOLLATION
|
2001-10-16 16:30:44 +04:00
|
|
|
|
|
|
|
protected:
|
2014-07-06 19:25:31 +04:00
|
|
|
~nsCollationMacUC();
|
|
|
|
|
2014-10-08 18:43:47 +04:00
|
|
|
nsresult ConvertLocaleICU(nsILocale* aNSLocale, char** aICULocale);
|
2001-10-16 16:30:44 +04:00
|
|
|
nsresult ConvertLocale(nsILocale* aNSLocale, LocaleRef* aMacLocale);
|
2014-10-08 18:43:47 +04:00
|
|
|
nsresult ConvertStrength(const int32_t aStrength,
|
|
|
|
UCollationStrength* aStrengthOut,
|
|
|
|
UColAttributeValue* aCaseLevelOut);
|
2012-08-22 19:56:38 +04:00
|
|
|
nsresult StrengthToOptions(const int32_t aStrength,
|
2001-10-16 16:30:44 +04:00
|
|
|
UCCollateOptions* aOptions);
|
2012-08-22 19:56:38 +04:00
|
|
|
nsresult EnsureCollator(const int32_t newStrength);
|
2014-10-08 18:43:47 +04:00
|
|
|
nsresult CleanUpCollator(void);
|
2001-10-16 16:30:44 +04:00
|
|
|
|
|
|
|
private:
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mInit;
|
|
|
|
bool mHasCollator;
|
2014-10-08 18:43:47 +04:00
|
|
|
char* mLocaleICU;
|
2001-10-16 16:30:44 +04:00
|
|
|
LocaleRef mLocale;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t mLastStrength;
|
2014-10-08 18:43:47 +04:00
|
|
|
UCollator* mCollatorICU;
|
2001-10-16 16:30:44 +04:00
|
|
|
CollatorRef mCollator;
|
2003-07-25 00:31:35 +04:00
|
|
|
void *mBuffer; // temporary buffer to generate collation keys
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mBufferLen; // byte length of buffer
|
2014-10-08 18:43:47 +04:00
|
|
|
bool mUseICU;
|
2001-10-16 16:30:44 +04:00
|
|
|
};
|
|
|
|
|
2009-05-02 02:57:08 +04:00
|
|
|
#endif /* nsCollationMacUC_h_ */
|