Skip to content

Commit 478139d

Browse files
committed
[EXPORTER] fix clang-tidy warnings in UrlParser
1 parent 149d29c commit 478139d

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed

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

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <cstdint>
88
#include <cstdlib>
99
#include <string>
10+
#include <utility>
1011

1112
#include "opentelemetry/version.h"
1213

@@ -34,7 +35,7 @@ class UrlParser
3435
std::string query_;
3536
bool success_;
3637

37-
UrlParser(std::string url) : url_(url), success_(true)
38+
UrlParser(std::string url) : url_(std::move(url)), success_(true)
3839
{
3940
if (url_.length() == 0)
4041
{
@@ -50,15 +51,16 @@ class UrlParser
5051
}
5152
else
5253
{
53-
scheme_ = std::string(url_.begin() + cpos, url_.begin() + pos);
54+
scheme_ = std::string(url_.begin() + static_cast<std::string::difference_type>(cpos),
55+
url_.begin() + static_cast<std::string::difference_type>(pos));
5456
cpos = pos + 3;
5557
}
5658

5759
// credentials
58-
size_t pos1 = url_.find_first_of("@", cpos);
59-
size_t pos2 = url_.find_first_of("/", cpos);
60+
size_t pos1 = url_.find_first_of('@', cpos);
6061
if (pos1 != std::string::npos)
6162
{
63+
size_t pos2 = url_.find_first_of('/', cpos);
6264
// TODO - handle credentials
6365
if (pos2 == std::string::npos || pos1 < pos2)
6466
{
@@ -80,7 +82,8 @@ class UrlParser
8082
{
8183
// port present
8284
is_port = true;
83-
host_ = std::string(url_.begin() + cpos, url_.begin() + pos);
85+
host_ = std::string(url_.begin() + static_cast<std::string::difference_type>(cpos),
86+
url_.begin() + static_cast<std::string::difference_type>(pos));
8487
cpos = pos + 1;
8588
}
8689
pos = url_.find_first_of("/?", cpos);
@@ -97,7 +100,9 @@ class UrlParser
97100
}
98101
else
99102
{
100-
host_ = std::string(url_.begin() + cpos, url_.begin() + url_.length());
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()));
101106
}
102107
return;
103108
}
@@ -109,7 +114,8 @@ class UrlParser
109114
}
110115
else
111116
{
112-
host_ = std::string(url_.begin() + cpos, url_.begin() + pos);
117+
host_ = std::string(url_.begin() + static_cast<std::string::difference_type>(cpos),
118+
url_.begin() + static_cast<std::string::difference_type>(pos));
113119
}
114120
cpos = pos;
115121

@@ -118,21 +124,27 @@ class UrlParser
118124
pos = url_.find('?', cpos);
119125
if (pos == std::string::npos)
120126
{
121-
path_ = std::string(url_.begin() + cpos, url_.begin() + url_.length());
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()));
122130
query_ = "";
123131
}
124132
else
125133
{
126-
path_ = std::string(url_.begin() + cpos, url_.begin() + pos);
127-
cpos = pos + 1;
128-
query_ = std::string(url_.begin() + cpos, url_.begin() + url_.length());
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()));
129140
}
130141
return;
131142
}
132143
path_ = std::string("/");
133144
if (url_[cpos] == '?')
134145
{
135-
query_ = std::string(url_.begin() + cpos, url_.begin() + url_.length());
146+
query_ = std::string(url_.begin() + static_cast<std::string::difference_type>(cpos),
147+
url_.begin() + static_cast<std::string::difference_type>(url_.length()));
136148
}
137149
}
138150

@@ -209,7 +221,7 @@ class UrlDecoder
209221
hex[1] = encoded[++pos];
210222

211223
char *endptr;
212-
long value = strtol(hex, &endptr, 16);
224+
int value = static_cast<int>(std::strtol(hex, &endptr, 16));
213225

214226
// Invalid input: no valid hex characters after '%'
215227
if (endptr != &hex[2])

0 commit comments

Comments
 (0)