haiku/headers/os/locale/Collator.h
Oliver Tappe 38ac8def5a Largish cleanup sweep concerning the Locale Kit (sorry it got so big):
* refactored private/mutable stuff out of LocaleRoster into MutableLocaleRoster
* moved management of Locale/Time settings file and broadcasting of any changes 
  out of preflets and into MutableLocaleRoster
* added proper sorting to the listviews of the Locale preflet
* the Time preflet no longer overlaps long timezone names into the actual time
* several fixes with respect to leaking ICU objects, esp. in BCountry
* the locale roster no longer passes out references to its own BCountry object,
  but uses copies, instead - this makes locking superfluous, as the clients'
  BCountry objects can no longer be changed by the setting a new default 
  country in the locale roster
* removed pretty useless POSIX-style symbol fetching from BCountry - if we
  need that at all, it should live in the dedicated formatter classes
* adjusted readonlybootprompt, dstcheck and Deskbar to the changed Locale API
* refactored existing Time-formatter into TimeUnitFormat and DurationFormat
  (the latter of which is now used by AboutSystem)
* added stubs for Date, DateTime and Time formatters
* lots of coding style fixes throughout the Locale Kit and the Locale and Time 
  preflets
This will probably break most external apps making use of the Locale Kit - it
does break WebPositive.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37831 a95241bf-73f2-0310-859d-f6bbb57e9c96
2010-08-01 20:28:19 +00:00

106 lines
2.6 KiB
C++

/*
* Copyright 2003-2010, Haiku, Inc.
* Distributed under the terms of the MIT Licence.
*/
#ifndef _COLLATOR_H_
#define _COLLATOR_H_
#include <Archivable.h>
#include <SupportDefs.h>
namespace icu_44 {
class Collator;
class RuleBasedCollator;
};
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 icu_44::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_ */