Warning, file /include/boost/locale/collator.hpp was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
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 <boost/locale/detail/facet_id.hpp>
0012 #include <locale>
0013
0014 #ifdef BOOST_MSVC
0015 # pragma warning(push)
0016 # pragma warning(disable : 4275 4251 4231 4660)
0017 #endif
0018
0019 namespace boost { namespace locale {
0020
0021
0022
0023
0024
0025
0026
0027 enum class collate_level {
0028 primary = 0,
0029 secondary = 1,
0030 tertiary = 2,
0031 quaternary = 3,
0032 identical = 4
0033 };
0034
0035 class BOOST_DEPRECATED("Use collate_level") collator_base {
0036 public:
0037 using level_type = collate_level;
0038 static constexpr auto primary = collate_level::primary;
0039 static constexpr auto secondary = collate_level::secondary;
0040 static constexpr auto tertiary = collate_level::tertiary;
0041 static constexpr auto quaternary = collate_level::quaternary;
0042 static constexpr auto identical = collate_level::identical;
0043 };
0044
0045
0046
0047
0048 template<typename CharType>
0049 class BOOST_SYMBOL_VISIBLE collator : public std::locale::facet, public detail::facet_id<collator<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 int compare(const char_type* b1, const char_type* e1, const char_type* b2, const char_type* e2) const
0072 {
0073 return compare(collate_level::identical, b1, e1, b2, e2);
0074 }
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085 string_type transform(collate_level level, const char_type* b, const char_type* e) const
0086 {
0087 return do_transform(level, b, e);
0088 }
0089
0090
0091
0092 string_type transform(const char_type* b, const char_type* e) const
0093 {
0094 return transform(collate_level::identical, b, e);
0095 }
0096
0097
0098
0099
0100
0101
0102 long hash(collate_level level, const char_type* b, const char_type* e) const { return do_hash(level, b, e); }
0103
0104
0105
0106 long hash(const char_type* b, const char_type* e) const { return hash(collate_level::identical, b, e); }
0107
0108
0109
0110
0111
0112 int compare(collate_level level, const string_type& l, const string_type& r) const
0113 {
0114 return do_compare(level, l.data(), l.data() + l.size(), r.data(), r.data() + r.size());
0115 }
0116
0117
0118
0119
0120 long hash(collate_level level, const string_type& s) const
0121 {
0122 return do_hash(level, s.data(), s.data() + s.size());
0123 }
0124
0125
0126
0127
0128
0129
0130
0131
0132 string_type transform(collate_level level, const string_type& s) const
0133 {
0134 return do_transform(level, s.data(), s.data() + s.size());
0135 }
0136
0137 protected:
0138
0139 collator(size_t refs = 0) : std::locale::facet(refs) {}
0140
0141
0142
0143 virtual int do_compare(collate_level level,
0144 const char_type* b1,
0145 const char_type* e1,
0146 const char_type* b2,
0147 const char_type* e2) const = 0;
0148
0149
0150 virtual string_type do_transform(collate_level level, const char_type* b, const char_type* e) const = 0;
0151
0152 virtual long do_hash(collate_level level, const char_type* b, const char_type* e) const = 0;
0153 };
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165 template<typename CharType, collate_level default_level = collate_level::identical>
0166 struct comparator {
0167 public:
0168
0169
0170
0171 comparator(const std::locale& l = std::locale(), collate_level level = default_level) :
0172 locale_(l), collator_(std::use_facet<collator<CharType>>(locale_)), level_(level)
0173 {}
0174
0175
0176 bool operator()(const std::basic_string<CharType>& left, const std::basic_string<CharType>& right) const
0177 {
0178 return collator_.compare(level_, left, right) < 0;
0179 }
0180
0181 private:
0182 std::locale locale_;
0183 const collator<CharType>& collator_;
0184 collate_level level_;
0185 };
0186
0187
0188 }}
0189
0190 #ifdef BOOST_MSVC
0191 # pragma warning(pop)
0192 #endif
0193
0194
0195
0196
0197
0198
0199 #endif