| 1 | #include <Functions/FunctionFactory.h> | 
|---|---|
| 2 | #include <Functions/FunctionStringToString.h> | 
| 3 | #include "FunctionsURL.h" | 
| 4 | #include <common/find_symbols.h> | 
| 5 | |
| 6 | namespace DB | 
| 7 | { | 
| 8 | |
| 9 | struct ExtractPath | 
| 10 | { | 
| 11 | static size_t getReserveLengthForElement() { return 25; } | 
| 12 | |
| 13 | static void execute(Pos data, size_t size, Pos & res_data, size_t & res_size) | 
| 14 | { | 
| 15 | res_data = data; | 
| 16 | res_size = 0; | 
| 17 | |
| 18 | Pos pos = data; | 
| 19 | Pos end = pos + size; | 
| 20 | |
| 21 | if (end != (pos = find_first_symbols<'/'>(pos, end)) && pos[1] == '/' && end != (pos = find_first_symbols<'/'>(pos + 2, end))) | 
| 22 | { | 
| 23 | Pos query_string_or_fragment = find_first_symbols<'?', '#'>(pos, end); | 
| 24 | |
| 25 | res_data = pos; | 
| 26 | res_size = query_string_or_fragment - res_data; | 
| 27 | } | 
| 28 | } | 
| 29 | }; | 
| 30 | |
| 31 | struct NamePath { static constexpr auto name = "path"; }; | 
| 32 | using FunctionPath = FunctionStringToString<ExtractSubstringImpl<ExtractPath>, NamePath>; | 
| 33 | |
| 34 | void registerFunctionPath(FunctionFactory & factory) | 
| 35 | { | 
| 36 | factory.registerFunction<FunctionPath>(); | 
| 37 | } | 
| 38 | |
| 39 | } | 
| 40 | 
