12 #include "opentelemetry/version.h"
40 if (
url_.length() == 0)
46 size_t pos =
url_.find(
"://", cpos);
47 if (pos == std::string::npos)
59 size_t pos1 =
url_.find_first_of(
'@', cpos);
60 if (pos1 != std::string::npos)
62 size_t pos2 =
url_.find_first_of(
'/', cpos);
64 if (pos2 == std::string::npos || pos1 < pos2)
70 pos = FindPortPosition(
url_, cpos);
72 if (pos == std::string::npos)
91 pos =
url_.find_first_of(
"/?", cpos);
92 if (pos == std::string::npos)
94 path_ = std::string(
"/");
97 auto port_str =
url_.substr(cpos);
98 port_ = GetPort(port_str);
108 auto port_str =
url_.substr(cpos, pos - cpos);
109 port_ = GetPort(port_str);
117 if (
url_[cpos] ==
'/')
119 pos =
url_.find(
'?', cpos);
120 if (pos == std::string::npos)
132 path_ = std::string(
"/");
133 if (
url_[cpos] ==
'?')
140 static std::string::size_type FindPortPosition(
const std::string &url,
141 std::string::size_type offset)
144 size_t sub_expression_counter = 0;
145 for (std::string::size_type i = offset; i < url.size(); ++i)
148 if (0 == sub_expression_counter && c ==
':')
155 ++sub_expression_counter;
159 if (sub_expression_counter > 0)
161 --sub_expression_counter;
164 else if (0 == sub_expression_counter && c ==
'/')
170 return std::string::npos;
173 std::uint16_t GetPort(
const std::string &s)
177 auto port = std::strtol(s.c_str(), &e, 10);
178 if (e == s.c_str() || e != s.c_str() + s.size() || errno == ERANGE || port < 0 || port > 65535)
184 return static_cast<uint16_t
>(port);
191 static std::string
Decode(
const std::string &encoded)
194 result.reserve(encoded.size());
196 auto hex_to_int = [](
int ch) ->
int {
197 if (ch >=
'0' && ch <=
'9')
199 if (ch >=
'a' && ch <=
'f')
200 return ch -
'a' + 10;
201 if (ch >=
'A' && ch <=
'F')
202 return ch -
'A' + 10;
206 for (
size_t pos = 0; pos < encoded.size(); pos++)
208 auto c = encoded[pos];
211 if (pos + 2 >= encoded.size())
216 int hi = hex_to_int(encoded[pos + 1]);
217 int lo = hex_to_int(encoded[pos + 2]);
219 if (hi == -1 || lo == -1)
224 c =
static_cast<char>((hi << 4) | lo);