1
0
mirror of https://github.com/esphome/esphome.git synced 2025-01-18 12:05:41 +00:00

[helpers] clang-tidy fix for #7706 (#7909)

This commit is contained in:
Keith Burzinski 2024-12-03 17:23:17 -06:00 committed by GitHub
parent a37ff2dbd9
commit d00ec7e544
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -259,10 +259,15 @@ bool random_bytes(uint8_t *data, size_t len) {
bool str_equals_case_insensitive(const std::string &a, const std::string &b) {
return strcasecmp(a.c_str(), b.c_str()) == 0;
}
#if ESP_IDF_VERSION_MAJOR >= 5
bool str_startswith(const std::string &str, const std::string &start) { return str.starts_with(start); }
bool str_endswith(const std::string &str, const std::string &end) { return str.ends_with(end); }
#else
bool str_startswith(const std::string &str, const std::string &start) { return str.rfind(start, 0) == 0; }
bool str_endswith(const std::string &str, const std::string &end) {
return str.rfind(end) == (str.size() - end.size());
}
#endif
std::string str_truncate(const std::string &str, size_t length) {
return str.length() > length ? str.substr(0, length) : str;
}