bytestring-nums 0.3.0 → 0.3.1
raw patch · 5 files changed
+72/−11 lines, 5 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Data.ByteString.Nums.Careless: class (Intable b f, Fractional f) => Floatable b f
+ Data.ByteString.Nums.Careless: class (Num n) => Hexable b n
+ Data.ByteString.Nums.Careless: class (Num n) => Intable b n
+ Data.ByteString.Nums.Careless: float :: (Floatable b f) => b -> f
+ Data.ByteString.Nums.Careless: hex :: (Hexable b n) => b -> n
+ Data.ByteString.Nums.Careless: int :: (Intable b n) => b -> n
+ Data.ByteString.Nums.Careless.Float: lazy_float :: (Intable ByteString f, Fractional f) => ByteString -> f
+ Data.ByteString.Nums.Careless.Float: point :: Char -> Bool
+ Data.ByteString.Nums.Careless.Float: strict_float :: (Intable ByteString f, Fractional f) => ByteString -> f
+ Data.ByteString.Nums.Careless.Hex: lazy_hex :: (Num n) => ByteString -> n
+ Data.ByteString.Nums.Careless.Hex: strict_hex :: (Num n) => ByteString -> n
+ Data.ByteString.Nums.Careless.Int: lazy_signed :: (Num n) => ByteString -> n
+ Data.ByteString.Nums.Careless.Int: negative :: (Num n) => n -> Word8 -> n
+ Data.ByteString.Nums.Careless.Int: positive :: (Num n) => n -> Word8 -> n
+ Data.ByteString.Nums.Careless.Int: strict_signed :: (Num n) => ByteString -> n
Files
- Data/ByteString/Nums/Careless.hs +4/−5
- Data/ByteString/Nums/Careless/Float.hs +16/−1
- Data/ByteString/Nums/Careless/Hex.hs +16/−1
- Data/ByteString/Nums/Careless/Int.hs +33/−1
- bytestring-nums.cabal +3/−3
Data/ByteString/Nums/Careless.hs view
@@ -1,13 +1,12 @@ -{-| Careless conversion of @ByteString@s to numbers, ignoring bytes that- aren't hex or decimal digits.+{-| Careless conversion of @ByteString@s to numbers. -} module Data.ByteString.Nums.Careless- ( module Data.ByteString.Nums.Careless.Int- , module Data.ByteString.Nums.Careless.Hex- , module Data.ByteString.Nums.Careless.Float+ ( Intable(..) + , Hexable(..)+ , Floatable(..) ) where
Data/ByteString/Nums/Careless/Float.hs view
@@ -2,10 +2,16 @@ {-# LANGUAGE MultiParamTypeClasses , TypeSynonymInstances+ , FlexibleContexts #-} -module Data.ByteString.Nums.Careless.Float where+module Data.ByteString.Nums.Careless.Float+ ( point+ , lazy_float+ , strict_float+ , Floatable(..)+ ) where import Data.Char@@ -46,6 +52,9 @@ +{-| Implementation for strict @Data.ByteString.ByteString@.+ -}+strict_float :: (Intable ByteString f, Fractional f) => ByteString -> f strict_float bytes | null bytes = 0 | head bytes == '-' = foldn 0 (tail integer) + nfrac@@ -65,6 +74,9 @@ | otherwise = foldp 0 fractional' * p +{-| Implementation for lazy @Data.ByteString.Lazy.ByteString@.+ -}+lazy_float :: (Intable Lazy.ByteString f, Fractional f) => Lazy.ByteString -> f lazy_float bytes | Lazy.null bytes = 0 | Lazy.head bytes == '-' = foldn 0 (Lazy.tail integer) + nfrac@@ -84,6 +96,9 @@ | otherwise = foldp 0 fractional' * p +{-| Is this character a decimal point or comma?+ -}+point :: Char -> Bool point c = c == '.' || c == ','
Data/ByteString/Nums/Careless/Hex.hs view
@@ -5,7 +5,12 @@ #-} -module Data.ByteString.Nums.Careless.Hex where+module Data.ByteString.Nums.Careless.Hex+ ( hexalize+ , lazy_hex+ , strict_hex+ , Hexable(..)+ ) where import Prelude hiding (head, tail, drop)@@ -89,6 +94,9 @@ +{-| Folds a byte into a number if the byte is a hexadecimal digit; otherwise+ the byte is ignored.+ -} hexalize :: (Num n) => n -> Word8 -> n hexalize acc byte | between 'a' 'f' = place_up (byte + 0x0a - c2w 'a')@@ -99,8 +107,15 @@ between a z = byte >= c2w a && byte <= c2w z place_up b = (0x10 * acc) + fromIntegral b ++{-| Strict fold with 'hexalize'.+ -}+strict_hex :: (Num n) => ByteString -> n strict_hex bytes = foldl' hexalize 0 bytes +{-| Lazy fold with 'hexalize'.+ -}+lazy_hex :: (Num n) => Lazy.ByteString -> n lazy_hex bytes = Lazy.foldlChunks (foldl' hexalize) 0 bytes
Data/ByteString/Nums/Careless/Int.hs view
@@ -5,7 +5,15 @@ #-} -module Data.ByteString.Nums.Careless.Int where+module Data.ByteString.Nums.Careless.Int+ ( positive+ , negative+ , lazy_unsigned+ , lazy_signed+ , strict_unsigned+ , strict_signed+ , Intable(..)+ ) where import Prelude hiding (head, tail, null)@@ -89,9 +97,18 @@ +{-| Implementation of unsigned number parser for+ 'Data.ByteString.Lazy.ByteString'. Only digits are parsed; no sign+ specifier is allowed.+ -} lazy_unsigned :: (Num n) => Lazy.ByteString -> n lazy_unsigned = Lazy.foldlChunks (foldl' positive) 0 +{-| Implementation of signed number parser for+ 'Data.ByteString.Lazy.ByteString'. An initial, optional sign specifier is+ okay.+ -}+lazy_signed :: (Num n) => Lazy.ByteString -> n lazy_signed bytes | Lazy.null bytes = 0 | Lazy.head bytes == '-' = fold negative 0 (Lazy.tail bytes)@@ -101,9 +118,16 @@ fold = Lazy.foldlChunks . foldl' +{-| Implementation of unsigned number parser for 'Data.ByteString.ByteString'.+ Only digits are parsed; no sign specifier is allowed.+ -} strict_unsigned :: (Num n) => ByteString -> n strict_unsigned = foldl' positive 0 +{-| Implementation of signed number parser for 'Data.ByteString.ByteString'.+ An initial, optional sign specifier is okay.+ -}+strict_signed :: (Num n) => ByteString -> n strict_signed bytes | null bytes = 0 | head bytes == '-' = foldl' negative 0 (tail bytes)@@ -111,8 +135,16 @@ | otherwise = foldl' positive 0 bytes +{-| Folds a byte into the accumulator, assuming the number we are parsing is+ a positive number.+ -}+positive :: (Num n) => n -> Word8 -> n positive acc byte = (acc * 10) + fromIntegral (byte - c2w '0') +{-| Folds a byte into the accumulator, assuming the number we are parsing is+ a negative number.+ -}+negative :: (Num n) => n -> Word8 -> n negative acc byte = (acc * 10) - fromIntegral (byte - c2w '0')
bytestring-nums.cabal view
@@ -1,5 +1,5 @@ name : bytestring-nums-version : 0.3.0+version : 0.3.1 category : Text license : BSD3 license-file : LICENSE@@ -27,7 +27,7 @@ Data.ByteString.Nums.Careless.Float extensions : MultiParamTypeClasses TypeSynonymInstances- BangPatterns+ FlexibleContexts ghc-options : -O2 -Wall -funbox-strict-fields @@ -35,7 +35,7 @@ main-is : SPOJEugeneKirpichov.hs extensions : MultiParamTypeClasses TypeSynonymInstances- BangPatterns+ FlexibleContexts ghc-options : -O2 -Wall -funbox-strict-fields