ini 0.3.3 → 0.3.4
raw patch · 2 files changed
+17/−4 lines, 2 filesdep ~base
Dependency ranges changed: base
Files
- ini.cabal +1/−1
- src/Data/Ini.hs +16/−3
ini.cabal view
@@ -1,5 +1,5 @@ name: ini-version: 0.3.3+version: 0.3.4 synopsis: Quick and easy configuration files in the INI format. description: Quick and easy configuration files in the INI format. license: BSD3
src/Data/Ini.hs view
@@ -44,6 +44,8 @@ ,lookupValue ,readValue ,parseValue+ ,sections+ ,keys -- * Writing ,printIni ,writeIniFile@@ -62,7 +64,7 @@ ) where -import Control.Applicative (many, (<*))+import Control.Applicative (many) import Control.Monad import Data.Attoparsec.Combinator import Data.Attoparsec.Text@@ -97,6 +99,17 @@ Nothing -> Left ("Couldn't find key: " ++ T.unpack key) Just value -> return value +-- | Get the sections in the config.+sections :: Ini -> [Text]+sections (Ini ini) = M.keys ini++-- | Get the keys in a section.+keys :: Text -> Ini -> Either String [Text]+keys name (Ini ini) =+ case M.lookup name ini of+ Nothing -> Left ("Couldn't find section: " ++ T.unpack name)+ Just section -> Right (M.keys section)+ -- | Read a value using a reader from "Data.Text.Read". readValue :: Text -> Text -> (Text -> Either String (a, Text)) -> Ini@@ -142,8 +155,8 @@ -- | Print an INI config. printIniWith :: WriteIniSettings -> Ini -> Text-printIniWith wis (Ini sections) =- T.concat (map buildSection (M.toList sections))+printIniWith wis (Ini ini) =+ T.concat (map buildSection (M.toList ini)) where buildSection (name,pairs) = "[" <> name <> "]\n" <> T.concat (map buildPair (M.toList pairs))