Commit 045cce7f authored by Andrey Vetlugin's avatar Andrey Vetlugin

WIP Refactor splitLine without regex

parent 84625e20
......@@ -11,11 +11,29 @@ String unescape(String escaped) {
assert unescape('asdf') == 'asdf'
//List<String> splitLine(String line) {
// return line.split(/,/)
//}
List<String> splitLine(String line) {
return line.split(/,/)
List<String> tokens = []
String currentToken = ''
line.each {
if (it == ',') {
tokens << currentToken
currentToken = ''
} else {
currentToken += it
}
}
tokens << currentToken
return tokens
}
assert splitLine('a,b,c') == ['a', 'b', 'c']
assert splitLine('"a","b","c"') == ['a', 'b', 'c']
assert splitLine('"as""df","qwer""') == ['as"df', 'qwer"']
List<String> lines = new File('data.csv').readLines()
......@@ -27,9 +45,6 @@ splitLine(lines.remove(0)).each {
}
println headers
// TODO get lines
// TODO split lines into values
List<Map<String, String>> parsedLines = []
lines.each { line ->
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment