properly escape carriage returns

This commit is contained in:
Andrew Martin 2016-07-05 10:01:04 -04:00
parent 3bfd8265bc
commit e17df21a2b
2 changed files with 9 additions and 9 deletions

View File

@ -40,8 +40,8 @@ import Control.Applicative
import Data.Monoid
byteStringChar8 :: Siphon ByteString
byteStringChar8 = Siphon
escape
byteStringChar8 = Siphon
escape
encodeRow
(A.parse (row comma))
B.null
@ -54,7 +54,7 @@ encodeRow = id
. coerce
escape :: ByteString -> Escaped ByteString
escape t = case B.find (\c -> c == newline || c == comma || c == doubleQuote) t of
escape t = case B.find (\c -> c == newline || c == cr || c == comma || c == doubleQuote) t of
Nothing -> Escaped t
Just _ -> escapeAlways t

View File

@ -30,9 +30,9 @@ main = defaultMain tests
tests :: [Test]
tests =
[ testGroup "ByteString encode/decode"
[ testGroup "ByteString encode/decode"
[ testCase "Headless Encoding (int,char,bool)" testEncodingA
, testProperty "Headless Isomorphism (int,char,bool)"
, testProperty "Headless Isomorphism (int,char,bool)"
$ propIsoPipe $
(SE.pipe SC.byteStringChar8 encodingA)
>->
@ -64,7 +64,7 @@ byteStringEncodeChar = BC8.singleton
byteStringEncodeInt :: Int -> ByteString
byteStringEncodeInt = LByteString.toStrict
. Builder.toLazyByteString
. Builder.toLazyByteString
. Builder.intDec
byteStringEncodeBool :: Bool -> ByteString
@ -84,7 +84,7 @@ encodingA = contramap tripleToPairs
$ divided (Encoding.headless byteStringEncodeInt)
$ divided (Encoding.headless byteStringEncodeChar)
$ divided (Encoding.headless byteStringEncodeBool)
$ conquered
$ conquered
tripleToPairs :: (a,b,c) -> (a,(b,(c,())))
tripleToPairs (a,b,c) = (a,(b,(c,())))
@ -93,8 +93,8 @@ propIsoPipe :: Eq a => Pipe a a Identity () -> [a] -> Bool
propIsoPipe p as = (Pipes.toList $ each as >-> p) == as
testEncodingA :: Assertion
testEncodingA =
( ByteString.concat $ Pipes.toList $
testEncodingA =
( ByteString.concat $ Pipes.toList $
Pipes.yield (4,'c',False) >-> SE.pipe SC.byteStringChar8 encodingA
) @?= "4,c,false\n"