1+ function _writevalue (io:: IO , value:: String , delim, quotechar:: Nothing , escapechar, nastring)
2+ print (io, value)
3+ end
4+
15function _writevalue (io:: IO , value:: String , delim, quotechar, escapechar, nastring)
2- if isnull (quotechar)
3- print (io, value)
4- else
5- quotechar_unpacked = get (quotechar)
6- print (io, quotechar_unpacked)
7- for c in value
8- if c== quotechar_unpacked || c== escapechar
9- print (io, escapechar)
10- end
11- print (io, c)
6+ print (io, quotechar)
7+ for c in value
8+ if c== quotechar || c== escapechar
9+ print (io, escapechar)
1210 end
13- print (io, quotechar_unpacked )
11+ print (io, c )
1412 end
13+ print (io, quotechar)
1514end
1615
1716function _writevalue (io:: IO , value, delim, quotechar, escapechar, nastring)
1817 print (io, value)
1918end
2019
21- function _writevalue {T} (io:: IO , value:: DataValue{T} , delim, quotechar, escapechar, nastring)
22- if isnull (value)
20+ function _writevalue (io:: IO , value:: DataValue{T} , delim, quotechar, escapechar, nastring) where {T}
21+ if isna (value)
2322 print (io, nastring)
2423 else
2524 _writevalue (io, get (value), delim, quotechar, escapechar, nastring)
2625 end
2726end
2827
2928
30- @generated function _writecsv {T} (io:: IO , it, :: Type{T} , delim, quotechar, escapechar, nastring)
29+ @generated function _writecsv (io:: IO , it, :: Type{T} , delim, quotechar, escapechar, nastring) where {T}
3130 col_names = fieldnames (T)
3231 n = length (col_names)
3332 push_exprs = Expr (:block )
@@ -50,19 +49,17 @@ function _save(io, data; delim=',', quotechar='"', escapechar='\\', nastring="NA
5049 isiterabletable (data) || error (" Can't write this data to a CSV file." )
5150
5251 it = getiterator (data)
53- colnames = TableTraits. column_names (it)
54-
55- quotechar_internal = quotechar== nothing ? Nullable {Char} () : Nullable {Char} (quotechar)
52+ colnames = collect (eltype (it). parameters[1 ])
5653
5754 if header
58- if isnull (quotechar_internal)
55+ if quotechar === nothing
5956 join (io,[string (colname) for colname in colnames],delim)
6057 else
61- 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)
6259 end
6360 println (io)
6461 end
65- _writecsv (io, it, eltype (it), delim, quotechar_internal , escapechar, nastring)
62+ _writecsv (io, it, eltype (it), delim, quotechar , escapechar, nastring)
6663end
6764
6865function _save (filename:: AbstractString , data; delim= ' ,' , quotechar= ' "' , escapechar= ' \\ ' , nastring= " NA" , header= true )
0 commit comments