18 std::size_t lastValid = 0;
20 const auto c =
static_cast<unsigned char>(value[i]);
24 }
else if ((c & 0xE0) == 0xC0) {
26 }
else if ((c & 0xF0) == 0xE0) {
28 }
else if ((c & 0xF8) == 0xF0) {
34 if (i + len > value.size() || i + len >
k_maxBytes)
37 bool validContinuation =
true;
38 for (std::size_t j = 1; j < len; ++j) {
39 const auto next =
static_cast<unsigned char>(value[i + j]);
40 if ((next & 0xC0) != 0x80) {
41 validContinuation =
false;
45 if (!validContinuation)
52 return std::string(value.substr(0, lastValid));
Definition ServerName.hpp:11
std::string clampUtf8Bytes(std::string_view value)
Definition ServerName.hpp:15
std::string sanitize(std::string_view value, std::string_view fallback=k_default)
Definition ServerName.hpp:55
constexpr std::size_t k_maxBytes
Definition ServerName.hpp:12
constexpr std::string_view k_default
Definition ServerName.hpp:13