2010-07-28 15:29:14 +04:00
|
|
|
/*
|
2011-08-19 02:13:06 +04:00
|
|
|
* Copyright 2003-2011, Haiku, Inc.
|
2010-07-28 15:29:14 +04:00
|
|
|
* Distributed under the terms of the MIT Licence.
|
2010-08-02 00:28:19 +04:00
|
|
|
*/
|
2009-05-01 23:23:59 +04:00
|
|
|
#ifndef _COLLATOR_H_
|
|
|
|
#define _COLLATOR_H_
|
|
|
|
|
|
|
|
|
|
|
|
#include <Archivable.h>
|
2010-08-02 00:28:19 +04:00
|
|
|
#include <SupportDefs.h>
|
2009-05-01 23:23:59 +04:00
|
|
|
|
2010-07-28 15:29:14 +04:00
|
|
|
|
2011-08-19 02:13:06 +04:00
|
|
|
namespace icu {
|
2010-07-28 15:29:14 +04:00
|
|
|
class Collator;
|
2010-07-28 17:16:11 +04:00
|
|
|
class RuleBasedCollator;
|
2010-07-28 15:29:14 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-05-01 23:23:59 +04:00
|
|
|
class BString;
|
|
|
|
class BCollatorAddOn;
|
|
|
|
|
|
|
|
|
|
|
|
enum collator_strengths {
|
|
|
|
B_COLLATE_DEFAULT = -1,
|
|
|
|
|
|
|
|
B_COLLATE_PRIMARY = 1, // e.g.: no diacritical differences, e = é
|
2010-07-28 15:29:14 +04:00
|
|
|
B_COLLATE_SECONDARY, // diacritics are different from their base
|
|
|
|
// characters, a != ä
|
2009-05-01 23:23:59 +04:00
|
|
|
B_COLLATE_TERTIARY, // case sensitive comparison
|
|
|
|
B_COLLATE_QUATERNARY,
|
|
|
|
|
|
|
|
B_COLLATE_IDENTICAL = 127 // Unicode value
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-08-02 00:28:19 +04:00
|
|
|
// N.B.: This class is not multithread-safe, as Compare() and GetKey() change
|
|
|
|
// the ICUCollator (the strength). So if you want to use a BCollator from
|
|
|
|
// more than one thread, you need to protect it with a lock
|
2009-05-02 01:56:16 +04:00
|
|
|
class BCollator : public BArchivable {
|
2010-08-02 00:28:19 +04:00
|
|
|
public:
|
|
|
|
BCollator();
|
|
|
|
BCollator(const char* locale,
|
|
|
|
int8 strength = B_COLLATE_PRIMARY,
|
|
|
|
bool ignorePunctuation = false);
|
|
|
|
BCollator(BMessage* archive);
|
|
|
|
|
|
|
|
BCollator(const BCollator& other);
|
|
|
|
|
|
|
|
~BCollator();
|
|
|
|
|
|
|
|
BCollator& operator=(const BCollator& source);
|
|
|
|
|
|
|
|
void SetDefaultStrength(int8 strength);
|
|
|
|
int8 DefaultStrength() const;
|
|
|
|
|
|
|
|
void SetIgnorePunctuation(bool ignore);
|
|
|
|
bool IgnorePunctuation() const;
|
|
|
|
|
|
|
|
status_t GetSortKey(const char* string, BString* key,
|
|
|
|
int8 strength = B_COLLATE_DEFAULT) const;
|
|
|
|
|
|
|
|
int Compare(const char* s1, const char* s2,
|
|
|
|
int8 strength = B_COLLATE_DEFAULT) const;
|
|
|
|
bool Equal(const char* s1, const char* s2,
|
|
|
|
int8 strength = B_COLLATE_DEFAULT) const;
|
|
|
|
bool Greater(const char* s1, const char* s2,
|
|
|
|
int8 strength = B_COLLATE_DEFAULT) const;
|
|
|
|
bool GreaterOrEqual(const char* s1, const char* s2,
|
|
|
|
int8 strength = B_COLLATE_DEFAULT) const;
|
|
|
|
|
|
|
|
// (un-)archiving API
|
|
|
|
status_t Archive(BMessage* archive, bool deep) const;
|
|
|
|
static BArchivable* Instantiate(BMessage* archive);
|
|
|
|
|
|
|
|
private:
|
|
|
|
status_t _SetStrength(int8 strength) const;
|
|
|
|
|
2011-08-19 02:13:06 +04:00
|
|
|
mutable icu::Collator* fICUCollator;
|
2010-08-02 00:28:19 +04:00
|
|
|
int8 fDefaultStrength;
|
|
|
|
bool fIgnorePunctuation;
|
2009-05-01 23:23:59 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-05-02 01:56:16 +04:00
|
|
|
inline bool
|
2010-08-02 00:28:19 +04:00
|
|
|
BCollator::Equal(const char *s1, const char *s2, int8 strength) const
|
2009-05-01 23:23:59 +04:00
|
|
|
{
|
2010-08-02 00:28:19 +04:00
|
|
|
return Compare(s1, s2, strength) == 0;
|
2009-05-01 23:23:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-02 01:56:16 +04:00
|
|
|
inline bool
|
2010-08-02 00:28:19 +04:00
|
|
|
BCollator::Greater(const char *s1, const char *s2, int8 strength) const
|
2009-05-01 23:23:59 +04:00
|
|
|
{
|
2010-08-02 00:28:19 +04:00
|
|
|
return Compare(s1, s2, strength) > 0;
|
2009-05-01 23:23:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-02 01:56:16 +04:00
|
|
|
inline bool
|
2010-08-02 00:28:19 +04:00
|
|
|
BCollator::GreaterOrEqual(const char *s1, const char *s2, int8 strength) const
|
2009-05-01 23:23:59 +04:00
|
|
|
{
|
2010-08-02 00:28:19 +04:00
|
|
|
return Compare(s1, s2, strength) >= 0;
|
2009-05-01 23:23:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* _COLLATOR_H_ */
|