winss
case_ignore.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2016-2017 Morgan Stanley
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef LIB_WINSS_CASE_IGNORE_HPP_
18 #define LIB_WINSS_CASE_IGNORE_HPP_
19 
20 #include <string>
21 #include <functional>
22 
23 namespace winss {
27 typedef unsigned char u_char;
28 
32 struct case_ignore : std::binary_function<std::string, std::string, bool> {
36  struct nocase_compare : public std::binary_function<u_char, u_char, bool> {
44  bool operator() (const u_char& c1, const u_char& c2) const {
45  return ::tolower(c1) < ::tolower(c2);
46  }
47  };
48 
56  bool operator() (const std::string& s1, const std::string& s2) const {
57  return std::lexicographical_compare
58  (s1.begin(), s1.end(), s2.begin(), s2.end(), nocase_compare());
59  }
60 };
61 } // namespace winss
62 
63 #endif // LIB_WINSS_CASE_IGNORE_HPP_
bool operator()(const u_char &c1, const u_char &c2) const
Compares two characters ignoring the case.
Definition: case_ignore.hpp:44
A binary function to ignore case when comparing strings.
Definition: case_ignore.hpp:32
Definition: case_ignore.hpp:23
unsigned char u_char
Unsigned char for readability.
Definition: case_ignore.hpp:27
A binary function to ignore case when comparing characters.
Definition: case_ignore.hpp:36