packages feed

SConfig 0.1.0.0 → 0.2.0.0

raw patch · 2 files changed

+15/−15 lines, 2 filesdep ~containers

Dependency ranges changed: containers

Files

SConfig.cabal view
@@ -2,9 +2,9 @@ -- documentation, see http://haskell.org/cabal/users-guide/  name:                SConfig-version:             0.1.0.0+version:             0.2.0.0 synopsis:            A simple config library--- description:         +description:         A simple config library. homepage:            https://github.com/fgaz/SConfig license:             MIT license-file:        LICENSE@@ -20,6 +20,6 @@   exposed-modules:     Data.SConfig   -- other-modules:          -- other-extensions:    -  build-depends:       base >=4.7 && <4.8, containers >=0.5 && <0.6+  build-depends:       base ==4.*, containers >=0.5 && <1   hs-source-dirs:      src   default-language:    Haskell2010
src/Data/SConfig.hs view
@@ -1,5 +1,6 @@ module Data.SConfig-( parseConfig+( readConfig+, writeConfig , getValue , Config , Key@@ -19,9 +20,15 @@ -- | Parsed configuration. Basically a Map String String type Config = M.Map Key Value +-- | Convert configuration to parseable string+writeConfig :: Config -> String+writeConfig cfg = concat+                $ intersperse "\n"+                $ map (\(key,value) -> key ++ "=" ++ value) $ M.toList cfg+ -- | Parse configuration-parseConfig :: String -> Config-parseConfig str = foldl readConfigLine M.empty --apply readConfigLine to every line+readConfig :: String -> Config+readConfig str = foldl readConfigLine M.empty --apply readConfigLine to every line                       $ filter (elem '=') --make sure all lines are actual configuration lines                       $ concatEscaped                       $ filter (\x -> (not $ null x) && (take 1 x) /= "#") --remove comments & empty lines@@ -29,15 +36,8 @@  --inserts a parsed key-value pair into the Config accumulator readConfigLine :: Config -> String -> Config-readConfigLine config str = M.insert-                                (filter (/=' ') key) --spaces only cause errors.-                                    value-                                config-    where (key,_:value) = splitAt-                              ( fromJust $ --already checked that str contains '='-                                    elemIndex '=' str-                              )-                              str+readConfigLine config str = M.insert (filter (/=' ') key) value config+    where (key,_:value) = break (=='=') str  --concatenate two lines if the first ends with a backslash concatEscaped :: [String] -> [String]