use std::from_chars to parse port

This commit is contained in:
orignal committed 2026-10-05 21:20:22 -04:00
1 parent 8b9efd08c1
commit c49af510fe
1 file changed
+5 -7
+5 -7
View File
@@ -160,14 +160,12 @@ namespace http
std::string_view port_str = (pos_c == std::string::npos)
? url.substr(pos_p, std::string::npos)
: url.substr(pos_p, pos_c - pos_p);
/* stoi throws exception on failure, we don't need it */
port = 0;
for (char c : port_str) {
if (c < '0' || c > '9')
return false;
port *= 10;
port += c - '0';
}
auto res = std::from_chars (port_str.data(), port_str.data() + port_str.size(), port);
if (res.ec != std::errc())
return false;
if (pos_c == std::string::npos)
return true; /* no path part */
pos_p = pos_c;