From 40bb0d66f492abed328ebd7961588b7c3a8ed7a6 Mon Sep 17 00:00:00 2001 From: James Crayne Date: Mon, 23 Jan 2017 07:29:21 +0000 Subject: build fixes --- src/Data/BEncode/Pretty.hs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'src/Data/BEncode/Pretty.hs') diff --git a/src/Data/BEncode/Pretty.hs b/src/Data/BEncode/Pretty.hs index 63efc61c..89fcb489 100644 --- a/src/Data/BEncode/Pretty.hs +++ b/src/Data/BEncode/Pretty.hs @@ -7,6 +7,9 @@ import qualified Data.ByteString.Lazy as BL import qualified Data.ByteString.Lazy.Char8 as BL8 import Data.Text (Text) import qualified Data.Text as T +import Data.Text.Encoding +import Text.Printf +import qualified Data.ByteString.Base16 as Base16 #ifdef BENCODE_AESON import Data.BEncode.BDict hiding (map) import Data.Aeson.Types hiding (parse) @@ -14,12 +17,9 @@ import Data.Aeson.Encode.Pretty import qualified Data.HashMap.Strict as HashMap import qualified Data.Vector as Vector import Data.Foldable as Foldable -import Data.Text.Encoding -import Text.Printf #endif -#ifdef BENCODE_AESON - +{- unhex :: Text -> BS.ByteString unhex t = BS.pack $ map unhex1 [0 .. BS.length nibs `div` 2] where @@ -31,6 +31,9 @@ unhex t = BS.pack $ map unhex1 [0 .. BS.length nibs `div` 2] hex :: BS.ByteString -> Text hex bs = T.concat $ map (T.pack . printf "%02X") $ BS.unpack bs +-} + +#ifdef BENCODE_AESON quote_chr :: Char quote_chr = ' ' @@ -39,12 +42,12 @@ quote :: Text -> Text quote t = quote_chr `T.cons` t `T.snoc` quote_chr encodeByteString :: BS.ByteString -> Text -encodeByteString s = either (const $ hex s) quote $ decodeUtf8' s +encodeByteString s = either (const . decodeUtf8 $ Base16.encode s) quote $ decodeUtf8' s decodeByteString :: Text -> BS.ByteString decodeByteString s | T.head s==quote_chr = encodeUtf8 (T.takeWhile (/=quote_chr) $ T.drop 1 s) - | otherwise = unhex s + | otherwise = fst (Base16.decode (encodeUtf8 s)) instance ToJSON BValue where toJSON (BInteger x) = Number $ fromIntegral x -- cgit v1.2.3