Skip to content

Commit 9335115

Browse files
author
Takayuki 'January June' Suwa
committed
Clarify (the existence of) the constant empty String
instead of use of naked global symbol.
1 parent 8049543 commit 9335115

File tree

8 files changed

+28
-20
lines changed

8 files changed

+28
-20
lines changed

cores/esp8266/AddrList.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ struct netifWrapper
123123

124124
// common to all addresses of this interface
125125
String ifname () const { return String(_netif->name[0]) + _netif->name[1]; }
126-
const char* ifhostname () const { return _netif->hostname?: emptyString.c_str(); }
126+
const char* ifhostname () const { return _netif->hostname?: String::empty().c_str(); }
127127
const char* ifmac () const { return (const char*)_netif->hwaddr; }
128128
int ifnumber () const { return _netif->num; }
129129

cores/esp8266/WString.h

+9-1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ class String {
7070
explicit String(double, unsigned char decimalPlaces = 2);
7171
~String(void);
7272

73+
// empty string singleton
74+
// return the reference to the constant empty string.
75+
static inline const String &empty() {
76+
extern const String emptyString;
77+
return emptyString;
78+
}
79+
7380
// memory management
7481
// return true on success, false on failure (in which case, the string
7582
// is left unchanged). reserve(0), if successful, will validate an
@@ -294,7 +301,8 @@ class StringSumHelper: public String {
294301
}
295302
};
296303

297-
extern const String emptyString;
304+
// only for backward compatibility
305+
extern const String emptyString __attribute__((deprecated("Use String::empty() instead.")));
298306

299307
#endif // __cplusplus
300308
#endif // String_class_h

libraries/ESP8266HTTPUpdateServer/src/ESP8266HTTPUpdateServer.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ ESP8266HTTPUpdateServer::ESP8266HTTPUpdateServer(bool serial_debug)
2020
{
2121
_serial_output = serial_debug;
2222
_server = NULL;
23-
_username = emptyString;
24-
_password = emptyString;
23+
_username = String::empty();
24+
_password = String::empty();
2525
_authenticated = false;
2626
}
2727

@@ -33,7 +33,7 @@ void ESP8266HTTPUpdateServer::setup(ESP8266WebServer *server, const String& path
3333

3434
// handler for the /update form page
3535
_server->on(path.c_str(), HTTP_GET, [&](){
36-
if(_username != emptyString && _password != emptyString && !_server->authenticate(_username.c_str(), _password.c_str()))
36+
if(_username != String::empty() && _password != String::empty() && !_server->authenticate(_username.c_str(), _password.c_str()))
3737
return _server->requestAuthentication();
3838
_server->send_P(200, PSTR("text/html"), serverIndex);
3939
});
@@ -61,7 +61,7 @@ void ESP8266HTTPUpdateServer::setup(ESP8266WebServer *server, const String& path
6161
if (_serial_output)
6262
Serial.setDebugOutput(true);
6363

64-
_authenticated = (_username == emptyString || _password == emptyString || _server->authenticate(_username.c_str(), _password.c_str()));
64+
_authenticated = (_username == String::empty() || _password == String::empty() || _server->authenticate(_username.c_str(), _password.c_str()));
6565
if(!_authenticated){
6666
if (_serial_output)
6767
Serial.printf("Unauthenticated Update\n");

libraries/ESP8266HTTPUpdateServer/src/ESP8266HTTPUpdateServer.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ class ESP8266HTTPUpdateServer
1010

1111
void setup(ESP8266WebServer *server)
1212
{
13-
setup(server, emptyString, emptyString);
13+
setup(server, String::empty(), String::empty());
1414
}
1515

1616
void setup(ESP8266WebServer *server, const String& path)
1717
{
18-
setup(server, path, emptyString, emptyString);
18+
setup(server, path, String::empty(), String::empty());
1919
}
2020

2121
void setup(ESP8266WebServer *server, const String& username, const String& password)

libraries/ESP8266WebServer/src/ESP8266WebServer.cpp

+9-9
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ void ESP8266WebServer::begin(uint16_t port) {
108108
String ESP8266WebServer::_extractParam(String& authReq,const String& param,const char delimit) const {
109109
int _begin = authReq.indexOf(param);
110110
if (_begin == -1)
111-
return emptyString;
111+
return String::empty();
112112
return authReq.substring(_begin+param.length(),authReq.indexOf(delimit,_begin+param.length()));
113113
}
114114

@@ -486,7 +486,7 @@ void ESP8266WebServer::_streamFileCore(const size_t fileSize, const String & fil
486486
contentType != String(FPSTR(mimeTable[none].mimeType))) {
487487
sendHeader(F("Content-Encoding"), F("gzip"));
488488
}
489-
send(200, contentType, emptyString);
489+
send(200, contentType, String::empty());
490490
}
491491

492492

@@ -499,19 +499,19 @@ const String& ESP8266WebServer::arg(String name) const {
499499
if ( _currentArgs[i].key == name )
500500
return _currentArgs[i].value;
501501
}
502-
return emptyString;
502+
return String::empty();
503503
}
504504

505505
const String& ESP8266WebServer::arg(int i) const {
506506
if (i >= 0 && i < _currentArgCount)
507507
return _currentArgs[i].value;
508-
return emptyString;
508+
return String::empty();
509509
}
510510

511511
const String& ESP8266WebServer::argName(int i) const {
512512
if (i >= 0 && i < _currentArgCount)
513513
return _currentArgs[i].key;
514-
return emptyString;
514+
return String::empty();
515515
}
516516

517517
int ESP8266WebServer::args() const {
@@ -536,7 +536,7 @@ const String& ESP8266WebServer::header(String name) const {
536536
if (_currentHeaders[i].key.equalsIgnoreCase(name))
537537
return _currentHeaders[i].value;
538538
}
539-
return emptyString;
539+
return String::empty();
540540
}
541541

542542
void ESP8266WebServer::collectHeaders(const char* headerKeys[], const size_t headerKeysCount) {
@@ -553,13 +553,13 @@ void ESP8266WebServer::collectHeaders(const char* headerKeys[], const size_t hea
553553
const String& ESP8266WebServer::header(int i) const {
554554
if (i < _headerKeysCount)
555555
return _currentHeaders[i].value;
556-
return emptyString;
556+
return String::empty();
557557
}
558558

559559
const String& ESP8266WebServer::headerName(int i) const {
560560
if (i < _headerKeysCount)
561561
return _currentHeaders[i].key;
562-
return emptyString;
562+
return String::empty();
563563
}
564564

565565
int ESP8266WebServer::headers() const {
@@ -619,7 +619,7 @@ void ESP8266WebServer::_handleRequest() {
619619

620620
void ESP8266WebServer::_finalizeResponse() {
621621
if (_chunked) {
622-
sendContent(emptyString);
622+
sendContent(String::empty());
623623
}
624624
}
625625

libraries/ESP8266WiFi/examples/IPv6/IPv6.ino

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ void setup() {
9898
Serial.println();
9999
Serial.println(ESP.getFullVersion());
100100

101-
Serial.printf("IPV6 is%s enabled\n", LWIP_IPV6 ? emptyString.c_str() : " NOT");
101+
Serial.printf("IPV6 is%s enabled\n", LWIP_IPV6 ? String::empty().c_str() : " NOT");
102102

103103
WiFi.mode(WIFI_STA);
104104
WiFi.begin(STASSID, STAPSK);

libraries/ESP8266WiFi/src/ESP8266WiFiAP.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class ESP8266WiFiAPClass {
3737
public:
3838

3939
bool softAP(const char* ssid, const char* passphrase = NULL, int channel = 1, int ssid_hidden = 0, int max_connection = 4);
40-
bool softAP(const String& ssid,const String& passphrase = emptyString,int channel = 1,int ssid_hidden = 0,int max_connection = 4);
40+
bool softAP(const String& ssid,const String& passphrase = String::empty(),int channel = 1,int ssid_hidden = 0,int max_connection = 4);
4141
bool softAPConfig(IPAddress local_ip, IPAddress gateway, IPAddress subnet);
4242
bool softAPdisconnect(bool wifioff = false);
4343

libraries/ESP8266WiFi/src/ESP8266WiFiSTA.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class ESP8266WiFiSTAClass {
3838

3939
wl_status_t begin(const char* ssid, const char *passphrase = NULL, int32_t channel = 0, const uint8_t* bssid = NULL, bool connect = true);
4040
wl_status_t begin(char* ssid, char *passphrase = NULL, int32_t channel = 0, const uint8_t* bssid = NULL, bool connect = true);
41-
wl_status_t begin(const String& ssid, const String& passphrase = emptyString, int32_t channel = 0, const uint8_t* bssid = NULL, bool connect = true);
41+
wl_status_t begin(const String& ssid, const String& passphrase = String::empty(), int32_t channel = 0, const uint8_t* bssid = NULL, bool connect = true);
4242
wl_status_t begin();
4343

4444
//The argument order for ESP is not the same as for Arduino. However, there is compatibility code under the hood

0 commit comments

Comments
 (0)