/** * Implementation of AutoConnectElementBasis classes. * @file AutoConnectElementImpl.h * @author hieromon@gmail.com * @version 0.9.11 * @date 2019-06-25 * @copyright MIT license. */ #ifndef _AUTOCONNECTELEMENTBASISIMPL_H_ #define _AUTOCONNECTELEMENTBASISIMPL_H_ #include #include #if defined(ARDUINO_ARCH_ESP8266) #include #elif defined(ARDUINO_ARCH_ESP32) #include #endif #include "AutoConnectElementBasis.h" /** * Append post-tag accoring by the post attribute. * @param s An original string * @return A string that appended the post tag */ const String AutoConnectElementBasis::posterior(const String& s) const { String html; if (post == AC_Tag_BR) html = s + String(F("
")); else if (post == AC_Tag_P) html = String("

") + s + String(F("

")); else html = s; return html; } /** * Generate an HTML ")); html = AutoConnectElementBasis::posterior(html); } return html; } /** * Generate an HTML element. * A "value" is associated with the input tag and sent by the form * action as the value of "name". If the label member is contained, it * is placed to the right side of the checkbox to be labeled. * f the label member is empty, only the checkbox is placed. * @return An HTML string. */ const String AutoConnectCheckboxBasis::toHTML(void) const { String html = String(""); if (enable) { html = String(F(""); if (label.length()) { String labelTag = String(F("")); if (labelPosition == AC_Infront) html = labelTag + html; else if (labelPosition == AC_Behind) html += labelTag; } html = AutoConnectElementBasis::posterior(html); } return html; } /** * Generate an HTML element. * The entered value can be obtained using the user callback function * registered by AutoConnectAux::on after the form is sent in * combination with AutoConnectSubmit. * @return String an HTML string. */ const String AutoConnectFileBasis::toHTML(void) const { String html = String(""); if (enable) { if (label.length()) html = String(F("")); html += String(F(""); html = AutoConnectElementBasis::posterior(html); } return html; } /** * Instantiate the upload handler with the specified store type. * @param store An enumeration value of ACFile_t */ bool AutoConnectFileBasis::attach(const ACFile_t store) { AutoConnectUploadFS* handlerFS; AutoConnectUploadSD* handlerSD; // Release previous handler detach(); // Classify a handler type and create the corresponding handler switch (store) { case AC_File_FS: handlerFS = new AutoConnectUploadFS(SPIFFS); _upload.reset(reinterpret_cast(handlerFS)); break; case AC_File_SD: handlerSD = new AutoConnectUploadSD(SD); _upload.reset(reinterpret_cast(handlerSD)); break; case AC_File_Extern: break; } return _upload != false; } /** * Generate an HTML element. * If the value member is contained, it is reflected in the placeholder * attribute. The entered value can be obtained using the user callback * function registered by AutoConnectAux::on after the form is sent in * combination with AutoConnectSubmit. * @return String an HTML string. */ const String AutoConnectInputBasis::toHTML(void) const { String html = String(""); if (enable) { if (label.length()) html = String(F("")); html += String(F(""); html = AutoConnectElementBasis::posterior(html); } return html; } /** * Evaluate the pattern as a regexp and return whether value matches. * Always return true if the pattern is undefined. * @return true The value matches a pattern. * @return false The value does not match a pattern. */ bool AutoConnectInputBasis::isValid(void) const { bool rc = true; if (pattern.length()) { #if defined(ARDUINO_ARCH_ESP8266) regex_t preg; if (regcomp(&preg, pattern.c_str(), REG_EXTENDED) != 0) { AC_DBG("%s regex compile failed\n", pattern.c_str()); rc = false; } else { regmatch_t p_match[1]; rc = regexec(&preg, value.c_str(), 1, p_match, 0) == 0 ? true : false; regfree(&preg); } #elif defined(ARDUINO_ARCH_ESP32) const std::regex re(pattern.c_str()); rc = std::regex_match(value.c_str(), re); #endif } return rc; } /** * Indicate an entry with the specified value in the value's collection. * @param value The value to indicates in the collection. */ void AutoConnectRadioBasis::check(const String& value) { for (std::size_t n = 0; n < _values.size(); n++) { if (at(n).equalsIgnoreCase(value)) { checked = n + 1; break; } } } /** * Clear value items of AutoConnectRadio and reallocate new storage. * All hold items are released. * @param reserve If 'reserve' is greater than 0, this function * allocates new holding storage with the value. */ void AutoConnectRadioBasis::empty(const size_t reserve) { _values.clear(); std::vector().swap(_values); if (reserve) _values.reserve(reserve); checked = 0; } /** * Generate an HTML element with an