| 1 | /* |
| 2 | * IXStrCaseCompare.cpp |
| 3 | * Author: Benjamin Sergeant |
| 4 | * Copyright (c) 2020 Machine Zone. All rights reserved. |
| 5 | */ |
| 6 | |
| 7 | #include "IXStrCaseCompare.h" |
| 8 | |
| 9 | #include <algorithm> |
| 10 | #include <locale> |
| 11 | |
| 12 | namespace ix |
| 13 | { |
| 14 | bool CaseInsensitiveLess::NocaseCompare::operator()(const unsigned char& c1, |
| 15 | const unsigned char& c2) const |
| 16 | { |
| 17 | #if defined(_WIN32) && !defined(__GNUC__) |
| 18 | return std::tolower(c1, std::locale()) < std::tolower(c2, std::locale()); |
| 19 | #else |
| 20 | return std::tolower(c1) < std::tolower(c2); |
| 21 | #endif |
| 22 | } |
| 23 | |
| 24 | bool CaseInsensitiveLess::cmp(const std::string& s1, const std::string& s2) |
| 25 | { |
| 26 | return std::lexicographical_compare(s1.begin(), |
| 27 | s1.end(), // source range |
| 28 | s2.begin(), |
| 29 | s2.end(), // dest range |
| 30 | NocaseCompare()); // comparison |
| 31 | } |
| 32 | |
| 33 | bool CaseInsensitiveLess::operator()(const std::string& s1, const std::string& s2) const |
| 34 | { |
| 35 | return CaseInsensitiveLess::cmp(s1, s2); |
| 36 | } |
| 37 | } // namespace ix |
| 38 | |