Debian Codegraph @

data/0.12-dev/src/InsensitiveSort.h

raw
1 #ifndef INCLUDED_INSENSITIVE_SORTER_H
2 #define INCLUDED_INSENSITIVE_SORTER_H
3
4 #include <string>
5 #include <cstring>
6 using namespace std;
7
8 class InsensitiveSorter
9 {
10 public:
11
12 bool operator()(const string& lhs, const string& rhs)
13 {
14 int val = strcasecmp(lhs.c_str(), rhs.c_str());
15
16 return (
17 (val == 0)
18 ? ( strcmp(lhs.c_str(), rhs.c_str()) < 0 )
19 : ( val < 0 )
20 );
21 }
22 };
23
24 inline void strReplace(string& s, char a, char b)
25 {
26 for(unsigned i = 0;i < s.size();++i)
27 if (s[i] == a)
28 s[i] = b;
29 }
30
31 class InsensitiveSorterFW
32 {
33 public:
34
35 bool operator()(string lhs, string rhs)
36 {
37 strReplace(lhs, ' ', 0);
38 strReplace(rhs, ' ', 0);
39
40 int val = strcasecmp(lhs.c_str(), rhs.c_str());
41
42 return (
43 (val == 0)
44 ? ( strcmp(lhs.c_str(), rhs.c_str()) < 0 )
45 : ( val < 0 )
46 );
47 }
48 };
49
50 #endif // INSENSITIVE_SORTER_H