From e1e20422a65666819f591d21f5bbd29a0c26a5ef Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 21 Feb 2026 21:47:03 -0600 Subject: [PATCH] deferred --- esphome/core/string_ref.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/esphome/core/string_ref.h b/esphome/core/string_ref.h index d502c4d27f..89ea9dd797 100644 --- a/esphome/core/string_ref.h +++ b/esphome/core/string_ref.h @@ -81,6 +81,19 @@ class StringRef { operator std::string() const { return str(); } + /// Compare with a null-terminated C string (compatible with std::string::compare) + int compare(const char *s) const { + size_t s_len = std::strlen(s); + int result = std::memcmp(base_, s, std::min(len_, s_len)); + if (result != 0) + return result; + if (len_ < s_len) + return -1; + if (len_ > s_len) + return 1; + return 0; + } + /// Find first occurrence of substring, returns std::string::npos if not found. /// Note: Requires the underlying string to be null-terminated. size_type find(const char *s, size_type pos = 0) const {