diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Config.hs | 17 |
1 files changed, 12 insertions, 5 deletions
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 |