Skip to content

Commit

Permalink
refs #25 improve logic
Browse files Browse the repository at this point in the history
  • Loading branch information
doyaaaaaken committed Aug 25, 2019
1 parent a7ea069 commit f90bd5a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,12 @@ internal class ParseStateMachine(
ParseState.FIELD -> {
when (ch) {
escapeChar -> {
if (nextCh != null) {
if (nextCh == escapeChar || nextCh == delimiter) {
field.append(nextCh)
state = ParseState.FIELD
pos += 1
} else {
throw MalformedCSVException("$pos")
}
if (nextCh != null && nextCh == escapeChar) {
field.append(nextCh)
state = ParseState.FIELD
pos += 1
} else {
state = ParseState.QUOTE_END
throw MalformedCSVException("$pos")
}
}
delimiter -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ class CsvParserTest : WordSpec() {
parser.parseRow("a\r") shouldBe listOf("a")
parser.parseRow("a\r\n") shouldBe listOf("a")
}
"parse escape character after field" {
parser.parseRow("a\"\"") shouldBe listOf("a\"")
}
}
}
}

0 comments on commit f90bd5a

Please sign in to comment.