integer and boolean types in AWK v_0 v0.12
authorFrantišek Kučera <franta-hg@frantovo.cz>
Mon, 27 May 2019 17:54:35 +0200
branchv_0
changeset 31 64d9244ee252
parent 30 5261dfd3b952
child 32 34bacd35f32e
integer and boolean types in AWK
src/AwkHandler.h
--- a/src/AwkHandler.h	Sun May 26 22:15:05 2019 +0200
+++ b/src/AwkHandler.h	Mon May 27 17:54:35 2019 +0200
@@ -361,13 +361,27 @@
 				awkScript << std::endl;
 
 				awkScript << L"function _readVariables() {" << std::endl;
-				for (int i = 0; i < currentReaderMetadata.size(); i++) awkScript << a2v(currentReaderMetadata[i].getAttributeName()) << L"=_unescape($" << (i + 1) << L");" << std::endl;
+				for (int i = 0; i < currentReaderMetadata.size(); i++) {
+					AttributeMetadata& a = currentReaderMetadata[i];
+					awkScript << a2v(a.getAttributeName());
+					if (a.getTypeId() == TypeId::INTEGER) awkScript << L"=$" << (i + 1) << L";";
+					else if (a.getTypeId() == TypeId::BOOLEAN) awkScript << L"= $" << (i + 1) << L" == \"true\";";
+					else awkScript << L"=_unescape($" << (i + 1) << L");";
+					awkScript << std::endl;
+				}
 				awkScript << L"};" << std::endl;
 				awkScript << std::endl;
 
 				awkScript << L"function _writeVariables() {" << std::endl;
 				awkScript << L"NF=" << currentWriterMetadata.size() << ";" << std::endl;
-				for (int i = 0; i < currentWriterMetadata.size(); i++) awkScript << L"$" << (i + 1) << L"=_escape(" << a2v(currentWriterMetadata[i].attributeName) << L");" << std::endl;
+				for (int i = 0; i < currentWriterMetadata.size(); i++) {
+					writer::AttributeMetadata& a = currentWriterMetadata[i];
+					awkScript << L"$" << (i + 1);
+					if (a.typeId == writer::TypeId::INTEGER) awkScript << L"=" << a2v(a.attributeName) << L";";
+					else if (a.typeId == writer::TypeId::BOOLEAN) awkScript << L"= " << a2v(a.attributeName) << L" ? \"true\" : \"false\" ;";
+					else awkScript << L"=_escape(" << a2v(a.attributeName) << L");";
+					awkScript << std::endl;
+				}
 				awkScript << L"};" << std::endl;
 				awkScript << std::endl;