value escaping in c++ v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Sat, 11 May 2019 22:47:49 +0200
branchv_0
changeset 23 bc20d499a458
parent 22 98acfdc4c20b
child 24 c805c968b7ed
value escaping in c++
src/AwkHandler.h
--- a/src/AwkHandler.h	Fri May 10 00:45:37 2019 +0200
+++ b/src/AwkHandler.h	Sat May 11 22:47:49 2019 +0200
@@ -152,8 +152,14 @@
 	}
 
 	string_t escapeAwkValue(const string_t& value) {
-		// FIXME: escape field and record separators
-		return value;
+		std::wstringstream escaped;
+		for (wchar_t ch : value) {
+			if (ch == '\t') escaped << L"\\t";
+			else if (ch == '\n') escaped << L"\\n";
+			else if (ch == '\\') escaped << L"\\\\";
+			else escaped << ch;
+		}
+		return escaped.str();
 	}
 
 	void processAwkOutput(int awkOutputReaderFD) {