{-# LANGUAGE ScopedTypeVariables #-}
module Data.Csv.Builder
(
encodeHeader
, encodeRecord
, encodeNamedRecord
, encodeDefaultOrderedNamedRecord
, encodeHeaderWith
, encodeRecordWith
, encodeNamedRecordWith
, encodeDefaultOrderedNamedRecordWith
) where
import qualified Data.Monoid as Mon
import Data.ByteString.Builder as Builder
import Data.Csv.Conversion
import qualified Data.Csv.Encoding as Encoding
import Data.Csv.Encoding (EncodeOptions(..))
import Data.Csv.Types hiding (toNamedRecord)
encodeHeader :: Header -> Builder.Builder
= Header -> Builder
forall a. ToRecord a => a -> Builder
encodeRecord
encodeRecord :: ToRecord a => a -> Builder.Builder
encodeRecord :: a -> Builder
encodeRecord = EncodeOptions -> a -> Builder
forall a. ToRecord a => EncodeOptions -> a -> Builder
encodeRecordWith EncodeOptions
Encoding.defaultEncodeOptions
encodeNamedRecord :: ToNamedRecord a =>
Header -> a -> Builder.Builder
encodeNamedRecord :: Header -> a -> Builder
encodeNamedRecord = EncodeOptions -> Header -> a -> Builder
forall a.
ToNamedRecord a =>
EncodeOptions -> Header -> a -> Builder
encodeNamedRecordWith EncodeOptions
Encoding.defaultEncodeOptions
encodeDefaultOrderedNamedRecord ::
(DefaultOrdered a, ToNamedRecord a) => a -> Builder.Builder
encodeDefaultOrderedNamedRecord :: a -> Builder
encodeDefaultOrderedNamedRecord =
EncodeOptions -> a -> Builder
forall a.
(DefaultOrdered a, ToNamedRecord a) =>
EncodeOptions -> a -> Builder
encodeDefaultOrderedNamedRecordWith EncodeOptions
Encoding.defaultEncodeOptions
encodeHeaderWith :: EncodeOptions -> Header -> Builder.Builder
= EncodeOptions -> Header -> Builder
forall a. ToRecord a => EncodeOptions -> a -> Builder
encodeRecordWith
encodeRecordWith :: ToRecord a => EncodeOptions -> a -> Builder.Builder
encodeRecordWith :: EncodeOptions -> a -> Builder
encodeRecordWith EncodeOptions
opts a
r =
Quoting -> Word8 -> Header -> Builder
Encoding.encodeRecord (EncodeOptions -> Quoting
encQuoting EncodeOptions
opts) (EncodeOptions -> Word8
encDelimiter EncodeOptions
opts) (a -> Header
forall a. ToRecord a => a -> Header
toRecord a
r)
Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
Mon.<> Bool -> Builder
Encoding.recordSep (EncodeOptions -> Bool
encUseCrLf EncodeOptions
opts)
encodeNamedRecordWith :: ToNamedRecord a =>
EncodeOptions -> Header -> a -> Builder.Builder
encodeNamedRecordWith :: EncodeOptions -> Header -> a -> Builder
encodeNamedRecordWith EncodeOptions
opts Header
hdr a
nr =
Header -> Quoting -> Word8 -> NamedRecord -> Builder
Encoding.encodeNamedRecord Header
hdr (EncodeOptions -> Quoting
encQuoting EncodeOptions
opts) (EncodeOptions -> Word8
encDelimiter EncodeOptions
opts)
(a -> NamedRecord
forall a. ToNamedRecord a => a -> NamedRecord
toNamedRecord a
nr) Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
Mon.<> Bool -> Builder
Encoding.recordSep (EncodeOptions -> Bool
encUseCrLf EncodeOptions
opts)
encodeDefaultOrderedNamedRecordWith ::
forall a. (DefaultOrdered a, ToNamedRecord a) =>
EncodeOptions -> a -> Builder.Builder
encodeDefaultOrderedNamedRecordWith :: EncodeOptions -> a -> Builder
encodeDefaultOrderedNamedRecordWith EncodeOptions
opts =
EncodeOptions -> Header -> a -> Builder
forall a.
ToNamedRecord a =>
EncodeOptions -> Header -> a -> Builder
encodeNamedRecordWith EncodeOptions
opts (a -> Header
forall a. DefaultOrdered a => a -> Header
headerOrder (a
forall a. HasCallStack => a
undefined :: a))