PageRenderTime 148ms CodeModel.GetById 141ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

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