12static constexpr size_t JSON_ESCAPE_MAX_EXPANSION = 6;
27 const size_t limit = buf.size() - 1;
29 for (
char ch : value) {
30 auto c =
static_cast<unsigned char>(ch);
64 }
else if (c < 0x20) {
67 if (
pos + JSON_ESCAPE_MAX_EXPANSION > limit)
78 buf[
pos++] =
static_cast<char>(c);
StringRef is a reference to a string owned by something else.
const char * json_escape_into_buffer(std::span< char > buf, StringRef value)
Copy value into buf, escaping the characters that cannot appear raw inside a JSON string literal.
ESPHOME_ALWAYS_INLINE char format_hex_char(uint8_t v, char base)
Convert a nibble (0-15) to hex char with specified base ('a' for lowercase, 'A' for uppercase)