File indexing completed on 2025-01-18 09:39:15
0001
0002
0003
0004
0005
0006
0007 #ifndef BOOST_LOCALE_COLLATOR_HPP_INCLUDED
0008 #define BOOST_LOCALE_COLLATOR_HPP_INCLUDED
0009
0010 #include <boost/locale/config.hpp>
0011 #include <locale>
0012
0013 #ifdef BOOST_MSVC
0014 # pragma warning(push)
0015 # pragma warning(disable : 4275 4251 4231 4660)
0016 #endif
0017
0018 namespace boost { namespace locale {
0019
0020
0021
0022
0023
0024
0025
0026 enum class collate_level {
0027 primary = 0,
0028 secondary = 1,
0029 tertiary = 2,
0030 quaternary = 3,
0031 identical = 4
0032 };
0033
0034 class BOOST_DEPRECATED("Use collate_level") collator_base {
0035 public:
0036 using level_type = collate_level;
0037 static constexpr auto primary = collate_level::primary;
0038 static constexpr auto secondary = collate_level::secondary;
0039 static constexpr auto tertiary = collate_level::tertiary;
0040 static constexpr auto quaternary = collate_level::quaternary;
0041 static constexpr auto identical = collate_level::identical;
0042 };
0043
0044
0045
0046
0047
0048 template<typename CharType>
0049 class collator : public std::collate<CharType> {
0050 public:
0051
0052 typedef CharType char_type;
0053
0054 typedef std::basic_string<CharType> string_type;
0055
0056
0057
0058
0059
0060 int compare(collate_level level,
0061 const char_type* b1,
0062 const char_type* e1,
0063 const char_type* b2,
0064 const char_type* e2) const
0065 {
0066 return do_compare(level, b1, e1, b2, e2);
0067 }
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078 string_type transform(collate_level level, const char_type* b, const char_type* e) const
0079 {
0080 return do_transform(level, b, e);
0081 }
0082
0083
0084
0085
0086
0087
0088 long hash(collate_level level, const char_type* b, const char_type* e) const { return do_hash(level, b, e); }
0089
0090
0091
0092
0093
0094 int compare(collate_level level, const string_type& l, const string_type& r) const
0095 {
0096 return do_compare(level, l.data(), l.data() + l.size(), r.data(), r.data() + r.size());
0097 }
0098
0099
0100
0101
0102 long hash(collate_level level, const string_type& s) const
0103 {
0104 return do_hash(level, s.data(), s.data() + s.size());
0105 }
0106
0107
0108
0109
0110
0111
0112
0113
0114 string_type transform(collate_level level, const string_type& s) const
0115 {
0116 return do_transform(level, s.data(), s.data() + s.size());
0117 }
0118
0119 protected:
0120
0121 collator(size_t refs = 0) : std::collate<CharType>(refs) {}
0122
0123
0124
0125 int
0126 do_compare(const char_type* b1, const char_type* e1, const char_type* b2, const char_type* e2) const override
0127 {
0128 return do_compare(collate_level::identical, b1, e1, b2, e2);
0129 }
0130
0131
0132
0133 string_type do_transform(const char_type* b, const char_type* e) const override
0134 {
0135 return do_transform(collate_level::identical, b, e);
0136 }
0137
0138
0139
0140 long do_hash(const char_type* b, const char_type* e) const override
0141 {
0142 return do_hash(collate_level::identical, b, e);
0143 }
0144
0145
0146
0147 virtual int do_compare(collate_level level,
0148 const char_type* b1,
0149 const char_type* e1,
0150 const char_type* b2,
0151 const char_type* e2) const = 0;
0152
0153
0154 virtual string_type do_transform(collate_level level, const char_type* b, const char_type* e) const = 0;
0155
0156 virtual long do_hash(collate_level level, const char_type* b, const char_type* e) const = 0;
0157 };
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168
0169 template<typename CharType, collate_level default_level = collate_level::identical>
0170 struct comparator {
0171 public:
0172
0173
0174
0175 comparator(const std::locale& l = std::locale(), collate_level level = default_level) :
0176 locale_(l), level_(level)
0177 {}
0178
0179
0180 bool operator()(const std::basic_string<CharType>& left, const std::basic_string<CharType>& right) const
0181 {
0182 return std::use_facet<collator<CharType>>(locale_).compare(level_, left, right) < 0;
0183 }
0184
0185 private:
0186 std::locale locale_;
0187 collate_level level_;
0188 };
0189
0190
0191 }}
0192
0193 #ifdef BOOST_MSVC
0194 # pragma warning(pop)
0195 #endif
0196
0197
0198
0199
0200
0201
0202 #endif