diff options
author | Jed Barber <jjbarber@y7mail.com> | 2017-01-19 22:50:37 +1100 |
---|---|---|
committer | Jed Barber <jjbarber@y7mail.com> | 2017-01-19 22:50:37 +1100 |
commit | e9547849b87d078e476cdc10568559bf278dba7b (patch) | |
tree | 6c56ec96fdb8404fa29576f1843b0e931144de61 /src/CSV.hs | |
parent | b66e9234fa0162a1035138891d88ad85f00950f6 (diff) |
Election functionality added, completely untested
Diffstat (limited to 'src/CSV.hs')
-rw-r--r-- | src/CSV.hs | 11 |
1 files changed, 11 insertions, 0 deletions
@@ -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 |