From c872a712bcb15321ad0351efd81b788cd2540027 Mon Sep 17 00:00:00 2001 From: Volodymyr Kolesnykov Date: Tue, 19 Nov 2024 16:53:28 +0200 Subject: [PATCH] fix: apply suggestions from code review comments --- .../ext/http/common/url_parser.h | 47 +++++++------------ 1 file changed, 18 insertions(+), 29 deletions(-) diff --git a/ext/include/opentelemetry/ext/http/common/url_parser.h b/ext/include/opentelemetry/ext/http/common/url_parser.h index e1d3430329..ff9b42ec00 100644 --- a/ext/include/opentelemetry/ext/http/common/url_parser.h +++ b/ext/include/opentelemetry/ext/http/common/url_parser.h @@ -51,8 +51,7 @@ class UrlParser } else { - scheme_ = std::string(url_.begin() + static_cast(cpos), - url_.begin() + static_cast(pos)); + scheme_ = url_.substr(cpos, pos - cpos); cpos = pos + 3; } @@ -74,16 +73,19 @@ class UrlParser { // port missing. Used default 80 / 443 if (scheme_ == "http") + { port_ = 80; - if (scheme_ == "https") + } + else if (scheme_ == "https") + { port_ = 443; + } } else { // port present is_port = true; - host_ = std::string(url_.begin() + static_cast(cpos), - url_.begin() + static_cast(pos)); + host_ = url_.substr(cpos, pos - cpos); cpos = pos + 1; } pos = url_.find_first_of("/?", cpos); @@ -92,30 +94,23 @@ class UrlParser path_ = std::string("/"); // use default path if (is_port) { - std::string port_str( - url_.begin() + static_cast(cpos), - url_.begin() + static_cast(url_.length())); - - port_ = GetPort(port_str); + auto port_str = url_.substr(cpos, url_.length()); + port_ = GetPort(port_str); } else { - host_ = - std::string(url_.begin() + static_cast(cpos), - url_.begin() + static_cast(url_.length())); + host_ = url_.substr(cpos, url_.length()); } return; } if (is_port) { - std::string port_str(url_.begin() + static_cast(cpos), - url_.begin() + static_cast(pos)); - port_ = GetPort(port_str); + auto port_str = url_.substr(cpos, pos - cpos); + port_ = GetPort(port_str); } else { - host_ = std::string(url_.begin() + static_cast(cpos), - url_.begin() + static_cast(pos)); + host_ = url_.substr(cpos, pos - cpos); } cpos = pos; @@ -124,27 +119,21 @@ class UrlParser pos = url_.find('?', cpos); if (pos == std::string::npos) { - path_ = - std::string(url_.begin() + static_cast(cpos), - url_.begin() + static_cast(url_.length())); + path_ = url_.substr(cpos, url_.length() - cpos); query_ = ""; } else { - path_ = std::string(url_.begin() + static_cast(cpos), - url_.begin() + static_cast(pos)); - cpos = pos + 1; - query_ = - std::string(url_.begin() + static_cast(cpos), - url_.begin() + static_cast(url_.length())); + path_ = url_.substr(cpos, pos - cpos); + cpos = pos + 1; + query_ = url_.substr(cpos, url_.length() - cpos); } return; } path_ = std::string("/"); if (url_[cpos] == '?') { - query_ = std::string(url_.begin() + static_cast(cpos), - url_.begin() + static_cast(url_.length())); + query_ = url_.substr(cpos, url_.length() - cpos); } }