module Data.Sv.Encode.Options (
EncodeOptions (EncodeOptions, _encodeSeparator, _quoting, _newline, _terminalNewline)
, HasEncodeOptions (encodeOptions, quoting, newline, terminalNewline)
, HasSeparator (separator)
, Quoting (..)
, defaultEncodeOptions
) where
import Control.Lens (Lens')
import Data.Sv.Structure.Newline (Newline, lf)
import Data.Sv.Structure.Separator (Separator, HasSeparator (separator), comma)
data Quoting
= Always
| AsNeeded
| Never
data EncodeOptions =
EncodeOptions {
_encodeSeparator :: Separator
, _quoting :: Quoting
, _newline :: Newline
, _terminalNewline :: Bool
}
class HasSeparator c => HasEncodeOptions c where
encodeOptions :: Lens' c EncodeOptions
quoting :: Lens' c Quoting
{-# INLINE quoting #-}
newline :: Lens' c Newline
{-# INLINE newline #-}
terminalNewline :: Lens' c Bool
{-# INLINE terminalNewline #-}
newline = encodeOptions . newline
quoting = encodeOptions . quoting
terminalNewline = encodeOptions . terminalNewline
instance HasSeparator EncodeOptions where
separator f (EncodeOptions x1 x2 x3 x4) =
fmap (\ y -> EncodeOptions y x2 x3 x4) (f x1)
{-# INLINE separator #-}
instance HasEncodeOptions EncodeOptions where
encodeOptions = id
{-# INLINE encodeOptions #-}
quoting f (EncodeOptions x1 x2 x3 x4) =
fmap (\ y -> EncodeOptions x1 y x3 x4) (f x2)
{-# INLINE quoting #-}
newline f (EncodeOptions x1 x2 x3 x4) =
fmap (\ y -> EncodeOptions x1 x2 y x4) (f x3)
{-# INLINE newline #-}
terminalNewline f (EncodeOptions x1 x2 x3 x4) =
fmap (EncodeOptions x1 x2 x3) (f x4)
{-# INLINE terminalNewline #-}
defaultEncodeOptions :: EncodeOptions
defaultEncodeOptions = EncodeOptions comma AsNeeded lf False