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_
7
8
9#include <Archivable.h>
10#include <SupportDefs.h>
11
12
13#ifndef U_ICU_NAMESPACE
14  #define U_ICU_NAMESPACE icu
15#endif
16namespace U_ICU_NAMESPACE {
17	class Collator;
18};
19
20class BString;
21
22
23enum collator_strengths {
24	B_COLLATE_DEFAULT = -1,
25
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,
31
32	B_COLLATE_IDENTICAL = 127	// Unicode value
33};
34
35
36class BCollator : public BArchivable {
37public:
38								BCollator();
39								BCollator(const char* locale,
40									int8 strength = B_COLLATE_PRIMARY,
41									bool ignorePunctuation = false);
42								BCollator(BMessage* archive);
43
44								BCollator(const BCollator& other);
45
46								~BCollator();
47
48			BCollator&			operator=(const BCollator& source);
49
50			status_t			SetStrength(int8 strength) const;
51
52			void				SetIgnorePunctuation(bool ignore);
53			bool				IgnorePunctuation() const;
54
55			status_t			SetNumericSorting(bool enable);
56
57			status_t			GetSortKey(const char* string, BString* key)
58									const;
59
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;
68
69								// (un-)archiving API
70			status_t			Archive(BMessage* archive, bool deep) const;
71	static	BArchivable*		Instantiate(BMessage* archive);
72
73private:
74
75			mutable U_ICU_NAMESPACE::Collator*	fICUCollator;
76			bool				fIgnorePunctuation;
77};
78
79
80inline bool
81BCollator::Equal(const char *s1, const char *s2) const
82{
83	return Compare(s1, s2) == 0;
84}
85
86
87inline bool
88BCollator::Greater(const char *s1, const char *s2) const
89{
90	return Compare(s1, s2) > 0;
91}
92
93
94inline bool
95BCollator::GreaterOrEqual(const char *s1, const char *s2) const
96{
97	return Compare(s1, s2) >= 0;
98}
99
100
101#endif	/* _COLLATOR_H_ */
102