-
Notifications
You must be signed in to change notification settings - Fork 5
/
split_arrays.cpp
42 lines (39 loc) · 1.43 KB
/
split_arrays.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <charconv>
#include <string_view>
//---------------------------------------------------------------------------
#include <udo/UDOperator.hpp>
//---------------------------------------------------------------------------
using namespace std;
//---------------------------------------------------------------------------
struct InputTuple {
udo::String name;
udo::String values;
};
//---------------------------------------------------------------------------
struct OutputTuple {
udo::String name;
int64_t value;
};
//---------------------------------------------------------------------------
class SplitArrays : public udo::UDOperator<InputTuple, OutputTuple> {
public:
void consume(LocalState& /*localState*/, const InputTuple& input) {
OutputTuple output;
output.name = input.name;
string_view values = input.values;
const char* currentValueBegin = values.data();
const char* it = values.data();
const char* end = values.data() + values.size();
for (; it != end; ++it) {
if (*it == ',' || it + 1 == end) {
auto currentValueEnd = *it == ',' ? it : end;
if (currentValueBegin != currentValueEnd) {
auto result = from_chars(currentValueBegin, currentValueEnd, output.value);
if (result.ptr == currentValueEnd)
produceOutputTuple(output);
}
currentValueBegin = it + 1;
}
}
}
};