Skip to content

Commit

Permalink
Various String handling cleanups
Browse files Browse the repository at this point in the history
Use the proper api (::clear(), isEmpty()) instead of doing
comparisons/assignments of empty strings. Also fix mixture
of tabs and spaces in the source code.
  • Loading branch information
dirkmueller committed Dec 26, 2019
1 parent 6c2ab25 commit 8e7a78c
Show file tree
Hide file tree
Showing 11 changed files with 108 additions and 108 deletions.
162 changes: 81 additions & 81 deletions cores/esp8266/WString.cpp

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion doc/PROGMEM.rst
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ constructor:

.. code:: cpp
String(const char *cstr = ""); // constructor from const char *
String(const char *cstr = nullptr); // constructor from const char *
String(const String &str); // copy constructor
String(const __FlashStringHelper *str); // constructor for flash strings
Expand Down
2 changes: 1 addition & 1 deletion libraries/ArduinoOTA/ArduinoOTA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ int ArduinoOTAClass::parseInt(){
}

String ArduinoOTAClass::readStringUntil(char end){
String res = "";
String res;
int value;
while(true){
value = _udp_ota->read();
Expand Down
2 changes: 1 addition & 1 deletion libraries/DNSServer/src/DNSServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ void DNSServer::respondToRequest(uint8_t *buffer, size_t length)
query, queryLength);

// If we have no domain name configured, just return an error
if (_domainName == "")
if (_domainName.isEmpty())
return replyWithError(dnsHeader, _errorReplyCode,
query, queryLength);

Expand Down
6 changes: 3 additions & 3 deletions libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ void HTTPClient::clear()
{
_returnCode = 0;
_size = -1;
_headers = "";
_headers.clear();
_location.clear();
_payload.reset();
_location = "";
}


Expand Down Expand Up @@ -657,7 +657,7 @@ int HTTPClient::sendRequest(const char * type, const uint8_t * payload, size_t s
// wipe out any existing headers from previous request
for(size_t i = 0; i < _headerKeysCount; i++) {
if (_currentHeaders[i].value.length() > 0) {
_currentHeaders[i].value = "";
_currentHeaders[i].value.clear();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ void ESP8266HTTPUpdateServerTemplate<ServerType>::setup(ESP8266WebServerTemplate
HTTPUpload& upload = _server->upload();

if(upload.status == UPLOAD_FILE_START){
_updaterError = String();
_updaterError.clear();
if (_serial_output)
Serial.setDebugOutput(true);

Expand Down
12 changes: 6 additions & 6 deletions libraries/ESP8266WebServer/examples/FSBrowser/FSBrowser.ino
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ void handleFileUpload() {
}
DBG_OUTPUT_PORT.print("handleFileUpload Name: "); DBG_OUTPUT_PORT.println(filename);
fsUploadFile = filesystem->open(filename, "w");
filename = String();
filename.clear();
} else if (upload.status == UPLOAD_FILE_WRITE) {
//DBG_OUTPUT_PORT.print("handleFileUpload Data: "); DBG_OUTPUT_PORT.println(upload.currentSize);
if (fsUploadFile) {
Expand Down Expand Up @@ -150,7 +150,7 @@ void handleFileDelete() {
}
filesystem->remove(path);
server.send(200, "text/plain", "");
path = String();
path.clear();
}

void handleFileCreate() {
Expand All @@ -172,7 +172,7 @@ void handleFileCreate() {
return server.send(500, "text/plain", "CREATE FAILED");
}
server.send(200, "text/plain", "");
path = String();
path.clear();
}

void handleFileList() {
Expand All @@ -184,7 +184,7 @@ void handleFileList() {
String path = server.arg("dir");
DBG_OUTPUT_PORT.println("handleFileList: " + path);
Dir dir = filesystem->openDir(path);
path = String();
path.clear();

String output = "[";
while (dir.next()) {
Expand Down Expand Up @@ -275,13 +275,13 @@ void setup(void) {

//get heap status, analog input value and all GPIO statuses in one json call
server.on("/all", HTTP_GET, []() {
String json = "{";
String json('{');
json += "\"heap\":" + String(ESP.getFreeHeap());
json += ", \"analog\":" + String(analogRead(A0));
json += ", \"gpio\":" + String((uint32_t)(((GPI | GPO) & 0xFFFF) | ((GP16I & 0x01) << 16)));
json += "}";
server.send(200, "text/json", json);
json = String();
json.clear();
});
server.begin();
DBG_OUTPUT_PORT.println("HTTP server started");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ void printDirectory() {
return returnFail("BAD PATH");
}
File dir = SD.open((char *)path.c_str());
path = String();
path.clear();
if (!dir.isDirectory()) {
dir.close();
return returnFail("NOT DIR");
Expand Down
10 changes: 5 additions & 5 deletions libraries/ESP8266WebServer/src/Parsing-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ bool ESP8266WebServerTemplate<ServerType>::_parseRequest(ClientType& client) {
String url = req.substring(addr_start + 1, addr_end);
String versionEnd = req.substring(addr_end + 8);
_currentVersion = atoi(versionEnd.c_str());
String searchStr = "";
String searchStr;
int hasSearch = url.indexOf('?');
if (hasSearch != -1){
searchStr = url.substring(hasSearch + 1);
Expand Down Expand Up @@ -144,7 +144,7 @@ bool ESP8266WebServerTemplate<ServerType>::_parseRequest(ClientType& client) {
while(1){
req = client.readStringUntil('\r');
client.readStringUntil('\n');
if (req == "") break;//no moar headers
if (req.isEmpty()) break;//no moar headers
int headerDiv = req.indexOf(':');
if (headerDiv == -1){
break;
Expand Down Expand Up @@ -222,7 +222,7 @@ bool ESP8266WebServerTemplate<ServerType>::_parseRequest(ClientType& client) {
while(1){
req = client.readStringUntil('\r');
client.readStringUntil('\n');
if (req == "") break;//no moar headers
if (req.isEmpty()) break;//no moar headers
int headerDiv = req.indexOf(':');
if (headerDiv == -1){
break;
Expand Down Expand Up @@ -452,7 +452,7 @@ bool ESP8266WebServerTemplate<ServerType>::_parseForm(ClientType& client, const
line = client.readStringUntil('\r');
client.readStringUntil('\n');
if (line.startsWith("--"+boundary)) break;
if (argValue.length() > 0) argValue += "\n";
if (argValue.length() > 0) argValue += '\n';
argValue += line;
}
#ifdef DEBUG_ESP_HTTP_SERVER
Expand Down Expand Up @@ -600,7 +600,7 @@ bool ESP8266WebServerTemplate<ServerType>::_parseForm(ClientType& client, const
template <typename ServerType>
String ESP8266WebServerTemplate<ServerType>::urlDecode(const String& text)
{
String decoded = "";
String decoded;
char temp[] = "0x00";
unsigned int len = text.length();
unsigned int i = 0;
Expand Down
14 changes: 7 additions & 7 deletions libraries/ESP8266WiFiMesh/src/ESP8266WiFiMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
const IPAddress ESP8266WiFiMesh::emptyIP = IPAddress();
const uint32_t ESP8266WiFiMesh::lwipVersion203Signature[3] {2,0,3};

String ESP8266WiFiMesh::lastSSID = "";
String ESP8266WiFiMesh::lastSSID;
bool ESP8266WiFiMesh::staticIPActivated = false;

// IP needs to be at the same subnet as server gateway (192.168.4 in this case). Station gateway ip must match ip for server.
Expand All @@ -55,7 +55,7 @@ ESP8266WiFiMesh::ESP8266WiFiMesh(ESP8266WiFiMesh::requestHandlerType requestHand
{
storeLwipVersion();

updateNetworkNames(meshName, (nodeID != "" ? nodeID : uint64ToString(ESP.getChipId())));
updateNetworkNames(meshName, (!nodeID.isEmpty() ? nodeID : uint64ToString(ESP.getChipId())));
_requestHandler = requestHandler;
_responseHandler = responseHandler;
setWiFiChannel(meshWiFiChannel);
Expand All @@ -67,9 +67,9 @@ ESP8266WiFiMesh::ESP8266WiFiMesh(ESP8266WiFiMesh::requestHandlerType requestHand

void ESP8266WiFiMesh::updateNetworkNames(const String &newMeshName, const String &newNodeID)
{
if(newMeshName != "")
if(!newMeshName.isEmpty())
_meshName = newMeshName;
if(newNodeID != "")
if(!newNodeID.isEmpty())
_nodeID = newNodeID;

String newSSID = _meshName + _nodeID;
Expand Down Expand Up @@ -453,7 +453,7 @@ void ESP8266WiFiMesh::initiateConnectionToAP(const String &targetSSID, int targe
*/
transmission_status_t ESP8266WiFiMesh::connectToNode(const String &targetSSID, int targetChannel, uint8_t *targetBSSID)
{
if(staticIPActivated && lastSSID != "" && lastSSID != targetSSID) // So we only do this once per connection, in case there is a performance impact.
if(staticIPActivated && !lastSSID.isEmpty() && lastSSID != targetSSID) // So we only do this once per connection, in case there is a performance impact.
{
#ifdef ENABLE_STATIC_IP_OPTIMIZATION
if(atLeastLwipVersion(lwipVersion203Signature))
Expand Down Expand Up @@ -562,12 +562,12 @@ void ESP8266WiFiMesh::attemptTransmission(const String &message, bool concluding
WiFi.disconnect();
yield();

String currentSSID = "";
String currentSSID;
int currentWiFiChannel = NETWORK_INFO_DEFAULT_INT;
uint8_t *currentBSSID = NULL;

// If an SSID has been assigned, it is prioritized over an assigned networkIndex since the networkIndex is more likely to change.
if(currentNetwork.SSID != "")
if(!currentNetwork.SSID.isEmpty())
{
currentSSID = currentNetwork.SSID;
currentWiFiChannel = currentNetwork.wifiChannel;
Expand Down
2 changes: 1 addition & 1 deletion tests/device/test_WiFi_events/test_WiFi_events.ino
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ TEST_CASE("STA mode events are called both when using DHCP and static config", "
delay(100);

REQUIRE(events == "connected,got_ip,disconnected,");
events = String();
events.clear();

// now run the same with static IP config saved above

Expand Down

0 comments on commit 8e7a78c

Please sign in to comment.