Convert CSV records to TSV: Difference between revisions

m
use a file
m (handle \r)
m (use a file)
Line 258:
end
 
const testfile = "test.tmp"
for test_string in [
fh = open(testfile, "w")
"""a,"b\"""",
 
"""\"a","b""c\"""",
write(fh, "","
"a,a",b"
"a",\"b""c",
 
" a , \"b\"",
,a
"""\"12",34""",
a,"
"a\tb,", # That is a TAB character
" a , \"b\"",
raw"a\tb", # That is not
"12",34
raw"a\n\rb",
a\tb, TAB
"a\0b", # That is a NUL character
a\\tb
"a\nb", # That is a LF (linefeed) character
a\\n\\rb
"a\rb", # That is a CR (carriage return) character
a\0b, NUL
raw"a\b"]
a\rb, RETURN
a\\b""")
 
close(fh)
 
for test_string in split(read(testfile, String), "\n")
csv, tsv = csv_tsv(test_string)
println(lpad(csv, 12), " => ", tsv)
Line 285 ⟶ 291:
a , "b" => a <TAB>b
"12",34 => 12<TAB>34
a\tb, TAB => a\tb<TAB> TAB
a\\tb => a\\tb
a\\n\\rb => a\\n\\rb
a\0b, NUL => a\0b<TAB> NUL
a\rb, RETURN => a\rb<TAB> RETURN
a\nb => a\nb
a\rb => a\rb
a\\b => a\\b
</pre>
4,102

edits