MCPcopy Create free account
hub / github.com/catboost/catboost / TryGetSchemeHostAndPort

Function TryGetSchemeHostAndPort

library/cpp/string_utils/url/url.cpp:262–284  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

260}
261
262bool TryGetSchemeHostAndPort(const TStringBuf url, TStringBuf& scheme, TStringBuf& host, ui16& port) {
263 const size_t schemeSize = GetSchemePrefixSize(url);
264 if (schemeSize != 0) {
265 scheme = url.Head(schemeSize);
266 }
267
268 TStringBuf portStr;
269 TStringBuf hostAndPort = GetHostAndPort(url.Tail(schemeSize));
270 if (hostAndPort && hostAndPort.back() != ']' && hostAndPort.TryRSplit(':', host, portStr)) {
271 // URL has port
272 if (!TryFromString(portStr, port)) {
273 return false;
274 }
275 } else {
276 host = hostAndPort;
277 if (scheme == TStringBuf("https://")) {
278 port = 443;
279 } else if (scheme == TStringBuf("http://")) {
280 port = 80;
281 }
282 }
283 return true;
284}
285
286void GetSchemeHostAndPort(const TStringBuf url, TStringBuf& scheme, TStringBuf& host, ui16& port) {
287 bool isOk = TryGetSchemeHostAndPort(url, scheme, host, port);

Callers 1

GetSchemeHostAndPortFunction · 0.85

Calls 7

GetSchemePrefixSizeFunction · 0.85
GetHostAndPortFunction · 0.85
TryFromStringFunction · 0.85
TailMethod · 0.80
TryRSplitMethod · 0.80
HeadMethod · 0.45
backMethod · 0.45

Tested by

no test coverage detected