From 7c6467a9e7ce67495274c7dcf989e2c08500b843 Mon Sep 17 00:00:00 2001 From: Andrzej Rybczak Date: Wed, 5 Sep 2012 18:02:37 +0200 Subject: keys: implement parsing key configuration file --- src/utility/comparators.h | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) (limited to 'src/utility/comparators.h') diff --git a/src/utility/comparators.h b/src/utility/comparators.h index fa5b73b4..87ddad80 100644 --- a/src/utility/comparators.h +++ b/src/utility/comparators.h @@ -26,17 +26,24 @@ class CaseInsensitiveStringComparison { - bool hasTheWord(const std::string &s) - { - return (s.length() > 3) - && (s[0] == 't' || s[0] == 'T') - && (s[1] == 'h' || s[1] == 'H') - && (s[2] == 'e' || s[2] == 'E') - && (s[3] == ' '); - } + bool m_ignore_the; + + bool hasTheWord(const char *s) const; public: - int operator()(const std::string &a, const std::string &b); + CaseInsensitiveStringComparison(bool ignore_the) : m_ignore_the(ignore_the) { } + + int operator()(const char *a, const char *b) const; + + int operator()(const char *a, const std::string &b) const { + return (*this)(a, b.c_str()); + } + int operator()(const std::string &a, const char *b) const { + return (*this)(a.c_str(), b); + } + int operator()(const std::string &a, const std::string &b) const { + return (*this)(a.c_str(), b.c_str()); + } }; class CaseInsensitiveSorting @@ -44,22 +51,22 @@ class CaseInsensitiveSorting CaseInsensitiveStringComparison cmp; public: - bool operator()(const std::string &a, const std::string &b) - { + CaseInsensitiveSorting(); + + bool operator()(const std::string &a, const std::string &b) const { return cmp(a, b) < 0; } - bool operator()(const MPD::Song &a, const MPD::Song &b) - { + bool operator()(const MPD::Song &a, const MPD::Song &b) const { return cmp(a.getName(), b.getName()) < 0; } - template bool operator()(const std::pair &a, const std::pair &b) - { + template + bool operator()(const std::pair &a, const std::pair &b) const { return cmp(a.first, b.first) < 0; } - bool operator()(const MPD::Item &a, const MPD::Item &b); + bool operator()(const MPD::Item &a, const MPD::Item &b) const; }; -#endif // _UTILITY_COMPARATORS \ No newline at end of file +#endif // _UTILITY_COMPARATORS -- cgit v1.2.3