Changeset View
Changeset View
Standalone View
Standalone View
src/util/strencodings.cpp
Show First 20 Lines • Show All 108 Lines • ▼ Show 20 Lines | std::vector<uint8_t> ParseHex(const std::string &str) { | ||||
return ParseHex(str.c_str()); | return ParseHex(str.c_str()); | ||||
} | } | ||||
void SplitHostPort(std::string in, int &portOut, std::string &hostOut) { | void SplitHostPort(std::string in, int &portOut, std::string &hostOut) { | ||||
size_t colon = in.find_last_of(':'); | size_t colon = in.find_last_of(':'); | ||||
// if a : is found, and it either follows a [...], or no other : is in the | // if a : is found, and it either follows a [...], or no other : is in the | ||||
// string, treat it as port separator | // string, treat it as port separator | ||||
bool fHaveColon = colon != in.npos; | bool fHaveColon = colon != in.npos; | ||||
bool fBracketed = | // if there is a colon, and in[0]=='[', colon is not 0, so in[colon-1] is | ||||
fHaveColon && | // safe | ||||
(in[0] == '[' && in[colon - 1] == ']'); // if there is a colon, and | bool fBracketed = fHaveColon && (in[0] == '[' && in[colon - 1] == ']'); | ||||
// in[0]=='[', colon is not 0, | |||||
// so in[colon-1] is safe | |||||
bool fMultiColon = | bool fMultiColon = | ||||
fHaveColon && (in.find_last_of(':', colon - 1) != in.npos); | fHaveColon && (in.find_last_of(':', colon - 1) != in.npos); | ||||
if (fHaveColon && (colon == 0 || fBracketed || !fMultiColon)) { | if (fHaveColon && (colon == 0 || fBracketed || !fMultiColon)) { | ||||
int32_t n; | int32_t n; | ||||
if (ParseInt32(in.substr(colon + 1), &n) && n > 0 && n < 0x10000) { | if (ParseInt32(in.substr(colon + 1), &n) && n > 0 && n < 0x10000) { | ||||
in = in.substr(0, colon); | in = in.substr(0, colon); | ||||
portOut = n; | portOut = n; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 515 Lines • Show Last 20 Lines |