Compare commits
2 Commits
22b6942900
...
3bc1be9eb9
Author | SHA1 | Date | |
---|---|---|---|
Jonathan Lamothe | 3bc1be9eb9 | ||
Jonathan Lamothe | d99862b3f4 |
|
@ -1,3 +1,5 @@
|
||||||
# Changelog for csv-sip
|
# Changelog for csv-sip
|
||||||
|
|
||||||
## Unreleased changes
|
## Unreleased changes
|
||||||
|
- changed the types of encodeCSV and encodeRawCSV to make them more generic
|
||||||
|
- slight re-structuring of documentation
|
||||||
|
|
|
@ -52,8 +52,9 @@ module Data.CSV.Sip (
|
||||||
labelFields,
|
labelFields,
|
||||||
decodeRows,
|
decodeRows,
|
||||||
decodeRawRows,
|
decodeRawRows,
|
||||||
decodeUTF8,
|
|
||||||
toBytes,
|
toBytes,
|
||||||
|
-- * Helper Functions
|
||||||
|
decodeUTF8,
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Conduit
|
import Conduit
|
||||||
|
@ -211,12 +212,6 @@ decodeRows = decodeRawRows .| mapC (map $ fromMaybe "" . decodeUTF8)
|
||||||
decodeRawRows :: Monad m => ConduitT BS.ByteString [BS.ByteString] m ()
|
decodeRawRows :: Monad m => ConduitT BS.ByteString [BS.ByteString] m ()
|
||||||
decodeRawRows = toBytes .| evalStateT decodeLoop newDecodeState
|
decodeRawRows = toBytes .| evalStateT decodeLoop newDecodeState
|
||||||
|
|
||||||
-- | decode a raw ByteString into Text (if possible)
|
|
||||||
decodeUTF8 :: BS.ByteString -> Maybe T.Text
|
|
||||||
decodeUTF8 bs = case decodeUtf8' bs of
|
|
||||||
Left _ -> Nothing
|
|
||||||
Right txt -> Just txt
|
|
||||||
|
|
||||||
-- | convert a stream to ByteStrings to a stream of bytes
|
-- | convert a stream to ByteStrings to a stream of bytes
|
||||||
toBytes :: Monad m => ConduitT BS.ByteString Word8 m ()
|
toBytes :: Monad m => ConduitT BS.ByteString Word8 m ()
|
||||||
toBytes = await >>= \case
|
toBytes = await >>= \case
|
||||||
|
@ -226,6 +221,12 @@ toBytes = await >>= \case
|
||||||
toBytes
|
toBytes
|
||||||
Nothing -> return ()
|
Nothing -> return ()
|
||||||
|
|
||||||
|
-- | decode a raw ByteString into Text (if possible)
|
||||||
|
decodeUTF8 :: BS.ByteString -> Maybe T.Text
|
||||||
|
decodeUTF8 bs = case decodeUtf8' bs of
|
||||||
|
Left _ -> Nothing
|
||||||
|
Right txt -> Just txt
|
||||||
|
|
||||||
-- Internal
|
-- Internal
|
||||||
|
|
||||||
data DecodeState = DecodeState
|
data DecodeState = DecodeState
|
||||||
|
|
|
@ -40,8 +40,8 @@ spec = describe "Data.CSV.Sip" $ do
|
||||||
labelFieldsSpec
|
labelFieldsSpec
|
||||||
decodeRowsSpec
|
decodeRowsSpec
|
||||||
decodeRawRowsSpec
|
decodeRawRowsSpec
|
||||||
decodeUTF8Spec
|
|
||||||
toBytesSpec
|
toBytesSpec
|
||||||
|
decodeUTF8Spec
|
||||||
|
|
||||||
encodeCSVSpec :: Spec
|
encodeCSVSpec :: Spec
|
||||||
encodeCSVSpec = describe "encodeCSV" $ do
|
encodeCSVSpec = describe "encodeCSV" $ do
|
||||||
|
@ -327,6 +327,14 @@ decodeRawRowsSpec = describe "decodeRawRows" $ mapM_
|
||||||
, ["baz", "quux"]
|
, ["baz", "quux"]
|
||||||
]
|
]
|
||||||
|
|
||||||
|
toBytesSpec :: Spec
|
||||||
|
toBytesSpec = describe "toBytes" $ let
|
||||||
|
input = ["ab", "cd"]
|
||||||
|
expected = map (fromIntegral . ord) "abcd"
|
||||||
|
in it ("should be " ++ show expected) $ do
|
||||||
|
result <- runConduit $ sourceList input .| toBytes .| consume
|
||||||
|
result `shouldBe` expected
|
||||||
|
|
||||||
decodeUTF8Spec :: Spec
|
decodeUTF8Spec :: Spec
|
||||||
decodeUTF8Spec = describe "decodeUTF8" $ mapM_
|
decodeUTF8Spec = describe "decodeUTF8" $ mapM_
|
||||||
( \(label, input, expected) -> context label $
|
( \(label, input, expected) -> context label $
|
||||||
|
@ -341,12 +349,4 @@ decodeUTF8Spec = describe "decodeUTF8" $ mapM_
|
||||||
, ( "blank", "", Just "" )
|
, ( "blank", "", Just "" )
|
||||||
]
|
]
|
||||||
|
|
||||||
toBytesSpec :: Spec
|
|
||||||
toBytesSpec = describe "toBytes" $ let
|
|
||||||
input = ["ab", "cd"]
|
|
||||||
expected = map (fromIntegral . ord) "abcd"
|
|
||||||
in it ("should be " ++ show expected) $ do
|
|
||||||
result <- runConduit $ sourceList input .| toBytes .| consume
|
|
||||||
result `shouldBe` expected
|
|
||||||
|
|
||||||
--jl
|
--jl
|
||||||
|
|
Loading…
Reference in New Issue
Block a user