summaryrefslogtreecommitdiff
path: root/src/CSV.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/CSV.hs')
-rw-r--r--src/CSV.hs11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/CSV.hs b/src/CSV.hs
index d25a669..05fb472 100644
--- a/src/CSV.hs
+++ b/src/CSV.hs
@@ -5,6 +5,7 @@ module CSV(
specialChars,
defaultSettings,
+ unParseRecord,
parseRecord
) where
@@ -14,6 +15,7 @@ module CSV(
import Text.ParserCombinators.Parsec ( (<|>), (<?>) )
import qualified Text.ParserCombinators.Parsec as Parsec
import qualified Data.Char as Char
+import qualified Data.List as List
@@ -40,6 +42,15 @@ specialChars s = (separator s):(quote s):(escape s):[]
+unParseRecord :: Settings -> [String] -> String
+unParseRecord settings record =
+ let escFunc c = if (c == escape settings || c == quote settings) then (escape settings):c:[] else c:[]
+ escapeField s = ((quote settings) : (concatMap escFunc s)) ++ ((quote settings):[])
+ in List.intercalate [separator settings] (map escapeField record)
+
+
+
+
parseRecord :: Settings -> String -> Either Parsec.ParseError [String]
parseRecord settings input =
Parsec.parse (record settings) "error" input