gameServer/Data/TConfig.hs
changeset 4993 905b349af377
parent 4992 408301a9d2d6
child 4995 d3ca68e4860e
equal deleted inserted replaced
4992:408301a9d2d6 4993:905b349af377
    54 repConfig k rv conf = let f _ = Just rv
    54 repConfig k rv conf = let f _ = Just rv
    55                       in M.alter f k conf
    55                       in M.alter f k conf
    56 
    56 
    57 -- |Reads a file and parses to a Map String String.
    57 -- |Reads a file and parses to a Map String String.
    58 readConfig :: FilePath -> IO Conf
    58 readConfig :: FilePath -> IO Conf
    59 readConfig path = liftM (M.fromList . map ((\(a, b) -> (filter (not . isSpace) a, dropWhile isSpace b)) . break (== '=')) . filter (not . null) . lines) $ readFile path
    59 readConfig path = liftM (M.fromList . map ((\(a, b) -> (filter (not . isSpace) a, dropWhile isSpace $ tail b)) . break (== '=')) . filter (not . null) . lines) $ readFile path
    60 
    60 
    61 -- |Parses a parsed configuration back to a file.
    61 -- |Parses a parsed configuration back to a file.
    62 writeConfig :: FilePath -> Conf -> IO ()
    62 writeConfig :: FilePath -> Conf -> IO ()
    63 writeConfig path = writeFile path . unlines . map (\(a, b) -> a ++ " = " ++ b) . M.toList
    63 writeConfig path = writeFile path . unlines . map (\(a, b) -> a ++ " = " ++ b) . M.toList