5
5
function _writevalue (io:: IO , value:: AbstractString , delim, quotechar, escapechar, nastring)
6
6
print (io, quotechar)
7
7
for c in value
8
- if c== quotechar || c== escapechar
8
+ if c == quotechar || c == escapechar
9
9
print (io, escapechar)
10
10
end
11
11
print (io, c)
31
31
n = length (col_names)
32
32
push_exprs = Expr (:block )
33
33
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) ))
37
37
end
38
38
end
39
- push! (push_exprs. args, :( println (io) ))
39
+ push! (push_exprs. args, :(println (io)))
40
40
41
41
quote
42
42
for i in it
@@ -52,10 +52,10 @@ function _save(io, data; delim=',', quotechar='"', escapechar='"', nastring="NA"
52
52
colnames = collect (eltype (it). parameters[1 ])
53
53
54
54
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)
57
57
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)
59
59
end
60
60
println (io)
61
61
end
@@ -69,11 +69,11 @@ function _save(filename::AbstractString, data; delim=',', quotechar='"', escapec
69
69
70
70
if ext == " gz" # Gzipped
71
71
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)
73
73
end
74
74
else
75
75
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)
77
77
end
78
78
end
79
79
end
99
99
#
100
100
# Streaming version writes header (if any) on first call, then appends on subsequent calls.
101
101
#
102
- const CSV_or_TSV = Union{FileIO. format " CSV" , FileIO. format " TSV" }
102
+ const CSV_or_TSV = Union{FileIO. format " CSV" ,FileIO. format " TSV" }
103
103
104
104
_delim (T) = T <: FileIO.format"CSV" ? ' ,' : ' \t '
105
105
@@ -112,26 +112,26 @@ mutable struct CSVFileSaveStream{T}
112
112
nastring:: AbstractString
113
113
header:: Bool
114
114
end
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
118
118
io = open (f. filename, " w" )
119
119
120
- if data!= = nothing
120
+ if data != = nothing
121
121
_save (io, data; delim= delim, quotechar= quotechar, escapechar= escapechar, nastring= nastring, header= header)
122
122
end
123
123
124
- return CSVFileSaveStream (io, data!= = nothing , delim, quotechar, escapechar, nastring, header)
124
+ return CSVFileSaveStream (io, data != = nothing , delim, quotechar, escapechar, nastring, header)
125
125
end
126
126
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
129
129
130
- if data!= = nothing
130
+ if data != = nothing
131
131
_save (s. io, data; delim= delim, quotechar= quotechar, escapechar= escapechar, nastring= nastring, header= header)
132
132
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)
135
135
end
136
136
137
137
function Base. write (s:: CSVFileSaveStream , data)
0 commit comments