diff --git a/include/util.hpp b/include/util.hpp index f84babae..2ec110e0 100644 --- a/include/util.hpp +++ b/include/util.hpp @@ -3,6 +3,9 @@ #ifndef RGBDS_UTIL_HPP #define RGBDS_UTIL_HPP +#include +#include +#include #include #include #include @@ -15,8 +18,19 @@ bool continuesIdentifier(int c); char const *printChar(int c); struct Uppercase { - size_t operator()(std::string const &str) const; - bool operator()(std::string const &str1, std::string const &str2) const; + // FNV-1a hash of an uppercased string + constexpr size_t operator()(std::string const &str) const { + return std::accumulate(RANGE(str), 0x811C9DC5, [](size_t hash, char c) { + return (hash ^ toupper(c)) * 16777619; + }); + } + + // Compare two strings without case-sensitivity (by converting to uppercase) + constexpr bool 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); + }); + } }; template diff --git a/src/util.cpp b/src/util.cpp index ad730203..d00cc11b 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -2,8 +2,6 @@ #include "util.hpp" -#include -#include #include #include @@ -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); - }); -}