1 | #pragma once |
---|---|
2 | |
3 | #include "FunctionsURL.h" |
4 | #include <Common/StringUtils/StringUtils.h> |
5 | |
6 | |
7 | namespace DB |
8 | { |
9 | |
10 | /// Extracts scheme from given url. |
11 | inline StringRef getURLScheme(const char * data, size_t size) |
12 | { |
13 | // scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." ) |
14 | const char * pos = data; |
15 | const char * end = data + size; |
16 | |
17 | if (isAlphaASCII(*pos)) |
18 | { |
19 | for (++pos; pos < end; ++pos) |
20 | { |
21 | if (!(isAlphaNumericASCII(*pos) || *pos == '+' || *pos == '-' || *pos == '.')) |
22 | { |
23 | break; |
24 | } |
25 | } |
26 | |
27 | return StringRef(data, pos - data); |
28 | } |
29 | |
30 | return {}; |
31 | } |
32 | |
33 | struct ExtractProtocol |
34 | { |
35 | static size_t getReserveLengthForElement() |
36 | { |
37 | return strlen("https") + 1; |
38 | } |
39 | |
40 | static void execute(Pos data, size_t size, Pos & res_data, size_t & res_size) |
41 | { |
42 | res_data = data; |
43 | res_size = 0; |
44 | |
45 | StringRef scheme = getURLScheme(data, size); |
46 | Pos pos = data + scheme.size; |
47 | |
48 | if (scheme.size == 0 || (data + size) - pos < 4) |
49 | return; |
50 | |
51 | if (pos[0] == ':') |
52 | res_size = pos - data; |
53 | } |
54 | }; |
55 | |
56 | } |
57 | |
58 |