File: comparators.hpp

package info (click to toggle)
dtl 1.21-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 440 kB
  • sloc: cpp: 2,285; makefile: 2
file content (24 lines) | stat: -rw-r--r-- 592 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#ifndef DTL_COMPARATORS
#define DTL_COMPARATORS

class CaseInsensitive: public dtl::Compare<char> {
public:
    virtual bool impl(const char& a, const char& b) const {
        return tolower(a) == tolower(b);
    }
};

class StringCaseInsensitive: public dtl::Compare<string> {
public:
    virtual bool impl(const string& a, const string& b) const {
        if (a.length() == b.length()) {
            bool equal = (strncasecmp(a.c_str(), b.c_str(), a.length()) == 0);
            return equal;
        }
        else {
            return false;
        }
    }
};

#endif // DTL_COMPARATORS