mirror of
https://github.com/esphome/esphome.git
synced 2026-02-18 15:35:59 -07:00
[core] Avoid heap allocation in str_equals_case_insensitive with string literals (#13312)
This commit is contained in:
@@ -572,6 +572,10 @@ template<typename T> constexpr T convert_little_endian(T val) {
|
||||
bool str_equals_case_insensitive(const std::string &a, const std::string &b);
|
||||
/// Compare StringRefs for equality in case-insensitive manner.
|
||||
bool str_equals_case_insensitive(StringRef a, StringRef b);
|
||||
/// Compare C strings for equality in case-insensitive manner (no heap allocation).
|
||||
inline bool str_equals_case_insensitive(const char *a, const char *b) { return strcasecmp(a, b) == 0; }
|
||||
inline bool str_equals_case_insensitive(const std::string &a, const char *b) { return strcasecmp(a.c_str(), b) == 0; }
|
||||
inline bool str_equals_case_insensitive(const char *a, const std::string &b) { return strcasecmp(a, b.c_str()) == 0; }
|
||||
|
||||
/// Check whether a string starts with a value.
|
||||
bool str_startswith(const std::string &str, const std::string &start);
|
||||
|
||||
Reference in New Issue
Block a user