tlx
equal_icase.cpp
Go to the documentation of this file.
1 /*******************************************************************************
2  * tlx/string/equal_icase.cpp
3  *
4  * Part of tlx - http://panthema.net/tlx
5  *
6  * Copyright (C) 2007-2017 Timo Bingmann <tb@panthema.net>
7  *
8  * All rights reserved. Published under the Boost Software License, Version 1.0
9  ******************************************************************************/
10 
12 #include <tlx/string/to_lower.hpp>
13 
14 #include <algorithm>
15 
16 namespace tlx {
17 
18 bool equal_icase(const char* a, const char* b) {
19 
20  while (*a != 0 && *b != 0 && to_lower(*a) == to_lower(*b))
21  ++a, ++b;
22 
23  return *a == 0 && *b == 0;
24 }
25 
26 bool equal_icase(const char* a, const std::string& b) {
27  std::string::const_iterator bi = b.begin();
28 
29  while (*a != 0 && bi != b.end() && to_lower(*a) == to_lower(*bi))
30  ++a, ++bi;
31 
32  return *a == 0 && bi == b.end();
33 }
34 
35 bool equal_icase(const std::string& a, const char* b) {
36  std::string::const_iterator ai = a.begin();
37 
38  while (ai != a.end() && *b != 0 && to_lower(*ai) == to_lower(*b))
39  ++ai, ++b;
40 
41  return ai == a.end() && *b != 0;
42 }
43 
44 bool equal_icase(const std::string& a, const std::string& b) {
45  if (a.size() != b.size()) return false;
46 
47  return std::equal(
48  a.begin(), a.end(), b.begin(),
49  [](char c1, char c2) { return to_lower(c1) == to_lower(c2); });
50 }
51 
52 } // namespace tlx
53 
54 /******************************************************************************/
bool equal_icase(const char *a, const char *b)
returns true if a == b without regard for letter case
Definition: equal_icase.cpp:18
char to_lower(char ch)
Transform the given character to lower case without any localization.
Definition: to_lower.cpp:17