Thrill  0.1
less_icase.cpp
Go to the documentation of this file.
1 /*******************************************************************************
2  * tlx/string/less_icase.cpp
3  *
4  * Part of tlx - http://panthema.net/tlx
5  *
6  * Copyright (C) 2007-2017 Timo Bingmann <[email protected]>
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 less_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  if (*a == 0 && *b == 0)
24  return false;
25  if (*a == 0)
26  return true;
27  if (*b == 0)
28  return false;
29 
30  return to_lower(*a) < to_lower(*b);
31 }
32 
33 bool less_icase(const char* a, const std::string& b) {
34  std::string::const_iterator bi = b.begin();
35 
36  while (*a != 0 && bi != b.end() && to_lower(*a) == to_lower(*bi))
37  ++a, ++bi;
38 
39  if (*a == 0 && bi == b.end())
40  return false;
41  if (*a == 0)
42  return true;
43  if (bi == b.end())
44  return false;
45 
46  return to_lower(*a) < to_lower(*bi);
47 }
48 
49 bool less_icase(const std::string& a, const char* b) {
50  std::string::const_iterator ai = a.begin();
51 
52  while (ai != a.end() && *b != 0 && to_lower(*ai) == to_lower(*b))
53  ++ai, ++b;
54 
55  if (ai == a.end() && *b == 0)
56  return false;
57  if (ai == a.end())
58  return true;
59  if (*b == 0)
60  return false;
61 
62  return to_lower(*ai) < to_lower(*b);
63 }
64 
65 bool less_icase(const std::string& a, const std::string& b) {
66  return std::lexicographical_compare(
67  a.begin(), a.end(), b.begin(), b.end(),
68  [](char c1, char c2) { return to_lower(c1) < to_lower(c2); });
69 }
70 
71 } // namespace tlx
72 
73 /******************************************************************************/
bool less_icase(const char *a, const char *b)
returns true if a < b without regard for letter case
Definition: less_icase.cpp:18
char to_lower(char ch)
Transform the given character to lower case without any localization.
Definition: to_lower.cpp:17
std::basic_string< char, std::char_traits< char >, Allocator< char > > string
string with Manager tracking
Definition: allocator.hpp:220