6 -- Simple implementation of tab-separated values with a trailing newline and no
9 splitList :: Eq a => a -> Bool -> [a] -> [[a]]
10 splitList delim terminated =
11 let sl [] | terminated = []
12 sl l = case break (== delim) l of
14 (hh, {-delim-} _ : t) -> hh : sl t
17 -- We use the Eq only to check the validity...
18 joinList :: Eq a => a -> Bool -> [[a]] -> [a]
19 joinList delim terminated l =
20 if any (any (== delim)) l then error "joinList: item contains delimiter"
22 then concatMap (++ [delim]) l
23 else intercalate [delim] l
27 formatTSV :: TSV -> String
28 formatTSV = joinList '\n' True . map (joinList '\t' False)
30 parseTSV :: String -> TSV
31 parseTSV = map (splitList '\t' False) . splitList '\n' True