ICP  1
ci_string.h
Go to the documentation of this file.
1 #ifndef CI_STRING_H
2 #define CI_STRING_H
3 
4 template <typename T> struct ci_char_traits
5 {
6 };
7 
8 template<> struct ci_char_traits<char>
9 {
10  typedef char char_type;
11  typedef int int_type;
12  typedef std::streamoff off_type;
13  typedef std::mbstate_t state_t;
14  static void assign(char_type& dst, const char_type& src)
15  {
16  std::char_traits<char>::assign(dst, src);
17  }
18  static char_type* assign(char_type* dst, std::size_t n, const char_type& c)
19  {
20  return std::char_traits<char>::assign(dst, n, c);
21  }
22  static size_t length(const char_type* str)
23  {
24  return std::char_traits<char>::length(str);
25  }
26  static bool eq(const char_type& c1, const char_type& c2)
27  {
28  return lower(c1) == lower(c2);
29  }
30  static bool lt(const char_type& c1, const char_type& c2)
31  {
32  return lower(c1) < lower(c2);
33  }
34  static int compare(const char_type* s1, const char_type* s2, std::size_t n)
35  {
36  for(size_t i = 0; i< n; i++)
37  {
38  char_type lc1 = static_cast<char_type>(lower(s1[i]));
39  char_type lc2 = static_cast<char_type>(lower(s2[i]));
40  if (lc1 < lc2)
41  {
42  return -1;
43  }
44  else if (lc1 > lc2)
45  {
46  return 1;
47  }
48  }
49  return 0;
50  }
51  static char_type* move(char_type* dst, const char_type* src, size_t n)
52  {
53  return std::char_traits<char>::move(dst, src, n);
54  }
55  static char_type* copy(char_type* dst, const char_type* src, size_t n)
56  {
57  return std::char_traits<char>::copy(dst, src, n);
58  }
59 
60 private:
62  {
63  return std::tolower(std::char_traits<char>::to_int_type(c));
64  }
65 };
66 
67 typedef std::basic_string<char, ci_char_traits<char> > ci_string_t;
68 
69 #endif /* CI_STRING_H */
static char_type * assign(char_type *dst, std::size_t n, const char_type &c)
Definition: ci_string.h:18
static size_t length(const char_type *str)
Definition: ci_string.h:22
std::streamoff off_type
Definition: ci_string.h:12
static int_type lower(char_type c)
Definition: ci_string.h:61
static bool lt(const char_type &c1, const char_type &c2)
Definition: ci_string.h:30
std::mbstate_t state_t
Definition: ci_string.h:13
static int compare(const char_type *s1, const char_type *s2, std::size_t n)
Definition: ci_string.h:34
static bool eq(const char_type &c1, const char_type &c2)
Definition: ci_string.h:26
static char_type * move(char_type *dst, const char_type *src, size_t n)
Definition: ci_string.h:51
static void assign(char_type &dst, const char_type &src)
Definition: ci_string.h:14
std::basic_string< char, ci_char_traits< char > > ci_string_t
Definition: ci_string.h:67
static char_type * copy(char_type *dst, const char_type *src, size_t n)
Definition: ci_string.h:55