bytestring-show 0.2.1 → 0.3.5.6
raw patch · 6 files changed
Files
- Tests/Properties.hs +0/−36
- Text/Show/ByteString.hs +16/−2
- Text/Show/ByteString/Float.hs +2/−2
- Text/Show/ByteString/Int.hs +68/−6
- Text/Show/ByteString/Integer.hs +27/−6
- bytestring-show.cabal +21/−8
− Tests/Properties.hs
@@ -1,36 +0,0 @@--module Main where--import Test.QuickCheck--import Data.Complex-import Data.Int-import Data.Word-import Data.Ratio--import qualified Text.Show.ByteString as S--import qualified Data.ByteString.Lazy.Char8 as L--test_matchesShow :: (Show a, S.Show a, Arbitrary a) => a -> Bool-test_matchesShow a = show a == L.unpack (S.show a)--test_all :: IO ()-test_all = do quickCheck (test_matchesShow :: Int -> Bool)--- quickCheck (test_matchesShow :: Int8 -> Bool)--- quickCheck (test_matchesShow :: Int16 -> Bool)--- quickCheck (test_matchesShow :: Int32 -> Bool)--- quickCheck (test_matchesShow :: Word -> Bool)--- quickCheck (test_matchesShow :: Word8 -> Bool)--- quickCheck (test_matchesShow :: Word16 -> Bool)--- quickCheck (test_matchesShow :: Word32 -> Bool)- quickCheck (test_matchesShow :: () -> Bool)- quickCheck (test_matchesShow :: Integer -> Bool)- quickCheck (test_matchesShow :: Float -> Bool)- quickCheck (test_matchesShow :: Double -> Bool)- quickCheck (test_matchesShow :: Rational -> Bool)- quickCheck (test_matchesShow :: (Int,Int,Int) -> Bool)- quickCheck (test_matchesShow :: (Int,Int,Int,Int) -> Bool)- quickCheck (test_matchesShow :: [Int] -> Bool)--main = test_all
Text/Show/ByteString.hs view
@@ -1,4 +1,4 @@-{-# LANGUAGE TypeSynonymInstances #-}+{-# LANGUAGE TypeSynonymInstances, FlexibleInstances #-} -- --------------------------------------------------------------------------- -- |@@ -22,6 +22,8 @@ -- * Putting digits , unsafePutDigit , putDigit+ -- * Putting integers+ , showpIntAtBase -- * Putting floats , showpGFloat , showpFFloat@@ -32,13 +34,17 @@ , showpParen -- * Printing values , print+ -- * Put+ , Put+ , PutM(..)+ , runPut ) where import Prelude hiding (Show(..), print, putStrLn) import qualified Prelude import Data.Binary.Put-import Data.ByteString.Lazy+import Data.ByteString.Lazy.Char8 import Data.Int import Data.Word@@ -161,6 +167,11 @@ showpPrec k i = showpParen (i < 0 && k > 0) $ showpInt32 i +instance Show Int64 where+ showp = showpInt64++ showpPrec k i = showpParen (i < 0 && k > 0) $ showpInt64 i+ instance Show Word where showp = showpWord @@ -172,6 +183,9 @@ instance Show Word32 where showp = showpWord32++instance Show Word64 where+ showp = showpWord64 instance Show Integer where showp = showpInteger
Text/Show/ByteString/Float.hs view
@@ -46,7 +46,7 @@ | otherwise = go fmt (floatToDigits (toInteger base) f) where base = 10- + go FFGeneric p@(_,e) | e < 0 || e > 7 = go FFExponent p | otherwise = go FFFixed p@@ -86,6 +86,6 @@ let (ei, is') = roundTo base dec' (replicate (-e) 0 ++ is) d:ds = if ei > 0 then is' else 0:is' in unsafePutDigit d >> when (not $ null ds) (putAscii '.' >> mapM_ unsafePutDigit ds)- + mk0 [] = putAscii '0' mk0 rs = mapM_ unsafePutDigit rs
Text/Show/ByteString/Int.hs view
@@ -1,4 +1,6 @@+{-# LANGUAGE CPP #-} {-# LANGUAGE MagicHash #-}+{-# LANGUAGE BangPatterns #-} -- --------------------------------------------------------------------------- -- |@@ -12,6 +14,8 @@ -- -- The code in this module is based on the printing in the GHC modules. +#include "MachDeps.h"+ module Text.Show.ByteString.Int where import GHC.Base@@ -24,18 +28,46 @@ putI :: Int# -> Put putI i#+#if __GLASGOW_HASKELL__ && __GLASGOW_HASKELL__ >= 708+ = case i# <# 0# of+ 1# -> let !(I# minInt#) = minInt+#elif __GLASGOW_HASKELL__ && __GLASGOW_HASKELL__ >= 611+ | i# <# 0# = let !(I# minInt#) = minInt+#else | i# <# 0# = let I# minInt# = minInt- in if i# ==# minInt#- then putWord8 45 >> putW (int2Word# (negateInt# (i# `quotInt#` 10#)))+#endif+ in case i# ==# minInt# of+#if __GLASGOW_HASKELL__ && __GLASGOW_HASKELL__ >= 708+ 1# ->+#else+ True ->+#endif+ putWord8 45 >> putW (int2Word# (negateInt# (i# `quotInt#` 10#))) >> putW (int2Word# (negateInt# (i# `remInt#` 10#)))- else putWord8 45 >> putW (int2Word# (negateInt# i#))+ _ ->+ putWord8 45 >> putW (int2Word# (negateInt# i#))+#if __GLASGOW_HASKELL__ && __GLASGOW_HASKELL__ >= 708+ _ -> putW (int2Word# i#)+#else | otherwise = putW (int2Word# i#)+#endif putW :: Word# -> Put putW w#- | w# `ltWord#` int2Word# 10# = unsafePutDigit# w#- | otherwise = putW (w# `quotWord#` int2Word# 10#)- >> unsafePutDigit# (w# `remWord#` int2Word# 10#)+#if __GLASGOW_HASKELL__ && __GLASGOW_HASKELL__ >= 708+ = case w# `ltWord#` int2Word# 10# of+ 1# ->+#else+ | w# `ltWord#` int2Word# 10# =+#endif+ unsafePutDigit# w#+#if __GLASGOW_HASKELL__ && __GLASGOW_HASKELL__ >= 708+ _ ->+#else+ | otherwise =+#endif+ putW (w# `quotWord#` int2Word# 10#)+ >> unsafePutDigit# (w# `remWord#` int2Word# 10#) showpInt :: Int -> Put showpInt (I# i#) = putI i#@@ -49,6 +81,22 @@ showpInt32 :: Int32 -> Put showpInt32 (I32# i#) = putI i# +showpInt64 :: Int64 -> Put+#if WORD_SIZE_IN_BITS >= 64+showpInt64 (I64# i#) = putI i#+#else /* WORD_SIZE_IN_BITS < 64 */+showpInt64 = putI64++-- Unboxed 64-bit-specific operations aren't exported++putI64 :: Int64 -> Put+putI64 i | i == minBound = putWord8 45+ >> putW64 (fromIntegral $ negate (i `quot` 10))+ >> putW64 (fromIntegral $ negate (i `rem` 10))+ | i < 0 = putWord8 45 >> putW64 (fromIntegral $ negate i)+ | otherwise = putW64 (fromIntegral i)+#endif+ showpWord :: Word -> Put showpWord (W# w#) = putW w# @@ -60,3 +108,17 @@ showpWord32 :: Word32 -> Put showpWord32 (W32# w#) = putW w#++showpWord64 :: Word64 -> Put+#if WORD_SIZE_IN_BITS >= 64+showpWord64 (W64# w#) = putW w#+#else /* WORD_SIZE_IN_BITS < 64 */+showpWord64 = putW64++putW64 :: Word64 -> Put+putW64 w | w < 10 = unsafePutDigit64 w+ | otherwise = putW64 (w `quot` 10)+ >> unsafePutDigit64 (w `rem` 10)+ where unsafePutDigit64 w = unsafePutDigit# (case fromIntegral w of (W# w#) -> w#)++#endif
Text/Show/ByteString/Integer.hs view
@@ -16,8 +16,12 @@ import GHC.Base -#ifdef INTEGER_GMP+#if __GLASGOW_HASKELL__ && __GLASGOW_HASKELL__ < 611 && INTEGER_GMP import GHC.Integer.Internals+#elif __GLASGOW_HASKELL__ && __GLASGOW_HASKELL__ >= 611 && INTEGER_GMP+import GHC.Integer.GMP.Internals+#elif __GLASGOW_HASKELL__ && INTEGER_SIMPLE+import GHC.Integer.Simple.Internals #endif import GHC.Num@@ -34,7 +38,12 @@ where mi = fromIntegral (maxBound :: Int) showpInteger :: Integer -> Put+#ifdef INTEGER_SIMPLE+#elif INTEGER_GMP showpInteger (S# i#) = putI i#+#else+showpInteger (I# i#) = putI i#+#endif showpInteger n | n < 0 = putAscii '-' >> posIntegerPut (-n) | otherwise = posIntegerPut n@@ -53,10 +62,10 @@ splith :: Integer -> [Integer] -> [Integer] splith _ [ ] = error "splith: the impossible happened." splith p (n:ns) = case n `quotRemInteger` p of-#ifdef INTEGER_GMP+#if defined(INTEGER_GMP) || defined(INTEGER_SIMPLE) (# q, r #) -> #else- (q, r) -> + (q, r) -> #endif if q > 0 then q : r : splitb p ns@@ -65,7 +74,7 @@ splitb :: Integer -> [Integer] -> [Integer] splitb _ [ ] = [] splitb p (n:ns) = case n `quotRemInteger` p of-#ifdef INTEGER_GMP+#if defined(INTEGER_GMP) || defined(INTEGER_SIMPLE) (# q, r #) -> #else (q, r) ->@@ -75,7 +84,7 @@ printh :: [Integer] -> Put printh [ ] = error "printh: the impossible happened." printh (n:ns) = case n `quotRemInteger` mx of-#ifdef INTEGER_GMP+#if defined(INTEGER_GMP) || defined(INTEGER_SIMPLE) (# q', r' #) -> #else (q', r') ->@@ -88,7 +97,7 @@ printb :: [Integer] -> Put printb [ ] = return () printb (n:ns) = case n `quotRemInteger` mx of-#ifdef INTEGER_GMP+#if defined(INTEGER_GMP) || defined(INTEGER_SIMPLE) (# q', r' #) -> #else (q', r') ->@@ -108,3 +117,15 @@ | d == 1 = unsafePutDigit n | otherwise = pblock' (d-1) q >> unsafePutDigit r where (q, r) = n `quotRemInt` 10++-- | Shows an Integral number using the base specified by the first+-- argument and the chracter representation specified by the second.+showpIntAtBase :: Integral a => a -> (Int -> Char) -> a -> Put+showpIntAtBase b f n | n < 0 = putAscii '-' >> showpIntAtBase b f (-n)+ | n == 0 = putAscii (f 0)+ | otherwise = let+ go k | k == 0 = return ()+ | otherwise = go d >> putAscii (f $ fromIntegral m)+ where+ (d, m) = k `divMod` b+ in go n
bytestring-show.cabal view
@@ -1,5 +1,5 @@ name: bytestring-show-version: 0.2.1+version: 0.3.5.6 license: BSD3 license-file: LICENSE author: Dan Doel@@ -9,10 +9,14 @@ synopsis: Efficient conversion of values into readable byte strings. description: Efficient conversion of values into readable byte strings. build-type: Simple-cabal-version: >= 1.2+cabal-version: >= 1.6 +flag integer-simple+ default: False+ description: use with integer-simple build of GHC+ library- build-depends: base, binary, bytestring >= 0.9, array, containers+ build-depends: base < 5, binary < 0.8, bytestring >= 0.9 && <= 1, array < 0.6, containers < 0.6 exposed-modules: Text.Show.ByteString@@ -24,12 +28,21 @@ Text.Show.ByteString.Float Text.Show.ByteString.Integer - extensions:- UnboxedTuples, MagicHash, BangPatterns, TypeSynonymInstances, CPP- ghc-options: -O2 -Wall - if impl(ghc >= 6.9)- build-depends: integer+ if flag(integer-simple)+ cpp-options: -DINTEGER_SIMPLE+ build-depends: integer-simple++ if impl(ghc >= 6.11) && !flag(integer-simple) cpp-options: -DINTEGER_GMP+ build-depends: integer-gmp >= 0.2++ if impl(ghc >= 6.9) && impl(ghc < 6.11) && !flag(integer-simple)+ cpp-options: -DINTEGER_GMP+ build-depends: integer >= 0.1 && < 0.2++source-repository head+ type: darcs+ location: http://hub.darcs.net/dolio/bytestring-show