Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Andrey Vetlugin
groovy-csv-exercise
Commits
045cce7f
Commit
045cce7f
authored
Jan 24, 2018
by
Andrey Vetlugin
Browse files
WIP Refactor splitLine without regex
parent
84625e20
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
4 deletions
+19
-4
reader.groovy
reader.groovy
+19
-4
No files found.
reader.groovy
View file @
045cce7f
...
...
@@ -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
->
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment