MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / parseAddress

Function parseAddress

src/Common/parseAddress.cpp:15–60  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

13}
14
15std::pair<std::string, UInt16> parseAddress(const std::string & str, UInt16 default_port)
16{
17 if (str.empty())
18 throw Exception(ErrorCodes::BAD_ARGUMENTS, "Empty address passed to function parseAddress");
19
20 const char * begin = str.data();
21 const char * end = begin + str.size();
22 const char * port = end; // NOLINT
23
24 if (begin[0] == '[')
25 {
26 const char * closing_square_bracket = find_first_symbols<']'>(begin + 1, end);
27 if (closing_square_bracket >= end)
28 throw Exception(ErrorCodes::BAD_ARGUMENTS, "Illegal address passed to function parseAddress: "
29 "the address begins with opening square bracket, but no closing square bracket found");
30
31 port = closing_square_bracket + 1;
32 }
33 else
34 port = find_first_symbols<':'>(begin, end);
35
36 if (port != end)
37 {
38 if (*port != ':')
39 throw Exception(ErrorCodes::BAD_ARGUMENTS,
40 "Illegal port prefix passed to function parseAddress: {}", port);
41
42 ++port;
43
44 UInt16 port_number = 0;
45 ReadBufferFromMemory port_buf(port, end - port);
46 if (!tryReadText(port_number, port_buf) || !port_buf.eof())
47 {
48 throw Exception(ErrorCodes::BAD_ARGUMENTS,
49 "Illegal port passed to function parseAddress: {}", port);
50 }
51 return { std::string(begin, port - 1), port_number };
52 }
53 if (default_port)
54 {
55 return {str, default_port};
56 }
57 throw Exception(
58 ErrorCodes::BAD_ARGUMENTS,
59 "The address passed to function parseAddress doesn't contain port number and no 'default_port' was passed");
60}
61
62}

Callers 9

getRedisConfigurationFunction · 0.85
getConfigurationImplFunction · 0.85
getConfigurationMethod · 0.85
StorageRabbitMQMethod · 0.85
registerDatabaseMySQLFunction · 0.85
parseEntriesMethod · 0.85
parseArgumentsMethod · 0.85
AddressMethod · 0.85

Calls 6

ExceptionClass · 0.70
tryReadTextFunction · 0.50
emptyMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45
eofMethod · 0.45

Tested by

no test coverage detected