csv: fix inferring separator from .ssv/.tsv file extensions
This was documented but untested and may have never worked.
This commit is contained in:
parent
fbf47b85dd
commit
a3c749f9e7
@ -725,10 +725,18 @@ readJournalFromCsv mrulesfile csvfile csvdata =
|
|||||||
Just s -> readDef (throwerr $ "could not parse skip value: " ++ show s) s
|
Just s -> readDef (throwerr $ "could not parse skip value: " ++ show s) s
|
||||||
|
|
||||||
-- parse csv
|
-- parse csv
|
||||||
-- parsec seems to fail if you pass it "-" here TODO: try again with megaparsec
|
let
|
||||||
let parsecfilename = if csvfile == "-" then "(stdin)" else csvfile
|
-- parsec seems to fail if you pass it "-" here TODO: try again with megaparsec
|
||||||
let separator = fromMaybe ',' (getDirective "separator" rules >>= parseSeparator)
|
parsecfilename = if csvfile == "-" then "(stdin)" else csvfile
|
||||||
dbg6IO "separator" separator
|
separator =
|
||||||
|
case getDirective "separator" rules >>= parseSeparator of
|
||||||
|
Just c -> c
|
||||||
|
_ | ext == "ssv" -> ';'
|
||||||
|
_ | ext == "tsv" -> '\t'
|
||||||
|
_ -> ','
|
||||||
|
where
|
||||||
|
ext = map toLower $ drop 1 $ takeExtension csvfile
|
||||||
|
dbg6IO "using separator" separator
|
||||||
records <- (either throwerr id .
|
records <- (either throwerr id .
|
||||||
dbg7 "validateCsv" . validateCsv rules skiplines .
|
dbg7 "validateCsv" . validateCsv rules skiplines .
|
||||||
dbg7 "parseCsv")
|
dbg7 "parseCsv")
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user