| 285 | |
| 286 | |
| 287 | int strcasecmp(const char* s1, const char* s2) { |
| 288 | for (size_t i = 0; s1[i] || s2[i]; i++) { |
| 289 | // Cast [-128, -1] char to [128, 255] because negative ints are undefined |
| 290 | int c1 = std::tolower((unsigned char) s1[i]); |
| 291 | int c2 = std::tolower((unsigned char) s2[i]); |
| 292 | if (c1 != c2) |
| 293 | return c1 - c2; |
| 294 | } |
| 295 | return 0; |
| 296 | } |
| 297 | |
| 298 | |
| 299 | bool CaseInsensitiveCompare::operator()(const std::string& a, const std::string& b) const { |