aboutsummaryrefslogtreecommitdiff
path: root/src/CSV.hs
blob: 80c6d7640b6d86a5cf2315d5036fea4affd403ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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