~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/util/string.h

Refactor

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
  Some sections of this code came from the Boost examples.
34
34
*/
35
35
 
36
 
#ifndef DRIZZLED_UTIL_STRING_H
37
 
#define DRIZZLED_UTIL_STRING_H
 
36
#pragma once
38
37
 
39
38
#include <utility>
40
39
#include <string>
41
40
#include <vector>
42
41
 
43
42
#include <boost/algorithm/string/predicate.hpp>
 
43
#include <boost/foreach.hpp>
44
44
#include <boost/functional/hash.hpp>
45
45
#include <boost/shared_ptr.hpp>
46
46
 
47
 
namespace drizzled
48
 
{
49
 
 
50
 
namespace util
51
 
{
52
 
 
53
 
 
54
 
namespace string {
55
 
typedef boost::shared_ptr<std::string> shared_ptr;
56
 
typedef boost::shared_ptr<const std::string> const_shared_ptr;
57
 
typedef std::vector< std::string > vector;
 
47
namespace drizzled {
 
48
namespace util {
 
49
 
 
50
namespace string 
 
51
{
 
52
  typedef boost::shared_ptr<std::string> shared_ptr;
 
53
  typedef boost::shared_ptr<const std::string> const_shared_ptr;
 
54
  typedef std::vector<std::string> vector;
58
55
}
59
56
 
60
57
struct insensitive_equal_to : std::binary_function<std::string, std::string, bool>
61
58
{
62
59
  bool operator()(std::string const& x, std::string const& y) const
63
60
  {
64
 
    return boost::algorithm::iequals(x, y, std::locale());
 
61
    return boost::algorithm::iequals(x, y);
65
62
  }
66
63
};
67
64
 
70
67
  std::size_t operator()(std::string const& x) const
71
68
  {
72
69
    std::size_t seed = 0;
73
 
    std::locale locale;
74
 
 
75
 
    for(std::string::const_iterator it = x.begin(); it != x.end(); ++it)
76
 
    {
77
 
      boost::hash_combine(seed, std::toupper(*it, locale));
78
 
    }
79
 
 
 
70
    BOOST_FOREACH(std::string::const_reference it, x)
 
71
      boost::hash_combine(seed, std::toupper(it));
80
72
    return seed;
81
73
  }
82
74
};
86
78
  std::size_t operator()(std::vector<char> const& x) const
87
79
  {
88
80
    std::size_t seed = 0;
89
 
 
90
 
    for(std::vector<char>::const_iterator it = x.begin(); it != x.end(); ++it)
91
 
    {
92
 
      boost::hash_combine(seed, *it);
93
 
    }
94
 
 
 
81
    BOOST_FOREACH(std::vector<char>::const_reference it, x)
 
82
      boost::hash_combine(seed, it);
95
83
    return seed;
96
84
  }
97
85
};
99
87
} /* namespace util */
100
88
} /* namespace drizzled */
101
89
 
102
 
#endif /* DRIZZLED_UTIL_STRING_H */