From 73a11fee2cddc9b31b607cf2b3a9313644b91032 Mon Sep 17 00:00:00 2001 From: Joris Guyonvarch Date: Sat, 11 Apr 2015 21:06:25 +0200 Subject: Fixing conf reader --- src/Config.hs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/Config.hs b/src/Config.hs index c09f69e..c0b0bc0 100644 --- a/src/Config.hs +++ b/src/Config.hs @@ -6,7 +6,7 @@ module Config , getConfig ) where -import Data.Maybe (catMaybes) +import Data.Maybe (catMaybes, isJust) import Data.Map (Map) import qualified Data.Map as M import Data.Text (Text) @@ -63,10 +63,17 @@ configFromMap map = do lineConfig :: Text -> Maybe (Text, Text) lineConfig line = do - (key, value) <- twoElementsList (map T.strip . T.splitOn "=" $ line) + (key, value) <- keyValue line guard (T.length key > 0) return (key, value) -twoElementsList :: [a] -> Maybe (a, a) -twoElementsList [x, y] = Just (x, y) -twoElementsLisst _ = Nothing +keyValue :: Text -> Maybe (Text, Text) +keyValue line = + let sep = '=' + in if isJust (T.find (== sep) line) + then + let key = T.takeWhile (/= sep) line + value = T.drop 1 . T.dropWhile (/= sep) $ line + in Just (T.strip key, T.strip value) + else + Nothing -- cgit v1.2.3