module Waargonaut.Encode.Builder.Whitespace
( whitespaceBuilder
, wsBuilder
, wsRemover
) where
import Data.Monoid (Monoid)
import Waargonaut.Types.Whitespace (WS (..), Whitespace (..))
import Waargonaut.Encode.Builder.Types (Builder (..))
whitespaceBuilder :: Monoid b => Builder t b -> Whitespace -> b
whitespaceBuilder bldr Space = fromChar bldr ' '
whitespaceBuilder bldr HorizontalTab = fromChar bldr '\t'
whitespaceBuilder bldr LineFeed = fromChar bldr '\f'
whitespaceBuilder bldr CarriageReturn = fromChar bldr '\r'
whitespaceBuilder bldr NewLine = fromChar bldr '\n'
{-# INLINE whitespaceBuilder #-}
wsBuilder :: Monoid b => Builder t b -> WS -> b
wsBuilder bldr (WS ws) = foldMap (whitespaceBuilder bldr) ws
{-# INLINE wsBuilder #-}
wsRemover :: Monoid b => Builder t b -> WS -> b
wsRemover _ = const mempty
{-# INLINE wsRemover #-}