55function _writevalue (io:: IO , value:: AbstractString , delim, quotechar, escapechar, nastring)
66 print (io, quotechar)
77 for c in value
8- if c== quotechar || c== escapechar
8+ if c == quotechar || c == escapechar
99 print (io, escapechar)
1010 end
1111 print (io, c)
3131 n = length (col_names)
3232 push_exprs = Expr (:block )
3333 for i in 1 : n
34- push! (push_exprs. args, :( _writevalue (io, i.$ (col_names[i]), delim, quotechar, escapechar, nastring) ))
35- if i< n
36- push! (push_exprs. args, :( print (io, delim ) ))
34+ push! (push_exprs. args, :(_writevalue (io, i.$ (col_names[i]), delim, quotechar, escapechar, nastring)))
35+ if i < n
36+ push! (push_exprs. args, :(print (io, delim) ))
3737 end
3838 end
39- push! (push_exprs. args, :( println (io) ))
39+ push! (push_exprs. args, :(println (io)))
4040
4141 quote
4242 for i in it
@@ -52,10 +52,10 @@ function _save(io, data; delim=',', quotechar='"', escapechar='"', nastring="NA"
5252 colnames = collect (eltype (it). parameters[1 ])
5353
5454 if header
55- if quotechar=== nothing
56- join (io,[string (colname) for colname in colnames],delim)
55+ if quotechar === nothing
56+ join (io, [string (colname) for colname in colnames], delim)
5757 else
58- join (io,[" $(quotechar) " * replace (string (colname), quotechar => " $(escapechar)$(quotechar) " ) * " $(quotechar) " for colname in colnames],delim)
58+ join (io, [" $(quotechar) " * replace (string (colname), quotechar => " $(escapechar)$(quotechar) " ) * " $(quotechar) " for colname in colnames], delim)
5959 end
6060 println (io)
6161 end
@@ -69,11 +69,11 @@ function _save(filename::AbstractString, data; delim=',', quotechar='"', escapec
6969
7070 if ext == " gz" # Gzipped
7171 open (GzipCompressorStream, filename, " w" ) do io
72- _save (io, data, delim= delim, quotechar= quotechar, escapechar= escapechar, nastring= nastring, header= header)
72+ _save (io, data, delim= delim, quotechar= quotechar, escapechar= escapechar, nastring= nastring, header= header)
7373 end
7474 else
7575 open (filename, " w" ) do io
76- _save (io, data, delim= delim, quotechar= quotechar, escapechar= escapechar, nastring= nastring, header= header)
76+ _save (io, data, delim= delim, quotechar= quotechar, escapechar= escapechar, nastring= nastring, header= header)
7777 end
7878 end
7979end
9999#
100100# Streaming version writes header (if any) on first call, then appends on subsequent calls.
101101#
102- const CSV_or_TSV = Union{FileIO. format " CSV" , FileIO. format " TSV" }
102+ const CSV_or_TSV = Union{FileIO. format " CSV" ,FileIO. format " TSV" }
103103
104104_delim (T) = T <: FileIO.format"CSV" ? ' ,' : ' \t '
105105
@@ -112,26 +112,26 @@ mutable struct CSVFileSaveStream{T}
112112 nastring:: AbstractString
113113 header:: Bool
114114end
115-
116- function fileio_savestreaming (f:: FileIO.File{T} , data= nothing ; delim= _delim (T), quotechar= ' "' , escapechar= ' "' , nastring= " NA" ,
117- header= true ) where T <: CSV_or_TSV
115+
116+ function fileio_savestreaming (f:: FileIO.File{T} , data= nothing ; delim= _delim (T), quotechar= ' "' , escapechar= ' "' , nastring= " NA" ,
117+ header= true ) where T<: CSV_or_TSV
118118 io = open (f. filename, " w" )
119119
120- if data!= = nothing
120+ if data != = nothing
121121 _save (io, data; delim= delim, quotechar= quotechar, escapechar= escapechar, nastring= nastring, header= header)
122122 end
123123
124- return CSVFileSaveStream (io, data!= = nothing , delim, quotechar, escapechar, nastring, header)
124+ return CSVFileSaveStream (io, data != = nothing , delim, quotechar, escapechar, nastring, header)
125125end
126126
127- function fileio_savestreaming (s:: FileIO.Stream{T} , data= nothing ; delim= _delim (T), quotechar= ' "' , escapechar= ' "' , nastring= " NA" ,
128- header= false ) where T <: CSV_or_TSV
127+ function fileio_savestreaming (s:: FileIO.Stream{T} , data= nothing ; delim= _delim (T), quotechar= ' "' , escapechar= ' "' , nastring= " NA" ,
128+ header= false ) where T<: CSV_or_TSV
129129
130- if data!= = nothing
130+ if data != = nothing
131131 _save (s. io, data; delim= delim, quotechar= quotechar, escapechar= escapechar, nastring= nastring, header= header)
132132 end
133-
134- return CSVFileSaveStream (s. io, data!= = nothing , delim, quotechar, escapechar, nastring, header)
133+
134+ return CSVFileSaveStream (s. io, data != = nothing , delim, quotechar, escapechar, nastring, header)
135135end
136136
137137function Base. write (s:: CSVFileSaveStream , data)
0 commit comments