Skip to content

Commit

Permalink
Improve CSV parsing
Browse files Browse the repository at this point in the history
Use first line as a header if no header is set at all
  • Loading branch information
dolfinus committed Sep 29, 2019
1 parent 6a8e117 commit 44fa4cb
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/org/camunda/latera/bss/utils/CSV.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ class CSV {
List item = []
if (isString(line) && notEmpty(line)) {
line = trim(line).split(delimiter)
if (!data && !header) { // read first line as header if header is not set
setHeader(line)
return
}
if (notHeader(line)) {
if (header) {
header.eachWithIndex { CharSequence column, Integer pos ->
Expand All @@ -78,11 +82,18 @@ class CSV {
}
}
} else if (isMap(line)) {
List mapKeys = keysList(line)
if (!header) {
setHeader(mapKeys)
}
header.each { CharSequence column ->
item << line[column]
}
result << item
} else if (isList(line)) {
if (!header) {
setHeader(line)
}
if (notHeader(line)) {
result << line
}
Expand Down

0 comments on commit 44fa4cb

Please sign in to comment.