From 1dc4a5432f54e9beaf41c9d2ac6f02b17b845ea2 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 17 Jan 2026 10:55:48 -1000 Subject: [PATCH] adl --- esphome/core/string_ref.h | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/esphome/core/string_ref.h b/esphome/core/string_ref.h index c5ee64941e..d5d2897e82 100644 --- a/esphome/core/string_ref.h +++ b/esphome/core/string_ref.h @@ -186,8 +186,8 @@ inline std::string operator+(const std::string &lhs, const StringRef &rhs) { return str; } // String conversion functions for ADL compatibility (allows stoi(x) where x is StringRef) -// Uses strtol/strtod directly to avoid heap allocation -// NOLINTBEGIN(readability-identifier-naming) +// Must be in esphome namespace for ADL to find them. Uses strtol/strtod directly to avoid heap allocation. +namespace internal { template inline R parse_number(const StringRef &str, size_t *pos, F conv) { char *end; R result = conv(str.c_str(), &end); @@ -202,14 +202,20 @@ template inline R parse_number(const StringRef &str, siz *pos = static_cast(end - str.c_str()); return result; } +} // namespace internal +// NOLINTBEGIN(readability-identifier-naming) inline int stoi(const StringRef &str, size_t *pos = nullptr, int base = 10) { - return static_cast(parse_number(str, pos, base, std::strtol)); + return static_cast(internal::parse_number(str, pos, base, std::strtol)); } inline long stol(const StringRef &str, size_t *pos = nullptr, int base = 10) { - return parse_number(str, pos, base, std::strtol); + return internal::parse_number(str, pos, base, std::strtol); +} +inline float stof(const StringRef &str, size_t *pos = nullptr) { + return internal::parse_number(str, pos, std::strtof); +} +inline double stod(const StringRef &str, size_t *pos = nullptr) { + return internal::parse_number(str, pos, std::strtod); } -inline float stof(const StringRef &str, size_t *pos = nullptr) { return parse_number(str, pos, std::strtof); } -inline double stod(const StringRef &str, size_t *pos = nullptr) { return parse_number(str, pos, std::strtod); } // NOLINTEND(readability-identifier-naming) #ifdef USE_JSON