diff options
Diffstat (limited to 'libadhocutil/case_less.h')
-rw-r--r-- | libadhocutil/case_less.h | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/libadhocutil/case_less.h b/libadhocutil/case_less.h new file mode 100644 index 0000000..fbe3d3b --- /dev/null +++ b/libadhocutil/case_less.h @@ -0,0 +1,19 @@ +#ifndef ADHOCUTIL_CASELESS_H +#define ADHOCUTIL_CASELESS_H + +#include <algorithm> +#include <cstring> + +namespace AdHoc { + struct case_less { + template<typename A, typename B> + inline bool + operator()(const A & a, const B & b) const + { + const auto cmp = strncasecmp(a.data(), b.data(), std::min(a.length(), b.length())); + return (cmp < 0) || (!cmp && a.length() < b.length()); + } + }; +} + +#endif |