From ed25a297094b483dce06e14d52ced2f93f6dca41 Mon Sep 17 00:00:00 2001 From: Sam Truzjan Date: Sat, 23 Nov 2013 03:37:15 +0400 Subject: Use pretty-class package --- src/Data/Torrent/InfoHash.hs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'src/Data/Torrent/InfoHash.hs') diff --git a/src/Data/Torrent/InfoHash.hs b/src/Data/Torrent/InfoHash.hs index 2e3946eb..e15fdbb3 100644 --- a/src/Data/Torrent/InfoHash.hs +++ b/src/Data/Torrent/InfoHash.hs @@ -19,11 +19,9 @@ module Data.Torrent.InfoHash -- * Rendering , longHex , shortHex - , ppInfoHash , addHashToURI - , Data.Torrent.InfoHash.hash , Data.Torrent.InfoHash.hashlazy ) where @@ -52,6 +50,7 @@ import Network.URI import Numeric import Text.ParserCombinators.ReadP as P import Text.PrettyPrint +import Text.PrettyPrint.Class -- | Exactly 20 bytes long SHA1 hash of the info part of torrent file. @@ -60,7 +59,7 @@ newtype InfoHash = InfoHash { getInfoHash :: BS.ByteString } -- | for hex encoded strings instance Show InfoHash where - show = render . ppInfoHash + show = render . pretty -- | for hex encoded strings instance Read InfoHash where @@ -106,6 +105,10 @@ instance FromJSON InfoHash where instance URLShow InfoHash where urlShow = show +-- | base16 encoded. +instance Pretty InfoHash where + pretty = text . BC.unpack . ppHex . getInfoHash + -- | Tries both base16 and base32 while decoding info hash. textToInfoHash :: Text -> Maybe InfoHash textToInfoHash text @@ -127,10 +130,6 @@ longHex = T.decodeUtf8 . Base16.encode . getInfoHash shortHex :: InfoHash -> Text shortHex = T.take 7 . longHex --- | Pretty print info hash in hexadecimal format. -ppInfoHash :: InfoHash -> Doc -ppInfoHash = text . BC.unpack . ppHex . getInfoHash - ppHex :: BS.ByteString -> BS.ByteString ppHex = BL.toStrict . B.toLazyByteString . B.byteStringHexFixed -- cgit v1.2.3