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