    {-# LANGUAGE OverloadedStrings #-}
    -- |A module for working with Debian control files <http://www.debian.org/doc/debian-policy/ch-controlfields.html>
    module Debian.Control
        ( -- * Types
          Control'(..)
        , Paragraph'(..)
        , Field'(..)
        , Control
        , Paragraph
        , Field
        , ControlParser
        , ControlFunctions(..)
        -- * Control File Parser
        , pControl
        -- * Helper Functions
        , mergeControls
        , fieldValue
        , removeField
        , prependFields
        , appendFields
        , renameField
        , modifyField
        , raiseFields
        , packParagraph
        , packField
        , formatControl
        , formatParagraph
        , formatField
        -- * Policy classes and functions
        , P.HasDebianControl(..)
        , P.ControlFileError(..)
        , P.parseDebianControlFromFile
        , P.validateDebianControl
        , P.unsafeDebianControl
        , P.debianSourceParagraph
        , P.debianBinaryParagraphs
        , P.debianPackageParagraphs
        , P.debianPackageNames
        , P.debianSourcePackageName
        , P.debianBinaryPackageNames
        , P.debianRelations
        , P.debianBuildDeps
        , P.debianBuildDepsIndep
        ) where

    --import Control.Monad
    --import Data.List
    --import Text.ParserCombinators.Parsec
    --import System.IO
    import Debian.Control.Common
    import Debian.Control.String
    import Data.List
    import Data.Text as T (Text, pack, concat)
    import qualified Debian.Control.Builder ()
    import qualified Debian.Control.Text as T
    --import qualified Debian.Control.TextLazy as TL
    import qualified Debian.Control.ByteString as B ()
    import qualified Debian.Control.Policy as P
    import qualified Debian.Control.String as S

    packParagraph :: S.Paragraph -> T.Paragraph
    packParagraph :: Paragraph -> Paragraph
    packParagraph (S.Paragraph [Field' String]
    s) = [Field' Text] -> Paragraph
    forall a. [Field' a] -> Paragraph' a
    T.Paragraph ((Field' String -> Field' Text) -> [Field' String] -> [Field' Text]
    forall a b. (a -> b) -> [a] -> [b]
    map Field' String -> Field' Text
    packField [Field' String]
    s)

    packField :: Field' String -> Field' Text
    packField :: Field' String -> Field' Text
    packField (S.Field (String
    name, String
    value)) = (Text, Text) -> Field' Text
    forall a. (a, a) -> Field' a
    T.Field (String -> Text
    T.pack String
    name, String -> Text
    T.pack String
    value)
    packField (S.Comment String
    s) = Text -> Field' Text
    forall a. a -> Field' a
    T.Comment (String -> Text
    T.pack String
    s)

    formatControl :: Control' Text -> [Text]
    formatControl :: Control' Text -> [Text]
    formatControl (T.Control [Paragraph]
    paragraphs) = Text -> [Text] -> [Text]
    forall a. a -> [a] -> [a]
    intersperse (String -> Text
    T.pack String
    "\n") ([Text] -> [Text])
    -> ([Paragraph] -> [Text]) -> [Paragraph] -> [Text]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Paragraph -> Text) -> [Paragraph] -> [Text]
    forall a b. (a -> b) -> [a] -> [b]
    map Paragraph -> Text
    formatParagraph ([Paragraph] -> [Text]) -> [Paragraph] -> [Text]
    forall a b. (a -> b) -> a -> b
    $ [Paragraph]
    paragraphs

    formatParagraph :: Paragraph' Text -> Text
    formatParagraph :: Paragraph -> Text
    formatParagraph (T.Paragraph [Field' Text]
    fields) = [Text] -> Text
    T.concat ([Text] -> Text)
    -> ([Field' Text] -> [Text]) -> [Field' Text] -> Text
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Field' Text -> Text) -> [Field' Text] -> [Text]
    forall a b. (a -> b) -> [a] -> [b]
    map Field' Text -> Text
    formatField ([Field' Text] -> Text) -> [Field' Text] -> Text
    forall a b. (a -> b) -> a -> b
    $ [Field' Text]
    fields

    formatField :: Field' Text -> Text
    formatField :: Field' Text -> Text
    formatField (T.Field (Text
    name, Text
    value)) = [Text] -> Text
    T.concat [Text
    name, String -> Text
    T.pack String
    ":", Text
    value, String -> Text
    T.pack String
    "\n"]
    formatField (T.Comment Text
    s) = Text
    s