diff options
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 |