aboutsummaryrefslogtreecommitdiff
path: root/Logs/UUIDBased.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-11-07 23:21:22 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-11-08 00:17:54 -0400
commitb11a63a860e8446cf3a4b35a5d8ef76329d5135c (patch)
treec8ae0c94d6473a3ccc7b15bdbc72d5b5c6ae96b3 /Logs/UUIDBased.hs
parentfdf988be6d2b3bb931a9eb3dcf3fbb83b1fb8c17 (diff)
clean up read/show abuse
Avoid ever using read to parse a non-haskell formatted input string. show :: Key is arguably still show abuse, but displaying Keys as filenames is just too useful to give up.
Diffstat (limited to 'Logs/UUIDBased.hs')
-rw-r--r--Logs/UUIDBased.hs17
1 files changed, 8 insertions, 9 deletions
diff --git a/Logs/UUIDBased.hs b/Logs/UUIDBased.hs
index 7184709fe..9609d7321 100644
--- a/Logs/UUIDBased.hs
+++ b/Logs/UUIDBased.hs
@@ -50,28 +50,27 @@ showLog :: (a -> String) -> Log a -> String
showLog shower = unlines . map showpair . M.toList
where
showpair (k, LogEntry (Date p) v) =
- unwords [show k, shower v, tskey ++ show p]
+ unwords [fromUUID k, shower v, tskey ++ show p]
showpair (k, LogEntry Unknown v) =
- unwords [show k, shower v]
+ unwords [fromUUID k, shower v]
parseLog :: (String -> Maybe a) -> String -> Log a
-parseLog parser = M.fromListWith best . catMaybes . map pair . lines
+parseLog parser = M.fromListWith best . catMaybes . map parse . lines
where
- pair line
+ parse line
| null ws = Nothing
- | otherwise = case parser $ unwords info of
- Nothing -> Nothing
- Just v -> Just (read u, LogEntry c v)
+ | otherwise = parser (unwords info) >>= makepair
where
+ makepair v = Just (toUUID u, LogEntry ts v)
ws = words line
u = head ws
end = last ws
- c
+ ts
| tskey `isPrefixOf` end =
pdate $ tail $ dropWhile (/= '=') end
| otherwise = Unknown
info
- | c == Unknown = drop 1 ws
+ | ts == Unknown = drop 1 ws
| otherwise = drop 1 $ init ws
pdate s = case parseTime defaultTimeLocale "%s%Qs" s of
Nothing -> Unknown