mirror of
https://github.com/esphome/esphome.git
synced 2026-10-19 04:32:50 +00:00
[core] Add ESPHOME_strstr_P (#20811)
This commit is contained in:
@@ -26,6 +26,7 @@
|
||||
#define ESPHOME_strncmp_P strncmp_P
|
||||
#define ESPHOME_strncasecmp_P strncasecmp_P
|
||||
#define ESPHOME_strlen_P strlen_P
|
||||
#define ESPHOME_strstr_P strstr_P
|
||||
// Type for pointers to PROGMEM strings (for use with ESPHOME_F return values)
|
||||
using ProgmemStr = const __FlashStringHelper *;
|
||||
// Storage class for PROGMEM_STRING_TABLE data; LOG_STR_ARG treats a LogString as PGM_P
|
||||
@@ -43,6 +44,7 @@ using ProgmemStr = const __FlashStringHelper *;
|
||||
#define ESPHOME_strncmp_P strncmp
|
||||
#define ESPHOME_strncasecmp_P strncasecmp
|
||||
#define ESPHOME_strlen_P strlen
|
||||
#define ESPHOME_strstr_P strstr
|
||||
// Type for pointers to strings (no PROGMEM on non-ESP8266 platforms)
|
||||
using ProgmemStr = const char *;
|
||||
// No-op on non-ESP8266 platforms where PROGMEM itself is a no-op.
|
||||
|
||||
@@ -62,4 +62,12 @@ TEST(ProgmemStringTable, LargeTableIsScanned) {
|
||||
"3123456789012345678901234567890123456789");
|
||||
}
|
||||
|
||||
TEST(ProgmemStringTable, StrstrFindsTableEntryInRamString) {
|
||||
const char *line = "MODE HEAT ON";
|
||||
const auto *heat = reinterpret_cast<ESPHOME_PGM_P>(SmallStrings::get_progmem_str(1, SmallStrings::LAST_INDEX));
|
||||
const auto *cool = reinterpret_cast<ESPHOME_PGM_P>(SmallStrings::get_progmem_str(2, SmallStrings::LAST_INDEX));
|
||||
EXPECT_EQ(ESPHOME_strstr_P(line, heat), line + 5);
|
||||
EXPECT_EQ(ESPHOME_strstr_P(line, cool), nullptr);
|
||||
}
|
||||
|
||||
} // namespace esphome::core::testing
|
||||
|
||||
Reference in New Issue
Block a user