Skip to content

Commit 5ebaf16

Browse files
Use strchr instead of counting spaces in a loop (#105)
1 parent e4946b9 commit 5ebaf16

1 file changed

Lines changed: 7 additions & 15 deletions

File tree

src/ESP32_VS1053_Stream.cpp

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -275,30 +275,22 @@ bool ESP32_VS1053_Stream::connectToHost(const char *url, const char *username,
275275
return false;
276276
}
277277

278-
bool needsEscape = false;
279-
for (size_t i = 0; i < length; ++i)
278+
_http = new HTTPClient;
279+
if (!_http)
280280
{
281-
if (url[i] == ' ')
282-
{
283-
needsEscape = true;
284-
break;
285-
}
281+
log_e("Could not create http client");
282+
return false;
286283
}
287284

285+
const bool needsEscape = (strchr(url, ' ') != nullptr);
286+
288287
if (needsEscape && !_escapeUrl(url, length))
289288
{
290289
log_e("Escaped URL exceeds buffer");
291290
return false;
292291
}
293292

294-
_http = new HTTPClient;
295-
if (!_http)
296-
{
297-
log_e("Could not create http client");
298-
return false;
299-
}
300-
301-
bool isHttps = (length > 4 && tolower(url[4]) == 's');
293+
const bool isHttps = (length > 4 && tolower(url[4]) == 's');
302294

303295
_http->setConnectTimeout(isHttps ? VS1053_CONNECT_TIMEOUT_MS_SSL
304296
: VS1053_CONNECT_TIMEOUT_MS);

0 commit comments

Comments
 (0)