diff --git a/esphome/core/string_ref.h b/esphome/core/string_ref.h index 5febb75d96e..35d04dab0a4 100644 --- a/esphome/core/string_ref.h +++ b/esphome/core/string_ref.h @@ -81,26 +81,26 @@ class StringRef { operator std::string() const { return str(); } - /// Find first occurrence of substring, returns npos if not found - static constexpr size_type npos = static_cast(-1); + /// Find first occurrence of substring, returns NPOS if not found + static constexpr size_type NPOS = static_cast(-1); size_type find(const char *s, size_type pos = 0) const { if (pos >= len_) - return npos; + return NPOS; const char *result = std::strstr(base_ + pos, s); - return result ? static_cast(result - base_) : npos; + return result ? static_cast(result - base_) : NPOS; } size_type find(char c, size_type pos = 0) const { if (pos >= len_) - return npos; + return NPOS; const char *result = std::strchr(base_ + pos, c); - return (result && result < base_ + len_) ? static_cast(result - base_) : npos; + return (result && result < base_ + len_) ? static_cast(result - base_) : NPOS; } /// Return substring as std::string - std::string substr(size_type pos = 0, size_type count = npos) const { + std::string substr(size_type pos = 0, size_type count = NPOS) const { if (pos >= len_) return std::string(); - size_type actual_count = (count == npos || pos + count > len_) ? len_ - pos : count; + size_type actual_count = (count == NPOS || pos + count > len_) ? len_ - pos : count; return std::string(base_ + pos, actual_count); }