1 | #include <Functions/FunctionFactory.h> |
---|---|
2 | #include <Functions/FunctionsVisitParam.h> |
3 | #include <Functions/FunctionsStringSearch.h> |
4 | |
5 | |
6 | namespace DB |
7 | { |
8 | |
9 | struct ExtractRaw |
10 | { |
11 | using ExpectChars = PODArrayWithStackMemory<char, 64>; |
12 | |
13 | static void extract(const UInt8 * pos, const UInt8 * end, ColumnString::Chars & res_data) |
14 | { |
15 | ExpectChars expects_end; |
16 | UInt8 current_expect_end = 0; |
17 | |
18 | for (auto extract_begin = pos; pos != end; ++pos) |
19 | { |
20 | if (current_expect_end && *pos == current_expect_end) |
21 | { |
22 | expects_end.pop_back(); |
23 | current_expect_end = expects_end.empty() ? 0 : expects_end.back(); |
24 | } |
25 | else |
26 | { |
27 | switch (*pos) |
28 | { |
29 | case '[': |
30 | current_expect_end = ']'; |
31 | expects_end.push_back(current_expect_end); |
32 | break; |
33 | case '{': |
34 | current_expect_end = '}'; |
35 | expects_end.push_back(current_expect_end); |
36 | break; |
37 | case '"' : |
38 | current_expect_end = '"'; |
39 | expects_end.push_back(current_expect_end); |
40 | break; |
41 | case '\\': |
42 | /// skip backslash |
43 | if (pos + 1 < end && pos[1] == '"') |
44 | pos++; |
45 | break; |
46 | default: |
47 | if (!current_expect_end && (*pos == ',' || *pos == '}')) |
48 | { |
49 | res_data.insert(extract_begin, pos); |
50 | return; |
51 | } |
52 | } |
53 | } |
54 | } |
55 | } |
56 | }; |
57 | |
58 | struct NameVisitParamExtractRaw { static constexpr auto name = "visitParamExtractRaw"; }; |
59 | using FunctionVisitParamExtractRaw = FunctionsStringSearchToString<ExtractParamToStringImpl<ExtractRaw>, NameVisitParamExtractRaw>; |
60 | |
61 | |
62 | void registerFunctionVisitParamExtractRaw(FunctionFactory & factory) |
63 | { |
64 | factory.registerFunction<FunctionVisitParamExtractRaw>(); |
65 | } |
66 | |
67 | } |
68 |