module NoSlow.Util.Tag ( Tag(..), Sort(..), split ) where import NoSlow.Util.Base ( Sort(..) ) data Tag = Tag { tagLibrary :: String , tagSubsystem :: String , tagGroup :: String , tagName :: String } deriving( Eq, Ord ) instance Show Tag where showsPrec _ t = showString (tagLibrary t) . showChar '/' . (if null (tagSubsystem t) then id else showString (tagSubsystem t) . showChar '/') . showString (tagGroup t) . (if null (tagName t) then id else showChar '/' . showString (tagName t)) instance Read Tag where readsPrec _ s = case split '/' s of [lib, sub, grp, name] -> [(mk_tag lib sub grp name, "")] [lib, grp, name] -> [(mk_tag lib "" grp name, "")] _ -> [] where mk_tag lib sub grp name = Tag { tagLibrary = lib , tagSubsystem = sub , tagGroup = grp , tagName = name } split :: Char -> String -> [String] split c xs = case span (/= c) xs of (ys,[]) -> [ys] (ys, _ : zs) -> ys : split c zs