DDS  ver. 3.5.3.8.g5fe284b
CIString.h
Go to the documentation of this file.
1 // Copyright 2014 GSI, Inc. All rights reserved.
2 //
3 // Case Insensitive String
4 //
5 #ifndef CISTRING_H_
6 #define CISTRING_H_
7 
8 namespace MiscCommon
9 {
19  template <class _charT>
20  struct char_traits_ci_base : std::char_traits<_charT>
21  {
22  static bool eq(const _charT& _Left, const _charT& _Right);
23  static bool lt(const _charT& _Left, const _charT& _Right);
24  static int compare(const _charT* _First1, const _charT* _First2, size_t _Count);
25  };
31  template <>
32  struct char_traits_ci_base<char> : std::char_traits<char>
33  {
34  typedef char _charT;
35  static bool eq(const _charT& _Left, const _charT& _Right)
36  {
37  // test for element equality
38  return (::toupper(_Left) == ::toupper(_Right));
39  }
40  static bool lt(const _charT& _Left, const _charT& _Right)
41  {
42  // test if _Left precedes _Right
43  return (::toupper(_Left) < ::toupper(_Right));
44  }
45  };
51  template <>
52  struct char_traits_ci_base<wchar_t> : std::char_traits<wchar_t>
53  {
54  typedef wchar_t _charT;
55  static bool eq(const _charT& _Left, const _charT& _Right)
56  {
57  // test for element equality
58  return (::towupper(_Left) == ::towupper(_Right));
59  }
60  static bool lt(const _charT& _Left, const _charT& _Right)
61  {
62  // test if _Left precedes _Right
63  return (::towupper(_Left) < ::towupper(_Right));
64  }
65  };
74  template <class _charT>
76  {
77  typedef std::_Secure_char_traits_tag _Secure_char_traits;
78 
79  static int compare(const _charT* _First1, const _charT* _First2, size_t _Count)
80  {
81  // compare [_First1, _First1 + _Count) with [_First2, ...)
82  return (::_memicmp(_First1, _First2, _Count * sizeof(_Elem)));
83  }
84  static const _charT* find(const _charT* _First, size_t _Count, const _charT& _Ch)
85  {
86  // look for _Ch in [_First, _First + _Count)
87  for (; 0 < _Count; --_Count, ++_First)
88  if (eq(*_First, _Ch))
89  return (_First);
90  return (0);
91  }
92  };
99  typedef std::basic_string<wchar_t, char_traits_ci_t<wchar_t>, std::allocator<wchar_t>> ci_wstring;
106  typedef std::basic_string<char, char_traits_ci_t<char>, std::allocator<char>> ci_string;
112 #if defined(_GLIBCPP_USE_WCHAR_T) && defined(_UNICODE)
113  typedef ci_wstring ci_tstring;
114 #else
116 #endif
117 }; // namespace MiscCommon
118 
119 #endif /*CISTRING_H_*/
static bool eq(const _charT &_Left, const _charT &_Right)
char _charT
Definition: CIString.h:34
std::_Secure_char_traits_tag _Secure_char_traits
Definition: CIString.h:77
static int compare(const _charT *_First1, const _charT *_First2, size_t _Count)
The char_traits_ci_t class is the default character traits class used for case insensitive strings....
Definition: CIString.h:75
std::basic_string< wchar_t, char_traits_ci_t< wchar_t >, std::allocator< wchar_t > > ci_wstring
The basic_string class is parameterized by wchar_t and by char_traits_ci_t. Represents case insensiti...
Definition: CIString.h:99
static bool lt(const _charT &_Left, const _charT &_Right)
Definition: CIString.h:60
static bool eq(const _charT &_Left, const _charT &_Right)
Definition: CIString.h:55
static int compare(const _charT *_First1, const _charT *_First2, size_t _Count)
Definition: CIString.h:79
static bool eq(const _charT &_Left, const _charT &_Right)
Definition: CIString.h:35
ci_string ci_tstring
A type definition of case insensitive string.
Definition: CIString.h:115
static bool lt(const _charT &_Left, const _charT &_Right)
std::basic_string< char, char_traits_ci_t< char >, std::allocator< char > > ci_string
The basic_string class is parameterized by char and by char_traits_ci_t. Represents case insensitive ...
Definition: CIString.h:106
wchar_t _charT
Definition: CIString.h:54
static const _charT * find(const _charT *_First, size_t _Count, const _charT &_Ch)
Definition: CIString.h:84
The char_traits_ci_base class is the default character traits class used for case insensitive strings...
Definition: CIString.h:20
static bool lt(const _charT &_Left, const _charT &_Right)
Definition: CIString.h:40
Miscellaneous functions and helpers are located here.
Definition: BOOST_FILESYSTEM.h:21