123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202 |
- #ifndef BOOST_LOCALE_COLLATOR_HPP_INCLUDED
- #define BOOST_LOCALE_COLLATOR_HPP_INCLUDED
- #include <boost/locale/config.hpp>
- #include <locale>
- #ifdef BOOST_MSVC
- # pragma warning(push)
- # pragma warning(disable : 4275 4251 4231 4660)
- #endif
- namespace boost { namespace locale {
-
-
-
-
-
- enum class collate_level {
- primary = 0,
- secondary = 1,
- tertiary = 2,
- quaternary = 3,
- identical = 4
- };
- class BOOST_DEPRECATED("Use collate_level") collator_base {
- public:
- using level_type = collate_level;
- static constexpr auto primary = collate_level::primary;
- static constexpr auto secondary = collate_level::secondary;
- static constexpr auto tertiary = collate_level::tertiary;
- static constexpr auto quaternary = collate_level::quaternary;
- static constexpr auto identical = collate_level::identical;
- };
-
-
-
-
- template<typename CharType>
- class collator : public std::collate<CharType> {
- public:
-
- typedef CharType char_type;
-
- typedef std::basic_string<CharType> string_type;
-
-
-
-
- int compare(collate_level level,
- const char_type* b1,
- const char_type* e1,
- const char_type* b2,
- const char_type* e2) const
- {
- return do_compare(level, b1, e1, b2, e2);
- }
-
-
-
-
-
-
-
-
-
- string_type transform(collate_level level, const char_type* b, const char_type* e) const
- {
- return do_transform(level, b, e);
- }
-
-
-
-
-
- long hash(collate_level level, const char_type* b, const char_type* e) const { return do_hash(level, b, e); }
-
-
-
-
- int compare(collate_level level, const string_type& l, const string_type& r) const
- {
- return do_compare(level, l.data(), l.data() + l.size(), r.data(), r.data() + r.size());
- }
-
-
-
- long hash(collate_level level, const string_type& s) const
- {
- return do_hash(level, s.data(), s.data() + s.size());
- }
-
-
-
-
-
-
-
- string_type transform(collate_level level, const string_type& s) const
- {
- return do_transform(level, s.data(), s.data() + s.size());
- }
- protected:
-
- collator(size_t refs = 0) : std::collate<CharType>(refs) {}
-
-
- int
- do_compare(const char_type* b1, const char_type* e1, const char_type* b2, const char_type* e2) const override
- {
- return do_compare(collate_level::identical, b1, e1, b2, e2);
- }
-
-
- string_type do_transform(const char_type* b, const char_type* e) const override
- {
- return do_transform(collate_level::identical, b, e);
- }
-
-
- long do_hash(const char_type* b, const char_type* e) const override
- {
- return do_hash(collate_level::identical, b, e);
- }
-
-
- virtual int do_compare(collate_level level,
- const char_type* b1,
- const char_type* e1,
- const char_type* b2,
- const char_type* e2) const = 0;
-
- virtual string_type do_transform(collate_level level, const char_type* b, const char_type* e) const = 0;
-
- virtual long do_hash(collate_level level, const char_type* b, const char_type* e) const = 0;
- };
-
-
-
-
-
-
-
-
-
-
- template<typename CharType, collate_level default_level = collate_level::identical>
- struct comparator {
- public:
-
-
-
- comparator(const std::locale& l = std::locale(), collate_level level = default_level) :
- locale_(l), level_(level)
- {}
-
- bool operator()(const std::basic_string<CharType>& left, const std::basic_string<CharType>& right) const
- {
- return std::use_facet<collator<CharType>>(locale_).compare(level_, left, right) < 0;
- }
- private:
- std::locale locale_;
- collate_level level_;
- };
-
- }}
- #ifdef BOOST_MSVC
- # pragma warning(pop)
- #endif
- #endif
|