haiku/headers/os/locale/Collator.h
Jérôme Duval 73de58376a Update icu x86_64 package with namespace renaming enabled.
"Renaming" means the icu namespace is suffixed with the version number,
atm icu_55. Using "renaming" allows to use two different versions of ICU,
thus easing upgrades. For instance haikuwebkit uses a current version of ICU,
while the system uses a newer one after an upgrade.

* Replace all uses of the icu namespace in our public headers, with a macro
defaulting to icu. As the namespace is only used for private fields pointers,
there should be no impact.
* Locale kit *.cpp have to import the macro from <unicode/uversion.h> *before*
including any locale headers. Ditto for a Time preferences cpp file. This way,
the correct current icu namespace is referenced.
* Fixes bug #12057.
2015-05-10 21:52:36 +02:00

107 lines
2.6 KiB
C++

/*
* Copyright 2003-2011, Haiku, Inc.
* Distributed under the terms of the MIT Licence.
*/
#ifndef _COLLATOR_H_
#define _COLLATOR_H_
#include <Archivable.h>
#include <SupportDefs.h>
#ifndef U_ICU_NAMESPACE
#define U_ICU_NAMESPACE icu
#endif
namespace U_ICU_NAMESPACE {
class Collator;
};
class BString;
class BCollatorAddOn;
enum collator_strengths {
B_COLLATE_DEFAULT = -1,
B_COLLATE_PRIMARY = 1, // e.g.: no diacritical differences, e = é
B_COLLATE_SECONDARY, // diacritics are different from their base
// characters, a != ä
B_COLLATE_TERTIARY, // case sensitive comparison
B_COLLATE_QUATERNARY,
B_COLLATE_IDENTICAL = 127 // Unicode value
};
// 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
class BCollator : public BArchivable {
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;
mutable U_ICU_NAMESPACE::Collator* fICUCollator;
int8 fDefaultStrength;
bool fIgnorePunctuation;
};
inline bool
BCollator::Equal(const char *s1, const char *s2, int8 strength) const
{
return Compare(s1, s2, strength) == 0;
}
inline bool
BCollator::Greater(const char *s1, const char *s2, int8 strength) const
{
return Compare(s1, s2, strength) > 0;
}
inline bool
BCollator::GreaterOrEqual(const char *s1, const char *s2, int8 strength) const
{
return Compare(s1, s2, strength) >= 0;
}
#endif /* _COLLATOR_H_ */