Make struct Uppercase have constexpr methods

This commit is contained in:
Rangi42
2025-08-05 12:11:23 -04:00
parent 70d129fcd7
commit 7020cf7188
2 changed files with 16 additions and 20 deletions

View File

@@ -2,8 +2,6 @@
#include "util.hpp"
#include <algorithm>
#include <ctype.h>
#include <stdint.h>
#include <stdio.h>
@@ -61,19 +59,3 @@ char const *printChar(int c) {
buf[4] = '\0';
return buf;
}
// FNV-1a hash of an uppercased string
size_t Uppercase::operator()(std::string const &str) const {
size_t hash = 0x811C9DC5;
for (char const &c : str) {
hash = (hash ^ toupper(c)) * 16777619;
}
return hash;
}
// Compare two strings without case-sensitivity (by converting to uppercase)
bool Uppercase::operator()(std::string const &str1, std::string const &str2) const {
return std::equal(RANGE(str1), RANGE(str2), [](char c1, char c2) {
return toupper(c1) == toupper(c2);
});
}