aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoris Guyonvarch2015-04-11 21:06:25 +0200
committerJoris Guyonvarch2015-04-11 21:06:25 +0200
commit73a11fee2cddc9b31b607cf2b3a9313644b91032 (patch)
treed7199f10383e60861063286103a72fd459b7170a /src
parent7fcca448d4d4f08abed94b4c9f13fd97c2c207ff (diff)
downloadad-listener-73a11fee2cddc9b31b607cf2b3a9313644b91032.tar.gz
ad-listener-73a11fee2cddc9b31b607cf2b3a9313644b91032.tar.bz2
ad-listener-73a11fee2cddc9b31b607cf2b3a9313644b91032.zip
Fixing conf reader
Diffstat (limited to 'src')
-rw-r--r--src/Config.hs17
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