vfs: check userland buffers before reading them.
[haiku.git] / headers / os / locale / Collator.h
blob1f1ec35129aeb8852aea0a95c237f39d0e3743ad
1 /*
2 * Copyright 2003-2017, Haiku, Inc.
3 * Distributed under the terms of the MIT Licence.
4 */
5 #ifndef _COLLATOR_H_
6 #define _COLLATOR_H_
9 #include <Archivable.h>
10 #include <SupportDefs.h>
13 #ifndef U_ICU_NAMESPACE
14 #define U_ICU_NAMESPACE icu
15 #endif
16 namespace U_ICU_NAMESPACE {
17 class Collator;
20 class BString;
23 enum collator_strengths {
24 B_COLLATE_DEFAULT = -1,
26 B_COLLATE_PRIMARY = 1, // e.g.: no diacritical differences, e = é
27 B_COLLATE_SECONDARY, // diacritics are different from their base
28 // characters, a != ä
29 B_COLLATE_TERTIARY, // case sensitive comparison
30 B_COLLATE_QUATERNARY,
32 B_COLLATE_IDENTICAL = 127 // Unicode value
36 class BCollator : public BArchivable {
37 public:
38 BCollator();
39 BCollator(const char* locale,
40 int8 strength = B_COLLATE_PRIMARY,
41 bool ignorePunctuation = false);
42 BCollator(BMessage* archive);
44 BCollator(const BCollator& other);
46 ~BCollator();
48 BCollator& operator=(const BCollator& source);
50 status_t SetStrength(int8 strength) const;
52 void SetIgnorePunctuation(bool ignore);
53 bool IgnorePunctuation() const;
55 status_t SetNumericSorting(bool enable);
57 status_t GetSortKey(const char* string, BString* key)
58 const;
60 int Compare(const char* s1, const char* s2)
61 const;
62 bool Equal(const char* s1, const char* s2)
63 const;
64 bool Greater(const char* s1, const char* s2)
65 const;
66 bool GreaterOrEqual(const char* s1, const char* s2)
67 const;
69 // (un-)archiving API
70 status_t Archive(BMessage* archive, bool deep) const;
71 static BArchivable* Instantiate(BMessage* archive);
73 private:
75 mutable U_ICU_NAMESPACE::Collator* fICUCollator;
76 bool fIgnorePunctuation;
80 inline bool
81 BCollator::Equal(const char *s1, const char *s2) const
83 return Compare(s1, s2) == 0;
87 inline bool
88 BCollator::Greater(const char *s1, const char *s2) const
90 return Compare(s1, s2) > 0;
94 inline bool
95 BCollator::GreaterOrEqual(const char *s1, const char *s2) const
97 return Compare(s1, s2) >= 0;
101 #endif /* _COLLATOR_H_ */