Skip to content

Commit

Permalink
Fixed #620: Generators can handle trailing quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
davesmith00000 committed Nov 19, 2023
1 parent daed9f7 commit c2c1d09
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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) -> "")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"""

Expand Down

0 comments on commit c2c1d09

Please sign in to comment.