siphon-0.6: Encode and decode CSV files

Safe HaskellNone
LanguageHaskell2010

Siphon.Internal

Description

A CSV parser. The parser defined here is RFC 4180 compliant, with the following extensions:

  • Empty lines are ignored.
  • Non-escaped fields may contain any characters except double-quotes, commas, carriage returns, and newlines.
  • Escaped fields may contain any characters (but double-quotes need to be escaped).

The functions in this module can be used to implement e.g. a resumable parser that is fed input incrementally.

Synopsis

Documentation

escapeAlways :: ByteString -> Escaped ByteString Source #

This implementation is definitely suboptimal. A better option (which would waste a little space but would be much faster) would be to build the new bytestring by writing to a buffer directly.

sepByDelim1' Source #

Arguments

:: Parser a 
-> Word8

Field delimiter

-> Parser [a] 

Specialized version of sepBy1' which is faster due to not accepting an arbitrary separator.

sepByEndOfLine1' :: Parser a -> Parser [a] Source #

Specialized version of sepBy1' which is faster due to not accepting an arbitrary separator.

row Source #

Arguments

:: Word8

Field delimiter

-> Parser (Vector ByteString) 

Parse a record, not including the terminating line separator. The terminating line separate is not included as the last record in a CSV file is allowed to not have a terminating line separator. You most likely want to use the endOfLine parser in combination with this parser.

rowNoNewline Source #

Arguments

:: Word8

Field delimiter

-> Parser (Vector ByteString) 

field :: Word8 -> Parser ByteString Source #

Parse a field. The field may be in either the escaped or non-escaped format. The return value is unescaped.

unescape :: Parser ByteString Source #

This could be improved. We could avoid the builder and just write to a buffer directly.

(<$!>) :: Monad m => (a -> b) -> m a -> m b infixl 4 Source #

A strict version of <$> for monads.

blankLine :: Vector ByteString -> Bool Source #

Is this an empty record (i.e. a blank line)?

liftM2' :: Monad m => (a -> b -> c) -> m a -> m b -> m c Source #

A version of liftM2 that is strict in the result of its first action.

endOfLine :: Parser () Source #

Match either a single newline character '\n', or a carriage return followed by a newline character "\r\n", or a single carriage return '\r'.