Libmacro  0.2
Libmacro is an extensible macro and hotkey library.
string_less_ci.h
1 /* Libmacro - A multi-platform, extendable macro and hotkey C library
2  Copyright (C) 2013 Jonathan Pelletier, New Paradigm Software
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Lesser General Public
6  License as published by the Free Software Foundation; either
7  version 2.1 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Lesser General Public License for more details.
13 
14  You should have received a copy of the GNU Lesser General Public
15  License along with this library; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 
19 #ifndef __cplusplus
20  #pragma message "C++ support is required for extras module"
21  #include "mcr/err.h"
22 #endif
23 
24 #ifndef MCR_EXTRAS_UTIL_STRING_LESS_CI_H_
25 #define MCR_EXTRAS_UTIL_STRING_LESS_CI_H_
26 
27 #include "mcr/extras/base_cpp.h"
28 
29 #include <string>
30 #include <functional>
31 
32 namespace mcr
33 {
35 struct string_less_ci : std::binary_function<std::string, std::string, bool>
36 {
37  // case-independent (ci) compare_less binary function
38  struct nocase_compare : public
39  std::binary_function<unsigned char,unsigned char,bool> {
40  bool operator()(const unsigned char& c1, const unsigned char& c2) const
41  {
42  return tolower(c1) < tolower(c2);
43  }
44  };
45  bool operator()(const std::string & s1, const std::string & s2) const
46  {
47  return std::lexicographical_compare
48  (s1.begin(), s1.end(), // source range
49  s2.begin(), s2.end(), // dest range
50  nocase_compare()); // comparison
51  }
52 };
53 }
54 
55 #endif
Raise a compiler error. Usage: #include "mcr/err.h"
Libmacro, by Jonathan Pelletier, New Paradigm Software. Alpha version.
Definition: classes.h:31