diff options
author | Joris Guyonvarch | 2015-04-11 21:06:25 +0200 |
---|---|---|
committer | Joris Guyonvarch | 2015-04-11 21:06:25 +0200 |
commit | 73a11fee2cddc9b31b607cf2b3a9313644b91032 (patch) | |
tree | d7199f10383e60861063286103a72fd459b7170a | |
parent | 7fcca448d4d4f08abed94b4c9f13fd97c2c207ff (diff) |
Fixing conf reader
-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 |