Skip to content

Commit 43cfd7c

Browse files
committed
fix: apply suggestions from code review comments
1 parent 478139d commit 43cfd7c

File tree

1 file changed

+18
-29
lines changed

1 file changed

+18
-29
lines changed

ext/include/opentelemetry/ext/http/common/url_parser.h

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ class UrlParser
5151
}
5252
else
5353
{
54-
scheme_ = std::string(url_.begin() + static_cast<std::string::difference_type>(cpos),
55-
url_.begin() + static_cast<std::string::difference_type>(pos));
54+
scheme_ = url_.substr(cpos, pos - cpos);
5655
cpos = pos + 3;
5756
}
5857

@@ -74,16 +73,19 @@ class UrlParser
7473
{
7574
// port missing. Used default 80 / 443
7675
if (scheme_ == "http")
76+
{
7777
port_ = 80;
78-
if (scheme_ == "https")
78+
}
79+
else if (scheme_ == "https")
80+
{
7981
port_ = 443;
82+
}
8083
}
8184
else
8285
{
8386
// port present
8487
is_port = true;
85-
host_ = std::string(url_.begin() + static_cast<std::string::difference_type>(cpos),
86-
url_.begin() + static_cast<std::string::difference_type>(pos));
88+
host_ = url_.substr(cpos, pos - cpos);
8789
cpos = pos + 1;
8890
}
8991
pos = url_.find_first_of("/?", cpos);
@@ -92,30 +94,23 @@ class UrlParser
9294
path_ = std::string("/"); // use default path
9395
if (is_port)
9496
{
95-
std::string port_str(
96-
url_.begin() + static_cast<std::string::difference_type>(cpos),
97-
url_.begin() + static_cast<std::string::difference_type>(url_.length()));
98-
99-
port_ = GetPort(port_str);
97+
auto port_str = url_.substr(cpos, url_.length());
98+
port_ = GetPort(port_str);
10099
}
101100
else
102101
{
103-
host_ =
104-
std::string(url_.begin() + static_cast<std::string::difference_type>(cpos),
105-
url_.begin() + static_cast<std::string::difference_type>(url_.length()));
102+
host_ = url_.substr(cpos, url_.length());
106103
}
107104
return;
108105
}
109106
if (is_port)
110107
{
111-
std::string port_str(url_.begin() + static_cast<std::string::difference_type>(cpos),
112-
url_.begin() + static_cast<std::string::difference_type>(pos));
113-
port_ = GetPort(port_str);
108+
auto port_str = url_.substr(cpos, pos - cpos);
109+
port_ = GetPort(port_str);
114110
}
115111
else
116112
{
117-
host_ = std::string(url_.begin() + static_cast<std::string::difference_type>(cpos),
118-
url_.begin() + static_cast<std::string::difference_type>(pos));
113+
host_ = url_.substr(cpos, pos - cpos);
119114
}
120115
cpos = pos;
121116

@@ -124,27 +119,21 @@ class UrlParser
124119
pos = url_.find('?', cpos);
125120
if (pos == std::string::npos)
126121
{
127-
path_ =
128-
std::string(url_.begin() + static_cast<std::string::difference_type>(cpos),
129-
url_.begin() + static_cast<std::string::difference_type>(url_.length()));
122+
path_ = url_.substr(cpos, url_.length());
130123
query_ = "";
131124
}
132125
else
133126
{
134-
path_ = std::string(url_.begin() + static_cast<std::string::difference_type>(cpos),
135-
url_.begin() + static_cast<std::string::difference_type>(pos));
136-
cpos = pos + 1;
137-
query_ =
138-
std::string(url_.begin() + static_cast<std::string::difference_type>(cpos),
139-
url_.begin() + static_cast<std::string::difference_type>(url_.length()));
127+
path_ = url_.substr(cpos, pos - cpos);
128+
cpos = pos + 1;
129+
query_ = url_.substr(cpos, url_.length());
140130
}
141131
return;
142132
}
143133
path_ = std::string("/");
144134
if (url_[cpos] == '?')
145135
{
146-
query_ = std::string(url_.begin() + static_cast<std::string::difference_type>(cpos),
147-
url_.begin() + static_cast<std::string::difference_type>(url_.length()));
136+
query_ = url_.substr(cpos, url_.length());
148137
}
149138
}
150139

0 commit comments

Comments
 (0)