mirror of
https://github.com/esphome/esphome.git
synced 2025-01-18 12:05:41 +00:00
parent
a37ff2dbd9
commit
d00ec7e544
@ -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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user