Shrink HtmlEscape code size

Shrink HtmlEscape code size by 200 bytes
This commit is contained in:
Theo Arends 2019-05-27 14:09:33 +02:00
parent 22663fc10c
commit 0c2d1323e7
1 changed files with 18 additions and 10 deletions

View File

@ -1294,15 +1294,23 @@ void ModuleSaveSettings(void)
/*-------------------------------------------------------------------------------------------*/
String htmlEscape(String s)
{
s.replace("&", "&");
s.replace("<", "&lt;");
s.replace(">", "&gt;");
s.replace("\"", "&quot;");
s.replace("'", "&#x27;");
s.replace("/", "&#x2F;");
return s;
const char kUnescapeCode[] = "&><\"\'";
const char kEscapeCode[] PROGMEM = "&amp;|&gt;|&lt;|&quot;|&apos;";
String HtmlEscape(const String unescaped) {
char escaped[10];
uint16_t ulen = unescaped.length();
String result = "";
for (size_t i = 0; i < ulen; i++) {
char c = unescaped[i];
char *p = strchr(kUnescapeCode, c);
if (p != nullptr) {
result += GetTextIndexed(escaped, sizeof(escaped), p - kUnescapeCode, kEscapeCode);
} else {
result += c;
}
}
return result;
}
void HandleWifiConfiguration(void)
@ -1373,7 +1381,7 @@ void HandleWifiConfiguration(void)
if (minimum_signal_quality == -1 || minimum_signal_quality < quality) {
uint8_t auth = WiFi.encryptionType(indices[i]);
WSContentSend_P(PSTR("<div><a href='#p' onclick='c(this)'>%s</a>&nbsp;(%d)&nbsp<span class='q'>%s %d%%</span></div>"),
htmlEscape(WiFi.SSID(indices[i])).c_str(),
HtmlEscape(WiFi.SSID(indices[i])).c_str(),
WiFi.channel(indices[i]),
(ENC_TYPE_WEP == auth) ? D_WEP : (ENC_TYPE_TKIP == auth) ? D_WPA_PSK : (ENC_TYPE_CCMP == auth) ? D_WPA2_PSK : (ENC_TYPE_AUTO == auth) ? D_AUTO : "",
quality