Permalink
Browse files

Revert "Add an option to skip the header in decodeWith"

I will investigate another design.

This reverts commit 8827bc2.
  • Loading branch information...
1 parent 0091ae4 commit 149a2e67fcebed5da5e013e80335da43279df176 @tibbe committed Aug 30, 2012
Showing with 2 additions and 21 deletions.
  1. +0 −2 Data/Csv/Encoding.hs
  2. +2 −19 Data/Csv/Parser.hs
View
@@ -57,8 +57,6 @@ import Data.Csv.Types
-- | Efficiently deserialize CSV records from a lazy 'L.ByteString'.
-- If this fails due to incomplete or invalid input, @'Left' msg@ is
-- returned. Equivalent to @'decodeWith' 'defaultDecodeOptions'@.
---
--- Use the 'decSkipHeader' and 'decodeWith' if the input has a header.
decode :: FromRecord a => L.ByteString -> Either String (Vector a)
decode = decodeWith defaultDecodeOptions
{-# INLINE decode #-}
View
@@ -27,7 +27,6 @@ module Data.Csv.Parser
import Blaze.ByteString.Builder (fromByteString, toByteString)
import Blaze.ByteString.Builder.Char.Utf8 (fromChar)
import Control.Applicative
-import Control.Monad (when)
import Data.Attoparsec.Char8 hiding (Parser, Result, parse)
import qualified Data.Attoparsec as A
import qualified Data.Attoparsec.Lazy as AL
@@ -47,25 +46,17 @@ import Data.Csv.Types
data DecodeOptions = DecodeOptions
{ -- | Field delimiter.
decDelimiter :: {-# UNPACK #-} !Word8
-
- -- | If 'True', the CSV file must have a header and this header
- -- will be skipped.
- , decSkipHeader :: !Bool
}
-- | Decoding options for parsing CSV files.
defaultDecodeOptions :: DecodeOptions
defaultDecodeOptions = DecodeOptions
- { decDelimiter = 44 -- comma
- , decSkipHeader = False
+ { decDelimiter = 44 -- comma
}
-- | Parse a CSV file that does not include a header.
csv :: DecodeOptions -> AL.Parser Csv
csv !opts = do
- when (decSkipHeader opts) $ do
- _ <- header (decDelimiter opts)
- return ()
vals <- record (decDelimiter opts) `sepBy1` endOfLine
_ <- optional endOfLine
endOfInput
@@ -75,11 +66,7 @@ csv !opts = do
-- | Parse a CSV file that includes a header.
csvWithHeader :: DecodeOptions -> AL.Parser (Header, V.Vector NamedRecord)
-csvWithHeader !opts
- | decSkipHeader opts = moduleError "csvWithHeader" $
- "decSkipHeader must not be used together with " ++
- "header-based parsing"
-csvWithHeader opts = do
+csvWithHeader !opts = do
hdr <- header (decDelimiter opts)
vals <- map (toNamedRecord hdr) . removeBlankLines <$>
(record (decDelimiter opts)) `sepBy1` endOfLine
@@ -168,7 +155,3 @@ doubleQuote, newline, cr :: Word8
doubleQuote = 34
newline = 10
cr = 13
-
-moduleError :: String -> String -> a
-moduleError func msg = error $ "Data.Csv.Parser." ++ func ++ ": " ++ msg
-{-# NOINLINE moduleError #-}

0 comments on commit 149a2e6

Please sign in to comment.