From c4eb771fa09e3972106d80ada6b3c4a023b85249 Mon Sep 17 00:00:00 2001 From: Joris Date: Sun, 30 Aug 2015 21:17:27 +0200 Subject: Fetch perfumes according to multiple materials --- src/CSV.hs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/CSV.hs (limited to 'src/CSV.hs') 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 -- cgit v1.2.3