mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 15:59:52 +03:00
remove flash
This commit is contained in:
@@ -608,7 +608,7 @@ bool Helpers::value2bool(const char * value, bool & value_b) {
|
||||
|
||||
// checks to see if a string is member of a vector and return the index, also allow true/false for on/off
|
||||
// this for a list of lists, when using translated strings
|
||||
bool Helpers::value2enum(const char * value, uint8_t & value_ui, const __FlashStringHelper * const ** strs) {
|
||||
bool Helpers::value2enum(const char * value, uint8_t & value_ui, const char * const ** strs) {
|
||||
if ((value == nullptr) || (strlen(value) == 0)) {
|
||||
return false;
|
||||
}
|
||||
@@ -616,7 +616,7 @@ bool Helpers::value2enum(const char * value, uint8_t & value_ui, const __FlashSt
|
||||
|
||||
for (value_ui = 0; strs[value_ui]; value_ui++) {
|
||||
std::string str1 = toLower(Helpers::translated_word(strs[value_ui]));
|
||||
std::string str2 = toLower(read_flash_string(strs[value_ui][0])); // also check for default language
|
||||
std::string str2 = toLower((strs[value_ui][0])); // also check for default language
|
||||
if ((str1 != "")
|
||||
&& ((str2 == "off" && str == "false") || (str2 == "on" && str == "true") || (str == str1) || (str == str2)
|
||||
|| (value[0] == ('0' + value_ui) && value[1] == '\0'))) {
|
||||
@@ -628,14 +628,14 @@ bool Helpers::value2enum(const char * value, uint8_t & value_ui, const __FlashSt
|
||||
}
|
||||
|
||||
// checks to see if a string is member of a vector and return the index, also allow true/false for on/off
|
||||
bool Helpers::value2enum(const char * value, uint8_t & value_ui, const __FlashStringHelper * const * strs) {
|
||||
bool Helpers::value2enum(const char * value, uint8_t & value_ui, const char * const * strs) {
|
||||
if ((value == nullptr) || (strlen(value) == 0)) {
|
||||
return false;
|
||||
}
|
||||
std::string str = toLower(value);
|
||||
|
||||
for (value_ui = 0; strs[value_ui]; value_ui++) {
|
||||
std::string enum_str = toLower(read_flash_string(strs[value_ui]));
|
||||
std::string enum_str = toLower((strs[value_ui]));
|
||||
|
||||
if ((enum_str != "")
|
||||
&& ((enum_str == "off" && (str == Helpers::translated_word(FL_(off)) || str == "false"))
|
||||
@@ -655,6 +655,23 @@ std::string Helpers::toLower(std::string const & s) {
|
||||
return lc;
|
||||
}
|
||||
|
||||
|
||||
// TODO fix toLower
|
||||
std::string Helpers::toLower(const char * s) {
|
||||
std::string lc = s;
|
||||
std::transform(lc.begin(), lc.end(), lc.begin(), [](unsigned char c) { return std::tolower(c); });
|
||||
return lc;
|
||||
|
||||
/*
|
||||
|
||||
for (; *s; ++s) {
|
||||
*p = tolower(*s);
|
||||
p++;
|
||||
}
|
||||
|
||||
*/
|
||||
}
|
||||
|
||||
std::string Helpers::toUpper(std::string const & s) {
|
||||
std::string lc = s;
|
||||
std::transform(lc.begin(), lc.end(), lc.begin(), [](unsigned char c) { return std::toupper(c); });
|
||||
@@ -676,7 +693,7 @@ void Helpers::replace_char(char * str, char find, char replace) {
|
||||
|
||||
// count number of items in a list
|
||||
// the end of a list has a nullptr
|
||||
uint8_t Helpers::count_items(const __FlashStringHelper * const * list) {
|
||||
uint8_t Helpers::count_items(const char * const * list) {
|
||||
uint8_t list_size = 0;
|
||||
if (list != nullptr) {
|
||||
while (list[list_size]) {
|
||||
@@ -688,7 +705,7 @@ uint8_t Helpers::count_items(const __FlashStringHelper * const * list) {
|
||||
|
||||
// count number of items in a list of lists
|
||||
// the end of a list has a nullptr
|
||||
uint8_t Helpers::count_items(const __FlashStringHelper * const ** list) {
|
||||
uint8_t Helpers::count_items(const char * const ** list) {
|
||||
uint8_t list_size = 0;
|
||||
if (list != nullptr) {
|
||||
while (list[list_size]) {
|
||||
@@ -699,29 +716,15 @@ uint8_t Helpers::count_items(const __FlashStringHelper * const ** list) {
|
||||
}
|
||||
|
||||
// return translated string as a std::string, optionally converting to lowercase (for console commands)
|
||||
// takes a FL(...)
|
||||
std::string Helpers::translated_word(const __FlashStringHelper * const * strings, bool to_lower) {
|
||||
std::string Helpers::translated_word(const char * const * strings, bool to_lower) {
|
||||
uint8_t language_index = EMSESP::system_.language_index();
|
||||
uint8_t index = 0;
|
||||
|
||||
// see how many translations we have for this entity. if there is no translation for this, revert to EN
|
||||
if (Helpers::count_items(strings) >= language_index + 1 && !read_flash_string(strings[language_index]).empty()) {
|
||||
if (Helpers::count_items(strings) >= language_index + 1 && strlen(strings[language_index])) {
|
||||
index = language_index;
|
||||
}
|
||||
return to_lower ? toLower(read_flash_string(strings[index])) : read_flash_string(strings[index]);
|
||||
}
|
||||
|
||||
// return translated string
|
||||
// takes a F(...)
|
||||
const __FlashStringHelper * Helpers::translated_fword(const __FlashStringHelper * const * strings) {
|
||||
uint8_t language_index = EMSESP::system_.language_index();
|
||||
uint8_t index = 0;
|
||||
|
||||
// see how many translations we have for this entity. if there is no translation for this, revert to EN
|
||||
if (Helpers::count_items(strings) >= language_index + 1 && !read_flash_string(strings[language_index]).empty()) {
|
||||
index = language_index;
|
||||
}
|
||||
return strings[index];
|
||||
return to_lower ? toLower((strings[index])) : (strings[index]);
|
||||
}
|
||||
|
||||
} // namespace emsesp
|
||||
|
||||
Reference in New Issue
Block a user