src/NullByteHandler.h
branchv_0
changeset 25 58de33c1af03
parent 24 d698d34baf9b
--- a/src/NullByteHandler.h	Sat Apr 23 11:31:30 2022 +0200
+++ b/src/NullByteHandler.h	Sat Apr 23 11:52:41 2022 +0200
@@ -29,6 +29,8 @@
 #include <relpipe/reader/handlers/RelationalReaderStringHandler.h>
 #include <relpipe/reader/handlers/AttributeMetadata.h>
 
+#include "Configuration.h"
+
 namespace relpipe {
 namespace out {
 namespace nullbyte {
@@ -40,10 +42,12 @@
 class NullByteHandler : public RelationalReaderStringHandler {
 private:
 	std::ostream& output;
-	std::wstring_convert<std::codecvt_utf8<wchar_t>> convertor; // TODO: support also other encodings.
+	std::wstring_convert<std::codecvt_utf8<wchar_t>> convertor; // TODO: support also other encodings?
+	Configuration configuration;
+	std::string nullByteReplacement;
 public:
 
-	NullByteHandler(std::ostream& output) : output(output) {
+	NullByteHandler(Configuration configuration, std::ostream& output) : configuration(configuration), output(output), nullByteReplacement(convertor.to_bytes(configuration.nullByteReplacement)) {
 	}
 
 	void startRelation(string_t name, std::vector<AttributeMetadata> attributes) override {
@@ -54,7 +58,7 @@
 		const std::string octets = convertor.to_bytes(value);
 		for (char ch : octets) {
 			if (ch) output.put(ch);
-			else output.put('@'); // TODO: configurable replacement, maybe a string instead of a single char
+			else output << nullByteReplacement;
 		}
 		output.put(0);
 	}