From c2c1d0963e62a826764d890c9eb64d79aaf71936 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Sun, 19 Nov 2023 17:19:16 +0000 Subject: [PATCH] Fixed #620: Generators can handle trailing quotes --- .../indigoplugin/generators/EmbedData.scala | 14 +++++++++++--- .../generators/EmbedDataTests.scala | 19 +++++++++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/indigo-plugin/indigo-plugin/src/indigoplugin/generators/EmbedData.scala b/indigo-plugin/indigo-plugin/src/indigoplugin/generators/EmbedData.scala index 1ff3e29dc..26631c6bd 100644 --- a/indigo-plugin/indigo-plugin/src/indigoplugin/generators/EmbedData.scala +++ b/indigo-plugin/indigo-plugin/src/indigoplugin/generators/EmbedData.scala @@ -110,9 +110,11 @@ object EmbedData { // to a list of pairs // of things and strings. def parse(delimiter: String): String => List[(DataType, String)] = { - val takeUpToDelimiter = s"^(.*?)${delimiter}(.*)".r - val takeMatchingSingleQuotes = s"^'(.*?)'${delimiter}(.*)".r - val takeMatchingDoubleQuotes = s"""^\"(.*?)\"${delimiter}(.*)""".r + val takeUpToDelimiter = s"^(.*?)${delimiter}(.*)".r + val takeMatchingSingleQuotes = s"^'(.*?)'${delimiter}(.*)".r + val takeMatchingDoubleQuotes = s"""^\"(.*?)\"${delimiter}(.*)""".r + val takeRemainingSingleQuotes = s"^'(.*?)'".r + val takeRemainingDoubleQuotes = s"""^\"(.*?)\"""".r (in: String) => in match { @@ -125,6 +127,12 @@ object EmbedData { case takeUpToDelimiter(take, left) => List(DataType.decideType(take.trim) -> left) ++ parse(delimiter)(left.trim) + case takeRemainingSingleQuotes(take) => + List(DataType.decideType(take.trim) -> "") + + case takeRemainingDoubleQuotes(take) => + List(DataType.decideType(take.trim) -> "") + case take => List(DataType.decideType(take.trim) -> "") } diff --git a/indigo-plugin/indigo-plugin/test/src/indigoplugin/generators/EmbedDataTests.scala b/indigo-plugin/indigo-plugin/test/src/indigoplugin/generators/EmbedDataTests.scala index b64e75690..03701977f 100644 --- a/indigo-plugin/indigo-plugin/test/src/indigoplugin/generators/EmbedDataTests.scala +++ b/indigo-plugin/indigo-plugin/test/src/indigoplugin/generators/EmbedDataTests.scala @@ -151,6 +151,25 @@ class EmbedDataTests extends munit.FunSuite { assertEquals(actual, expected) } + test("Extract row data - csv - with leading and trailing quotes".only) { + val row = """"hello there",abc,123,def,456,"ghi 789"""" + + val actual = + EmbedData.extractRowData(row, ",") + + val expected = + List( + DataType.StringData("hello there"), + DataType.StringData("abc"), + DataType.IntData(123), + DataType.StringData("def"), + DataType.IntData(456), + DataType.StringData("ghi 789") + ) + + assertEquals(actual, expected) + } + test("Extract row data - csv - with double quotes and single quotes") { val row = """abc,"123,'def'",456,ghi789"""