equal
deleted
inserted
replaced
27 #include <relpipe/reader/typedefs.h> |
27 #include <relpipe/reader/typedefs.h> |
28 #include <relpipe/reader/TypeId.h> |
28 #include <relpipe/reader/TypeId.h> |
29 #include <relpipe/reader/handlers/RelationalReaderStringHandler.h> |
29 #include <relpipe/reader/handlers/RelationalReaderStringHandler.h> |
30 #include <relpipe/reader/handlers/AttributeMetadata.h> |
30 #include <relpipe/reader/handlers/AttributeMetadata.h> |
31 |
31 |
|
32 #include "Configuration.h" |
|
33 |
32 namespace relpipe { |
34 namespace relpipe { |
33 namespace out { |
35 namespace out { |
34 namespace nullbyte { |
36 namespace nullbyte { |
35 |
37 |
36 using namespace relpipe; |
38 using namespace relpipe; |
38 using namespace relpipe::reader::handlers; |
40 using namespace relpipe::reader::handlers; |
39 |
41 |
40 class NullByteHandler : public RelationalReaderStringHandler { |
42 class NullByteHandler : public RelationalReaderStringHandler { |
41 private: |
43 private: |
42 std::ostream& output; |
44 std::ostream& output; |
43 std::wstring_convert<std::codecvt_utf8<wchar_t>> convertor; // TODO: support also other encodings. |
45 std::wstring_convert<std::codecvt_utf8<wchar_t>> convertor; // TODO: support also other encodings? |
|
46 Configuration configuration; |
|
47 std::string nullByteReplacement; |
44 public: |
48 public: |
45 |
49 |
46 NullByteHandler(std::ostream& output) : output(output) { |
50 NullByteHandler(Configuration configuration, std::ostream& output) : configuration(configuration), output(output), nullByteReplacement(convertor.to_bytes(configuration.nullByteReplacement)) { |
47 } |
51 } |
48 |
52 |
49 void startRelation(string_t name, std::vector<AttributeMetadata> attributes) override { |
53 void startRelation(string_t name, std::vector<AttributeMetadata> attributes) override { |
50 |
54 |
51 } |
55 } |
52 |
56 |
53 void attribute(const string_t& value) override { |
57 void attribute(const string_t& value) override { |
54 const std::string octets = convertor.to_bytes(value); |
58 const std::string octets = convertor.to_bytes(value); |
55 for (char ch : octets) { |
59 for (char ch : octets) { |
56 if (ch) output.put(ch); |
60 if (ch) output.put(ch); |
57 else output.put('@'); // TODO: configurable replacement, maybe a string instead of a single char |
61 else output << nullByteReplacement; |
58 } |
62 } |
59 output.put(0); |
63 output.put(0); |
60 } |
64 } |
61 |
65 |
62 void endOfPipe() { |
66 void endOfPipe() { |