Skip to content

Commit

Permalink
Merge pull request #443 from davidavdav/master
Browse files Browse the repository at this point in the history
Added support for whitespace-delimited input to readtable()
  • Loading branch information
johnmyleswhite committed Dec 13, 2013
2 parents 6df1f7b + 591c130 commit afb0d61
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ function readnrows!(p::ParsedCSV, io::IO, nrows::Int, o::ParseOptions)
at_start = true
chr = 0xff
nextchr = 0xff
skip_white = true # whitespace flag if separator=' '

# 'in' does not work if passed Uint8 and Vector{Char}
quotemark = convert(Vector{Uint8}, o.quotemark)
Expand Down Expand Up @@ -159,7 +160,15 @@ function readnrows!(p::ParsedCSV, io::IO, nrows::Int, o::ParseOptions)
if chr in quotemark
in_quotes = true
p.quoted[n_fields] = true
skip_white = false
# Finished reading a field
elseif o.separator == ' ' && (chr == ' ' || chr == '\t')
if !in(char(nextchr), " \t\n\r") && !skip_white
@push n_bounds p.bounds n_bytes l_bounds
@push n_bytes p.bytes '\n' l_bytes
@push n_fields p.quoted false l_quoted
skip_white = false
end
elseif chr == o.separator
@push n_bounds p.bounds n_bytes l_bounds
@push n_bytes p.bytes '\n' l_bytes
Expand All @@ -171,9 +180,11 @@ function readnrows!(p::ParsedCSV, io::IO, nrows::Int, o::ParseOptions)
@push n_bytes p.bytes '\n' l_bytes
@push n_lines p.lines n_bytes l_lines
@push n_fields p.quoted false l_quoted
skip_white = true
# Store character in buffer
else
@push n_bytes p.bytes chr l_bytes
skip_white = false
end
else
# Escape a quotemark inside quoted field
Expand Down
3 changes: 3 additions & 0 deletions test/data/quoting/quotedwhitespace.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
C1 C2 C3 C4 C5
a "b" "c d" 1.0 1
a " b " "" 4 5
5 changes: 5 additions & 0 deletions test/data/separators/sample_data_white.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
0 3 5
1 13 4
12 3 3
13 3 102
10 20 30
4 changes: 4 additions & 0 deletions test/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ module TestIO
readtable("test/data/comments/before_after_data.csv", allowcomments = true)
readtable("test/data/comments/middata.csv", allowcomments = true)
readtable("test/data/skiplines/skipfront.csv", skipstart = 3)

readtable("test/data/separators/sample_data_white.txt",separator=' ')
readtable("test/data/quoting/quotedwhitespace.txt", separator=' ')


# TODO: Implement skipping lines at specified row positions
# readtable("test/data/skiplines/skipbottom.csv", skiprows = [1, 2, 3])
Expand Down

0 comments on commit afb0d61

Please sign in to comment.