#include <cstddef>
#include <cstdint>
#include <string_view>
#include "cow_string.hpp"
#include "transformer/unicode_normalize.hpp"
#include "utf8.hpp"
using namespace ddwaf::utf8;
namespace ddwaf::transformer {
bool unicode_normalize::needs_transform(std::string_view str)
{
uint32_t codepoint;
uint64_t position = 0;
while ((codepoint = fetch_next_codepoint(str.data(), position, str.length())) != UTF8_EOF) {
if (codepoint == UTF8_INVALID || codepoint < 0x80) {
continue;
}
int32_t decomposed_codepoint = 0;
const size_t decomposed_length =
ddwaf::utf8::normalize_codepoint(codepoint, &decomposed_codepoint, 1);
if (decomposed_length != 1 || codepoint != static_cast<uint32_t>(decomposed_codepoint)) {
return true;
}
}
return false;
}
bool unicode_normalize::transform_impl(cow_string &str) { return utf8::normalize_string(str); }
}