--- a/src/AwkHandler.h Sat May 25 17:00:51 2019 +0200
+++ b/src/AwkHandler.h Sat May 25 21:52:56 2019 +0200
@@ -324,18 +324,42 @@
awkScript << L"END {" << std::endl;
awkScript << currentRelationConfiguration->awkAfterRecords << std::endl;
awkScript << L"};" << std::endl;
- awkScript << std::endl;
- awkScript << L"function _escape(value) {" << std::endl;
- // FIXME: escape function
- awkScript << L"return value;" << std::endl;
- awkScript << L"};" << std::endl;
- awkScript << std::endl;
+ awkScript << LR"AWK(
+function _escape(value, i) {
+ result = "";
+ split(value, chars, "");
+ for (i = 1; i <= length(chars); i++) {
+ ch = chars[i];
+ if (ch == "\\") { ch = "\\\\"; }
+ else if (ch == "\t") { ch = "\\t"; }
+ else if (ch == "\n") { ch = "\\n"; }
+ result = result ch;
+ }
+ return result;
+};
+
+function _unescape(value, i) {
+ result = "";
+ split(value, chars, "");
+ for (i = 1; i <= length(chars); i++) {
+ ch = chars[i];
+ if (ch == "\\") {
+ ch = chars[++i];
+ if (ch == "\\") { ch = "\\"; }
+ else if (ch == "t") { ch = "\t"; }
+ else if (ch == "n") { ch = "\n"; }
+ else {
+ printf("Unsupported escape sequence: %s\n", ch) > "/dev/stderr";
+ exit 70;
+ }
+ }
+ result = result ch;
+ }
+ return result;
+};
+)AWK";
- awkScript << L"function _unescape(value) {" << std::endl;
- // FIXME: unescape function
- awkScript << L"return value;" << std::endl;
- awkScript << L"};" << std::endl;
awkScript << std::endl;
awkScript << L"function _readVariables() {" << std::endl;