VIPRA Documentation
Loading...
Searching...
No Matches
caseless_str_comp.hpp
1#pragma once
2
3#include <cstring>
4#include <string>
5
6namespace VIPRA::Behaviors {
7
13 struct Comp {
14 auto operator()(std::string const& str1, std::string const& str2) const -> bool
15 {
16 const size_t cnt = str1.size();
17 if ( cnt != str2.size() ) {
18 return false;
19 }
20
21 for ( size_t i = 0; i < cnt; ++i ) {
22 if ( str1[i] == str2[i] ) {
23 continue;
24 }
25
26 if ( str1[i] > str2[i] ) {
27 if ( str1[i] - SPACE_ASCII != str2[i] ) {
28 return false;
29 }
30 }
31 else {
32 if ( str2[i] - SPACE_ASCII != str1[i] ) {
33 return false;
34 }
35 }
36 }
37 return true;
38 }
39 };
40 struct Hash {
41 auto operator()(std::string const& str) const -> size_t
42 {
43 std::string temp{str};
44 for ( char& chr : temp ) {
45 chr = static_cast<char>(std::tolower(chr));
46 }
47 return std::hash<std::string>{}(temp);
48 }
49 };
50
51 private:
52 static constexpr char SPACE_ASCII = 32;
53};
54
55} // namespace VIPRA::Behaviors
Definition caseless_str_comp.hpp:13
Definition caseless_str_comp.hpp:40
Struct for caseless look up in a std::map.
Definition caseless_str_comp.hpp:12