Copyright | © 2016–2021 Stack Builders |
---|---|
License | MIT |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Synopsis
- newtype ConversionError = ConversionError String
- type Parser = Parsec ConversionError ByteString
- csv :: FromRecord a => DecodeOptions -> Parser (Vector a)
- csvWithHeader :: FromNamedRecord a => DecodeOptions -> Parser (Header, Vector a)
- decodeWithC :: (DecodeOptions -> Parser a) -> DecodeOptions -> HasHeader -> FilePath -> ByteString -> Either (ParseErrorBundle ByteString ConversionError) a
- toNamedRecord :: Header -> Record -> NamedRecord
- header :: Word8 -> Parser Header
- name :: Word8 -> Parser Name
- record :: Word8 -> (Record -> Parser a) -> Parser a
- field :: Word8 -> Parser Field
- escapedField :: Parser ByteString
- unescapedField :: Word8 -> Parser ByteString
Documentation
newtype ConversionError Source #
Custom error component for CSV parsing. It allows typed reporting of conversion errors.
Instances
type Parser = Parsec ConversionError ByteString Source #
Parser type that uses “custom error component” ConversionError
.
:: FromRecord a | |
=> DecodeOptions | Decoding options |
-> Parser (Vector a) | The parser that parses collection of records |
Parse a CSV file that does not include a header.
:: FromNamedRecord a | |
=> DecodeOptions | Decoding options |
-> Parser (Header, Vector a) | The parser that parser collection of named records |
Parse a CSV file that includes a header.
:: (DecodeOptions -> Parser a) | Parsing function parametrized by |
-> DecodeOptions | Decoding options |
-> HasHeader | Whether to expect a header in the input |
-> FilePath | File name (only for displaying in parse error messages, use empty string if you have none) |
-> ByteString | CSV data |
-> Either (ParseErrorBundle ByteString ConversionError) a |
Decode CSV data using the provided parser, skipping a leading header if necessary.
toNamedRecord :: Header -> Record -> NamedRecord Source #
Convert a Record
to a NamedRecord
by attaching column names. The
Header
and Record
must be of the same length.
name :: Word8 -> Parser Name Source #
Parse a header name. Header names have the same format as regular
field
s.
:: Word8 | Field delimiter |
-> (Record -> Parser a) | How to “parse” record to get the data of interest |
-> Parser a |
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.
field :: Word8 -> Parser Field Source #
Parse a field. The field may be in either the escaped or non-escaped format. The returned value is unescaped.
escapedField :: Parser ByteString Source #
Parse an escaped field.
unescapedField :: Word8 -> Parser ByteString Source #
Parse an unescaped field.