/Src/Dependencies/Boost/libs/unordered/examples/case_insensitive.hpp

http://hadesmem.googlecode.com/ · C++ Header · 60 lines · 40 code · 11 blank · 9 comment · 2 complexity · d0440f3539d1cbac43b510856dab4010 MD5 · raw file

  1. // Copyright 2006-2009 Daniel James.
  2. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  3. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  4. // This file implements a locale aware case insenstive equality predicate and
  5. // hash function. Unfortunately it still falls short of full
  6. // internationalization as it only deals with a single character at a time
  7. // (some languages have tricky cases where the characters in an upper case
  8. // string don't have a one-to-one correspondence with the lower case version of
  9. // the text, eg. )
  10. #if !defined(BOOST_HASH_EXAMPLES_CASE_INSENSITIVE_HEADER)
  11. #define BOOST_HASH_EXAMPLES_CASE_INSENSITIVE_HEADER
  12. #include <boost/algorithm/string/predicate.hpp>
  13. #include <boost/functional/hash.hpp>
  14. namespace hash_examples
  15. {
  16. struct iequal_to
  17. : std::binary_function<std::string, std::string, bool>
  18. {
  19. iequal_to() {}
  20. explicit iequal_to(std::locale const& l) : locale_(l) {}
  21. template <typename String1, typename String2>
  22. bool operator()(String1 const& x1, String2 const& x2) const
  23. {
  24. return boost::algorithm::iequals(x1, x2, locale_);
  25. }
  26. private:
  27. std::locale locale_;
  28. };
  29. struct ihash
  30. : std::unary_function<std::string, std::size_t>
  31. {
  32. ihash() {}
  33. explicit ihash(std::locale const& l) : locale_(l) {}
  34. template <typename String>
  35. std::size_t operator()(String const& x) const
  36. {
  37. std::size_t seed = 0;
  38. for(typename String::const_iterator it = x.begin();
  39. it != x.end(); ++it)
  40. {
  41. boost::hash_combine(seed, std::toupper(*it, locale_));
  42. }
  43. return seed;
  44. }
  45. private:
  46. std::locale locale_;
  47. };
  48. }
  49. #endif