not used
[ghsmtp.git] / iequal.hpp
blob297ede86d8bc8391c9391a069c95a3cf52942854
1 #ifndef IEQUAL_DOT_HPP
2 #define IEQUAL_DOT_HPP
4 #include <algorithm>
5 #include <cctype>
6 #include <string_view>
8 // Like boost, but ASCII only. Only C locale required.
10 inline bool iequal_char(char a, char b)
12 return std::toupper(static_cast<unsigned char>(a)) ==
13 std::toupper(static_cast<unsigned char>(b));
16 inline bool iequal(std::string_view a, std::string_view b)
18 return (size(a) == size(b)) &&
19 std::equal(begin(b), end(b), begin(a), iequal_char);
22 inline bool iless_char(char a, char b)
24 return std::toupper(static_cast<unsigned char>(a)) <
25 std::toupper(static_cast<unsigned char>(b));
28 inline bool iless(std::string_view a, std::string_view b)
30 return std::lexicographical_compare(begin(a), end(a), begin(b), end(b),
31 iless_char);
34 inline bool istarts_with(std::string_view str, std::string_view prefix)
36 return (str.size() >= prefix.size()) &&
37 iequal(str.substr(0, prefix.size()), prefix);
40 inline bool iends_with(std::string_view str, std::string_view suffix)
42 return (str.size() >= suffix.size()) &&
43 iequal(str.substr(str.size() - suffix.size(), str.size()), suffix);
46 struct ci_less {
47 bool operator()(std::string_view a, std::string_view b) const
49 return iless(a, b);
53 // Ahh, the olden days of loops and pointers...
55 // inline bool iequal(char const* a, char const* b)
56 // {
57 // if (a == b)
58 // return true;
59 // for (;;) {
60 // if (!iequal_char(*a, *b))
61 // return false;
62 // if (*a == '\0')
63 // return true;
64 // ++a;
65 // ++b;
66 // }
67 // }
69 #endif // IEQUAL_DOT_HPP