ESPHome 2026.5.0b1
Loading...
Searching...
No Matches
alloc_helpers.h File Reference

Heap-allocating helper functions. More...

Go to the source code of this file.

Namespaces

namespace  esphome
 

Functions

std::string esphome::str_truncate (const std::string &str, size_t length)
 Truncate a string to a specific length.
 
std::string esphome::str_until (const char *str, char ch)
 Extract the part of the string until either the first occurrence of the specified character, or the end (requires str to be null-terminated).
 
std::string esphome::str_until (const std::string &str, char ch)
 Extract the part of the string until either the first occurrence of the specified character, or the end.
 
std::string esphome::str_lower_case (const std::string &str)
 Convert the string to lower case.
 
std::string esphome::str_upper_case (const std::string &str)
 Convert the string to upper case.
 
std::string esphome::str_snake_case (const std::string &str)
 Convert the string to snake case (lowercase with underscores).
 
std::string esphome::str_sanitize (const std::string &str)
 Sanitizes the input string by removing all characters but alphanumerics, dashes and underscores.
 
std::string esphome::__attribute__ ((format(printf, 1, 3))) str_snprintf(const char *fmt
 snprintf-like function returning std::string of maximum length len (excluding null terminator).
 
std::string size_t std::string esphome::__attribute__ ((format(printf, 1, 2))) str_sprintf(const char *fmt
 sprintf-like function returning std::string.
 
std::string size_t std::string std::string esphome::format_mac_address_pretty (const uint8_t mac[6])
 Format the six-byte array mac into a MAC address string.
 
std::string esphome::format_hex (const uint8_t *data, size_t length)
 Format the byte array data of length len in lowercased hex.
 
std::string esphome::format_hex (const std::vector< uint8_t > &data)
 Format the vector data in lowercased hex.
 
std::string esphome::format_hex_pretty (const uint8_t *data, size_t length, char separator='.', bool show_length=true)
 Format a byte array in pretty-printed, human-readable hex format.
 
std::string esphome::format_hex_pretty (const uint16_t *data, size_t length, char separator='.', bool show_length=true)
 Format a 16-bit word array in pretty-printed, human-readable hex format.
 
std::string esphome::format_hex_pretty (const std::vector< uint8_t > &data, char separator='.', bool show_length=true)
 Format a byte vector in pretty-printed, human-readable hex format.
 
std::string esphome::format_hex_pretty (const std::vector< uint16_t > &data, char separator='.', bool show_length=true)
 Format a 16-bit word vector in pretty-printed, human-readable hex format.
 
std::string esphome::format_hex_pretty (const std::string &data, char separator='.', bool show_length=true)
 Format a string's bytes in pretty-printed, human-readable hex format.
 
std::string esphome::format_bin (const uint8_t *data, size_t length)
 Format the byte array data of length len in binary.
 
std::string esphome::base64_encode (const uint8_t *buf, size_t buf_len)
 Format a float value with accuracy decimals to a string.
 
std::string esphome::base64_encode (const std::vector< uint8_t > &buf)
 Encode a byte vector to base64 string.
 
std::vector< uint8_t > esphome::base64_decode (const std::string &encoded_string)
 Decode a base64 string to a byte vector.
 
std::string esphome::get_mac_address ()
 Get the device MAC address as a string, in lowercase hex notation.
 
std::string esphome::get_mac_address_pretty ()
 Get the device MAC address as a string, in colon-separated uppercase hex notation.
 

Variables

std::string size_t esphome::len
 

Detailed Description

Heap-allocating helper functions.

These functions return std::string and allocate heap memory on every call. On long-running embedded devices, repeated heap allocations fragment memory over time, eventually causing crashes even with free memory available.

Prefer the stack-based alternatives documented on each function instead. New code should avoid using these functions.

Definition in file alloc_helpers.h.