debian-4.1.2: Modules for working with the Debian package system

Safe Haskell | None
Language | Haskell2010

Debian.Control.String

Contents

- Types
- Control File Parser
- Helper Functions
- Orphan instances

Synopsis

- newtype Control' a = Control [Paragraph' a]
- newtype Paragraph' a = Paragraph [Field' a]
- data Field' a
  - = Field (a, a)
  - | Comment a
- type Control = Control' String
- type Paragraph = Paragraph' String
- type Field = Field' String
- type ControlParser a = CharParser () a
- class ControlFunctions a where
  - parseControlFromFile :: FilePath -> IO (Either ParseError (Control' a))
  - parseControlFromHandle :: String -> Handle -> IO (Either ParseError (Control' a))
  - parseControl :: String -> a -> Either ParseError (Control' a)
  - lookupP :: String -> Paragraph' a -> Maybe (Field' a)
  - stripWS :: a -> a
  - protectFieldText :: a -> a
  - asString :: a -> String
- pControl :: ControlParser Control
- mergeControls :: [Control' a] -> Control' a
- fieldValue :: ControlFunctions a => String -> Paragraph' a -> Maybe a
- removeField :: Eq a => a -> Paragraph' a -> Paragraph' a
- prependFields :: [Field' a] -> Paragraph' a -> Paragraph' a
- appendFields :: [Field' a] -> Paragraph' a -> Paragraph' a
- renameField :: Eq a => a -> a -> Paragraph' a -> Paragraph' a
- modifyField :: Eq a => a -> (a -> a) -> Paragraph' a -> Paragraph' a
- raiseFields :: Eq a => (a -> Bool) -> Paragraph' a -> Paragraph' a

# Types

newtype Control' a Source #

Constructors

Control [Paragraph' a] |

#### Instances

Instances details

(ControlFunctions a, Pretty (PP a)) => Pretty (Control' a) Source # | This may have bad performance issues (dsf: Whoever wrote this comment should have explained why.)
Instance details Defined in Debian.Control.Common Methods pretty :: Control' a -> Doc Source # prettyVersioned :: CabalSpecVersion -> Control' a -> Doc Source #
Read a => Read (Control' a) Source # |
Instance details Defined in Debian.Control.Common Methods readsPrec :: Int -> ReadS (Control' a) Source # readList :: ReadS [Control' a] Source # readPrec :: ReadPrec (Control' a) Source # readListPrec :: ReadPrec [Control' a] Source #
Show a => Show (Control' a) Source # |
Instance details Defined in Debian.Control.Common Methods showsPrec :: Int -> Control' a -> ShowS Source # show :: Control' a -> String Source # showList :: [Control' a] -> ShowS Source #
Eq a => Eq (Control' a) Source # |
Instance details Defined in Debian.Control.Common Methods (==) :: Control' a -> Control' a -> Bool Source # (/=) :: Control' a -> Control' a -> Bool Source #
Ord a => Ord (Control' a) Source # |

Instance details

Defined in Debian.Control.Common

Methods

compare :: Control' a -> Control' a -> Ordering Source #

(<) :: Control' a -> Control' a -> Bool Source #

(<=) :: Control' a -> Control' a -> Bool Source #

(>) :: Control' a -> Control' a -> Bool Source #

(>=) :: Control' a -> Control' a -> Bool Source #

max :: Control' a -> Control' a -> Control' a Source #

min :: Control' a -> Control' a -> Control' a Source #

newtype Paragraph' a Source #

Constructors

Paragraph [Field' a] |

#### Instances

Instances details

(ControlFunctions a, Pretty (PP a)) => Pretty (Paragraph' a) Source # |
Instance details Defined in Debian.Control.Common Methods pretty :: Paragraph' a -> Doc Source # prettyVersioned :: CabalSpecVersion -> Paragraph' a -> Doc Source #
Read a => Read (Paragraph' a) Source # |
Instance details Defined in Debian.Control.Common Methods readsPrec :: Int -> ReadS (Paragraph' a) Source # readList :: ReadS [Paragraph' a] Source # readPrec :: ReadPrec (Paragraph' a) Source # readListPrec :: ReadPrec [Paragraph' a] Source #
Show a => Show (Paragraph' a) Source # |
Instance details Defined in Debian.Control.Common Methods showsPrec :: Int -> Paragraph' a -> ShowS Source # show :: Paragraph' a -> String Source # showList :: [Paragraph' a] -> ShowS Source #
Eq a => Eq (Paragraph' a) Source # |
Instance details Defined in Debian.Control.Common Methods (==) :: Paragraph' a -> Paragraph' a -> Bool Source # (/=) :: Paragraph' a -> Paragraph' a -> Bool Source #
Ord a => Ord (Paragraph' a) Source # |

Instance details

Defined in Debian.Control.Common

Methods

compare :: Paragraph' a -> Paragraph' a -> Ordering Source #

(<) :: Paragraph' a -> Paragraph' a -> Bool Source #

(<=) :: Paragraph' a -> Paragraph' a -> Bool Source #

(>) :: Paragraph' a -> Paragraph' a -> Bool Source #

(>=) :: Paragraph' a -> Paragraph' a -> Bool Source #

max :: Paragraph' a -> Paragraph' a -> Paragraph' a Source #

min :: Paragraph' a -> Paragraph' a -> Paragraph' a Source #

data Field' a Source #

NOTE: we do not strip the leading or trailing whitespace in the name or value

Constructors

Field (a, a) |
Comment a | Lines beginning with #

#### Instances

Instances details

(ControlFunctions a, Pretty (PP a)) => Pretty (Field' a) Source # |
Instance details Defined in Debian.Control.Common Methods pretty :: Field' a -> Doc Source # prettyVersioned :: CabalSpecVersion -> Field' a -> Doc Source #
Read a => Read (Field' a) Source # |
Instance details Defined in Debian.Control.Common Methods readsPrec :: Int -> ReadS (Field' a) Source # readList :: ReadS [Field' a] Source # readPrec :: ReadPrec (Field' a) Source # readListPrec :: ReadPrec [Field' a] Source #
Show a => Show (Field' a) Source # |
Instance details Defined in Debian.Control.Common Methods showsPrec :: Int -> Field' a -> ShowS Source # show :: Field' a -> String Source # showList :: [Field' a] -> ShowS Source #
Eq a => Eq (Field' a) Source # |
Instance details Defined in Debian.Control.Common Methods (==) :: Field' a -> Field' a -> Bool Source # (/=) :: Field' a -> Field' a -> Bool Source #
Ord a => Ord (Field' a) Source # |
Instance details Defined in Debian.Control.Common Methods compare :: Field' a -> Field' a -> Ordering Source # (<) :: Field' a -> Field' a -> Bool Source # (<=) :: Field' a -> Field' a -> Bool Source # (>) :: Field' a -> Field' a -> Bool Source # (>=) :: Field' a -> Field' a -> Bool Source # max :: Field' a -> Field' a -> Field' a Source # min :: Field' a -> Field' a -> Field' a Source #

type Control = Control' String Source #

type Paragraph = Paragraph' String Source #

type Field = Field' String Source #

type ControlParser a = CharParser () a Source #

class ControlFunctions a where Source #

Methods

parseControlFromFile :: FilePath -> IO (Either ParseError (Control' a)) Source #

`parseControlFromFile` `filepath` is a simple wrapper function that parses `filepath` using `pControl`

parseControlFromHandle :: String -> Handle -> IO (Either ParseError (Control' a)) Source #

`parseControlFromHandle` `sourceName` `handle` - `sourceName` is only used for error reporting

parseControl :: String -> a -> Either ParseError (Control' a) Source #

`parseControlFromString` `sourceName` `text` - `sourceName` is only used for error reporting

lookupP :: String -> Paragraph' a -> Maybe (Field' a) Source #

`lookupP` `fieldName paragraph` looks up a `Field` in a `Paragraph`. `N.B.` trailing and leading whitespace is not stripped.

stripWS :: a -> a Source #

Strip the trailing and leading space and tab characters from a string. Folded whitespace is not unfolded. This should probably be moved to someplace more general purpose.

protectFieldText :: a -> a Source #

Protect field value text so the parser doesn't split it into multiple fields or paragraphs. This must modify all field text to enforce two conditions: (1) All lines other than the initial one must begin with a space or a tab, and (2) the trailing white space must not contain newlines. This is called before pretty printing to prevent the parser from misinterpreting field text as multiple fields or paragraphs.

asString :: a -> String Source #

#### Instances

Instances details

ControlFunctions ByteString Source # |

Instance details

Defined in Debian.Control.ByteString

Methods

parseControlFromFile :: FilePath -> IO (Either ParseError (Control' ByteString)) Source #

parseControlFromHandle :: String -> Handle -> IO (Either ParseError (Control' ByteString)) Source #

parseControl :: String -> ByteString -> Either ParseError (Control' ByteString) Source #

lookupP :: String -> Paragraph' ByteString -> Maybe (Field' ByteString) Source #

stripWS :: ByteString -> ByteString Source #

protectFieldText :: ByteString -> ByteString Source #

asString :: ByteString -> String Source #

ControlFunctions Text Source # |

Instance details

Defined in Debian.Control.Text

Methods

parseControlFromFile :: FilePath -> IO (Either ParseError (Control' Text)) Source #

parseControlFromHandle :: String -> Handle -> IO (Either ParseError (Control' Text)) Source #

parseControl :: String -> Text -> Either ParseError (Control' Text) Source #

lookupP :: String -> Paragraph' Text -> Maybe (Field' Text) Source #

stripWS :: Text -> Text Source #

protectFieldText :: Text -> Text Source #

asString :: Text -> String Source #

ControlFunctions Builder Source # |

Instance details

Defined in Debian.Control.Builder

Methods

parseControlFromFile :: FilePath -> IO (Either ParseError (Control' Builder)) Source #

parseControlFromHandle :: String -> Handle -> IO (Either ParseError (Control' Builder)) Source #

parseControl :: String -> Builder -> Either ParseError (Control' Builder) Source #

lookupP :: String -> Paragraph' Builder -> Maybe (Field' Builder) Source #

stripWS :: Builder -> Builder Source #

protectFieldText :: Builder -> Builder Source #

asString :: Builder -> String Source #

ControlFunctions Text Source # |

Instance details

Defined in Debian.Control.TextLazy

Methods

parseControlFromFile :: FilePath -> IO (Either ParseError (Control' Text)) Source #

parseControlFromHandle :: String -> Handle -> IO (Either ParseError (Control' Text)) Source #

parseControl :: String -> Text -> Either ParseError (Control' Text) Source #

lookupP :: String -> Paragraph' Text -> Maybe (Field' Text) Source #

stripWS :: Text -> Text Source #

protectFieldText :: Text -> Text Source #

asString :: Text -> String Source #

ControlFunctions String Source # |

Instance details

Defined in Debian.Control.String

Methods

parseControlFromFile :: FilePath -> IO (Either ParseError (Control' String)) Source #

parseControlFromHandle :: String -> Handle -> IO (Either ParseError (Control' String)) Source #

parseControl :: String -> String -> Either ParseError (Control' String) Source #

lookupP :: String -> Paragraph' String -> Maybe (Field' String) Source #

stripWS :: String -> String Source #

protectFieldText :: String -> String Source #

asString :: String -> String Source #

# Control File Parser

pControl :: ControlParser Control Source #

A parser for debian control file. This parser handles control files that end without a newline as well as ones that have several blank lines at the end. It is very liberal and does not attempt validate the fields in any way. All trailing, leading, and folded whitespace is preserved in the field values. See `stripWS`.

# Helper Functions

mergeControls :: [Control' a] -> Control' a Source #

fieldValue :: ControlFunctions a => String -> Paragraph' a -> Maybe a Source #

removeField :: Eq a => a -> Paragraph' a -> Paragraph' a Source #

prependFields :: [Field' a] -> Paragraph' a -> Paragraph' a Source #

appendFields :: [Field' a] -> Paragraph' a -> Paragraph' a Source #

renameField :: Eq a => a -> a -> Paragraph' a -> Paragraph' a Source #

modifyField :: Eq a => a -> (a -> a) -> Paragraph' a -> Paragraph' a Source #

raiseFields :: Eq a => (a -> Bool) -> Paragraph' a -> Paragraph' a Source #

Move selected fields to the beginning of a paragraph.

# Orphan instances

ControlFunctions String Source # |

Instance details

Methods

parseControlFromFile :: FilePath -> IO (Either ParseError (Control' String)) Source #

parseControlFromHandle :: String -> Handle -> IO (Either ParseError (Control' String)) Source #

parseControl :: String -> String -> Either ParseError (Control' String) Source #

lookupP :: String -> Paragraph' String -> Maybe (Field' String) Source #

stripWS :: String -> String Source #

protectFieldText :: String -> String Source #

asString :: String -> String Source #