[Pkg-haskell-commits] [SCM] haskell-testpack branch, master, updated. debian/1.0.2-1-4-gb0d6b36
John Goerzen
jgoerzen at complete.org
Fri Apr 23 14:59:02 UTC 2010
The following commit has been merged in the master branch:
commit 0cd479e764a91055c5688b7700c3cf95a79b0070
Author: John Goerzen <jgoerzen at complete.org>
Date: Fri May 13 23:49:31 2005 +0100
Added CSV generation support
diff --git a/MissingH/Str/CSV.hs b/MissingH/Str/CSV.hs
index 357e376..ba9b469 100644
--- a/MissingH/Str/CSV.hs
+++ b/MissingH/Str/CSV.hs
@@ -31,8 +31,9 @@ Haskell Parsec parsers for comma-separated value (CSV) files.
Written by John Goerzen, jgoerzen\@complete.org
-}
-module MissingH.Str.CSV(csvFile) where
+module MissingH.Str.CSV(csvFile, genCsvFile) where
import Text.ParserCombinators.Parsec
+import Data.List
eol = (try $ string "\n\r") <|> (try $ string "\r\n") <|> string "\n" <|>
string "\r" <?> "End of line"
@@ -88,3 +89,19 @@ For more details, see the Parsec information.
csvFile :: CharParser st [[String]]
csvFile = endBy line eol
+
+{- | Generate CSV data for a file. The resulting string can be
+written out to disk directly. -}
+genCsvFile :: [[String]] -> String
+genCsvFile inp =
+ unlines . map csvline $ inp
+ where csvline :: [String] -> String
+ csvline l = concat . intersperse "," . map csvcells $ l
+ csvcells :: String -> String
+ csvcells "" = ""
+ csvcells c = '"' : convcell c ++ "\""
+ convcell :: String -> String
+ convcell c = concatMap convchar c
+ convchar '"' = "\"\""
+ convchar x = [x]
+
\ No newline at end of file
--
haskell-testpack
More information about the Pkg-haskell-commits
mailing list