diff options
Diffstat (limited to 'src/CSV.hs')
-rw-r--r-- | src/CSV.hs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/CSV.hs b/src/CSV.hs new file mode 100644 index 0000000..80c6d76 --- /dev/null +++ b/src/CSV.hs @@ -0,0 +1,18 @@ +{-# LANGUAGE OverloadedStrings #-} + +module CSV + ( getCsv + ) where + +import Data.Text (Text) +import qualified Data.Text as T + +getCsv :: [[Text]] -> Text +getCsv = T.intercalate "\n" . map (T.intercalate "," . map quote) + +quote :: Text -> Text +quote text = T.concat [ "\"", T.concatMap escape text, "\"" ] + +escape :: Char -> Text +escape '"' = "\"\"" +escape x = T.singleton x |