aboutsummaryrefslogtreecommitdiff
path: root/src/CSV.hs
diff options
context:
space:
mode:
authorJoris2015-08-30 21:17:27 +0200
committerJoris2015-08-30 21:17:27 +0200
commitc4eb771fa09e3972106d80ada6b3c4a023b85249 (patch)
tree9214b64628e34089b73ff6b4bdcb0edbc668a51e /src/CSV.hs
downloadperfume-c4eb771fa09e3972106d80ada6b3c4a023b85249.tar.gz
perfume-c4eb771fa09e3972106d80ada6b3c4a023b85249.tar.bz2
perfume-c4eb771fa09e3972106d80ada6b3c4a023b85249.zip
Fetch perfumes according to multiple materials
Diffstat (limited to 'src/CSV.hs')
-rw-r--r--src/CSV.hs18
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