module Debian.Release
( ReleaseName(..)
, parseReleaseName
, releaseName'
, Section(..)
, SubSection(..)
, sectionName
, sectionName'
, sectionNameOfSubSection
, parseSection
, parseSection'
) where
import Data.Data (Data)
import Data.Typeable (Typeable)
import Network.URI (unEscapeString, escapeURIString, isAllowedInURI)
data ReleaseName = ReleaseName { relName :: String } deriving (Eq, Ord, Read, Show, Data, Typeable)
parseReleaseName :: String -> ReleaseName
parseReleaseName name = ReleaseName {relName = unEscapeString name}
releaseName' :: ReleaseName -> String
releaseName' (ReleaseName {relName = s}) = escapeURIString isAllowedInURI s
newtype Section = Section String deriving (Read, Show, Eq, Ord)
data SubSection = SubSection { section :: Section, subSectionName :: String } deriving (Read, Show, Eq, Ord)
sectionName :: SubSection -> String
sectionName (SubSection (Section "main") y) = y
sectionName (SubSection x y) = sectionName' x ++ "/" ++ y
sectionName' :: Section -> String
sectionName' (Section s) = escapeURIString isAllowedInURI s
sectionNameOfSubSection :: SubSection -> String
sectionNameOfSubSection = sectionName' . section
parseSection :: String -> SubSection
parseSection s =
case span (/= '/') s of
(x, "") -> SubSection (Section "main") x
("main", y) -> SubSection (Section "main") y
(x, y) -> SubSection (Section x) (tail y)
parseSection' :: String -> Section
parseSection' name =
Section (unEscapeString name)