module Data.Csv.Util
( (<$!>)
, blankLine
, liftM2'
, endOfLine
, doubleQuote
, newline
, cr
) where
import Control.Applicative ((<|>), (*>))
import Data.Word (Word8)
import Data.Attoparsec.ByteString.Char8 (string)
import qualified Data.Attoparsec as A
import qualified Data.ByteString as B
import qualified Data.Vector as V
import Data.Attoparsec (Parser)
(<$!>) :: Monad m => (a -> b) -> m a -> m b
f <$!> m = do
a <- m
return $! f a
infixl 4 <$!>
blankLine :: V.Vector B.ByteString -> Bool
blankLine v = V.length v == 1 && (B.null (V.head v))
liftM2' :: (Monad m) => (a -> b -> c) -> m a -> m b -> m c
liftM2' f a b = do
!x <- a
y <- b
return (f x y)
endOfLine :: Parser ()
endOfLine = (A.word8 newline *> return ()) <|> (string "\r\n" *> return ()) <|> (A.word8 cr *> return ())
doubleQuote, newline, cr :: Word8
doubleQuote = 34
newline = 10
cr = 13