Template
1
0
Files
WebBase/src/Helpers.hpp
2025-07-02 15:30:31 +03:00

29 lines
939 B
C++

// Big thanks to
// https://medium.com/@ryan_forrester_/using-switch-statements-with-strings-in-c-a-complete-guide-efa12f64a59d
#include <cstddef>
#include <cstdint>
#include <string>
#include <string_view>
namespace Helpers {
std::string ReadFile(std::string Path);
void getlineAndCount(std::basic_istream<char> &stream, uint64_t &count,
std::string &string, char delimit = '\0');
std::string GenerateResponse(std::string statusCode, std::string contentType,
std::string content);
// ===========
// Hashing
// ===========
// This is called a polynomial rolling hash, prob going to collide
constexpr uint64_t Pathhash(std::string_view s) {
uint64_t res = 0;
for (uint8_t c : s) {
res = (res * 131) + c;
}
return res;
}
} // namespace Helpers
constexpr uint64_t operator""_hash(const char *string, std::size_t count) {
return Helpers::Pathhash(std::string_view(string));
}