diff options
author | Sam T <pxqr.sta@gmail.com> | 2013-08-26 21:48:28 +0400 |
---|---|---|
committer | Sam T <pxqr.sta@gmail.com> | 2013-08-26 21:48:28 +0400 |
commit | 49bdb7974459e2b37eb67641fd93871cc88e2fd3 (patch) | |
tree | ded45a054610fbbac977dc3ff30baf50f3be4858 /src/Data/BEncode.hs | |
parent | 5e395da12ef08ff5b69a0e436fe045c36e41dfd2 (diff) |
+ Drop `_` prefix in selector names.
Diffstat (limited to 'src/Data/BEncode.hs')
-rw-r--r-- | src/Data/BEncode.hs | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/Data/BEncode.hs b/src/Data/BEncode.hs index b53f6e5..f41e4b8 100644 --- a/src/Data/BEncode.hs +++ b/src/Data/BEncode.hs | |||
@@ -259,11 +259,14 @@ instance (GBEncodable a e, GBEncodable b e) | |||
259 | Right rv -> return (R1 rv) | 259 | Right rv -> return (R1 rv) |
260 | Left re -> decodingError $ "generic: both" ++ le ++ " " ++ re | 260 | Left re -> decodingError $ "generic: both" ++ le ++ " " ++ re |
261 | 261 | ||
262 | selRename :: String -> String | ||
263 | selRename = dropWhile ('_'==) | ||
264 | |||
262 | gfromM1S :: forall c. Selector c | 265 | gfromM1S :: forall c. Selector c |
263 | => GBEncodable f BEncode | 266 | => GBEncodable f BEncode |
264 | => Dict -> Result (M1 i c f p) | 267 | => Dict -> Result (M1 i c f p) |
265 | gfromM1S dict | 268 | gfromM1S dict |
266 | | Just va <- M.lookup (BC.pack name) dict = M1 <$> gfrom va | 269 | | Just va <- M.lookup (BC.pack (selRename name)) dict = M1 <$> gfrom va |
267 | | otherwise = decodingError $ "generic: Selector not found " ++ show name | 270 | | otherwise = decodingError $ "generic: Selector not found " ++ show name |
268 | where | 271 | where |
269 | name = selName (error "gfromM1S: impossible" :: M1 i c f p) | 272 | name = selName (error "gfromM1S: impossible" :: M1 i c f p) |
@@ -271,7 +274,7 @@ gfromM1S dict | |||
271 | instance (Selector s, GBEncodable f BEncode) | 274 | instance (Selector s, GBEncodable f BEncode) |
272 | => GBEncodable (M1 S s f) Dict where | 275 | => GBEncodable (M1 S s f) Dict where |
273 | {-# INLINE gto #-} | 276 | {-# INLINE gto #-} |
274 | gto s @ (M1 x) = BC.pack (selName s) `M.singleton` gto x | 277 | gto s @ (M1 x) = BC.pack (selRename (selName s)) `M.singleton` gto x |
275 | 278 | ||
276 | {-# INLINE gfrom #-} | 279 | {-# INLINE gfrom #-} |
277 | gfrom = gfromM1S | 280 | gfrom = gfromM1S |