hw-bits 0.2.0.2 → 0.3.0.0
raw patch · 6 files changed
+53/−58 lines, 6 filesdep +hw-string-parsedep −parsecPVP ok
version bump matches the API change (PVP)
Dependencies added: hw-string-parse
Dependencies removed: parsec
API changes (from Hackage documentation)
+ HaskellWorks.Data.Bits.PackedVector.PackedVector64: empty :: PackedVector64
Files
- LICENSE +17/−26
- hw-bits.cabal +3/−3
- src/HaskellWorks/Data/Bits/BitParse.hs +19/−18
- src/HaskellWorks/Data/Bits/BitRead.hs +4/−2
- src/HaskellWorks/Data/Bits/PackedVector/PackedVector64.hs +8/−7
- test/HaskellWorks/Data/Bits/BitReadSpec.hs +2/−2
LICENSE view
@@ -1,30 +1,21 @@-Copyright John Ky (c) 2016--All rights reserved.--Redistribution and use in source and binary forms, with or without-modification, are permitted provided that the following conditions are met:+MIT License - * Redistributions of source code must retain the above copyright- notice, this list of conditions and the following disclaimer.+Copyright (c) 2016 John Ky - * Redistributions in binary form must reproduce the above- copyright notice, this list of conditions and the following- disclaimer in the documentation and/or other materials provided- with the distribution.+Permission is hereby granted, free of charge, to any person obtaining a copy+of this software and associated documentation files (the "Software"), to deal+in the Software without restriction, including without limitation the rights+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell+copies of the Software, and to permit persons to whom the Software is+furnished to do so, subject to the following conditions: - * Neither the name of Author name here nor the names of other- contributors may be used to endorse or promote products derived- from this software without specific prior written permission.+The above copyright notice and this permission notice shall be included in all+copies or substantial portions of the Software. -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS-"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT-LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR-A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT-OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,-SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT-LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,-DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY-THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE-OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE+SOFTWARE.
hw-bits.cabal view
@@ -1,9 +1,9 @@ name: hw-bits-version: 0.2.0.2+version: 0.3.0.0 synopsis: Conduits for tokenizing streams. description: Please see README.md homepage: http://github.com/haskell-works/hw-bits#readme-license: BSD3+license: MIT license-file: LICENSE author: John Ky maintainer: newhoggy@gmail.com@@ -57,7 +57,7 @@ build-depends: base >= 4 && < 5 , bytestring , hw-prim >= 0.3.0.1- , parsec+ , hw-string-parse >= 0.0.0.1 , safe , vector
src/HaskellWorks/Data/Bits/BitParse.hs view
@@ -10,6 +10,7 @@ ( BitParse(..) ) where +import Control.Applicative import qualified Data.ByteString as BS import qualified Data.Vector as DV import qualified Data.Vector.Storable as DVS@@ -17,7 +18,7 @@ import GHC.Exts import HaskellWorks.Data.Bits.BitLength import HaskellWorks.Data.Bits.BitWise-import Text.ParserCombinators.Parsec+import HaskellWorks.Data.String.Parse -- | Parsers for bit strings class BitParse a where@@ -33,11 +34,11 @@ p1 = char '0' >> return False instance BitParse Bool where- bitParse0 = option False bitParse1+ bitParse0 = bitParse1 <|> return False bitParse1 = p0 <|> p1 instance BitParse Word8 where- bitParse0 = option 0 bitParse1+ bitParse0 = bitParse1 <|> return 0 bitParse1 = do a :: Bool <- bitParse1 b :: Bool <- bitParse0@@ -58,21 +59,21 @@ (if h then 0x80 else 0) instance BitParse Word16 where- bitParse0 = option 0 bitParse1+ bitParse0 = bitParse1 <|> return 0 bitParse1 = do (a :: Word8) <- bitParse1 (b :: Word8) <- bitParse0 return $ (fromIntegral b .<. bitLength a) .|. fromIntegral a instance BitParse Word32 where- bitParse0 = option 0 bitParse1+ bitParse0 = bitParse1 <|> return 0 bitParse1 = do (a :: Word16) <- bitParse1 (b :: Word16) <- bitParse0 return $ (fromIntegral b .<. bitLength a) .|. fromIntegral a instance BitParse Word64 where- bitParse0 = option 0 bitParse1+ bitParse0 = bitParse1 <|> return 0 bitParse1 = do (a :: Word32) <- bitParse1 (b :: Word32) <- bitParse0@@ -83,49 +84,49 @@ bitParse1 = fmap BS.pack bitParse1 instance BitParse [Word8] where- bitParse0 = option [] bitParse1+ bitParse0 = bitParse1 <|> return [] bitParse1 = many bitParse1 instance BitParse [Word16] where- bitParse0 = option [] bitParse1+ bitParse0 = bitParse1 <|> return [] bitParse1 = many bitParse1 instance BitParse [Word32] where- bitParse0 = option [] bitParse1+ bitParse0 = bitParse1 <|> return [] bitParse1 = many bitParse1 instance BitParse [Word64] where- bitParse0 = option [] bitParse1+ bitParse0 = bitParse1 <|> return [] bitParse1 = many bitParse1 instance BitParse (DV.Vector Word8) where- bitParse0 = option DV.empty bitParse1+ bitParse0 = bitParse1 <|> return DV.empty bitParse1 = fromList `fmap` bitParse0 instance BitParse (DV.Vector Word16) where- bitParse0 = option DV.empty bitParse1+ bitParse0 = bitParse1 <|> return DV.empty bitParse1 = fromList `fmap` bitParse0 instance BitParse (DV.Vector Word32) where- bitParse0 = option DV.empty bitParse1+ bitParse0 = bitParse1 <|> return DV.empty bitParse1 = fromList `fmap` bitParse0 instance BitParse (DV.Vector Word64) where- bitParse0 = option DV.empty bitParse1+ bitParse0 = bitParse1 <|> return DV.empty bitParse1 = fromList `fmap` bitParse0 instance BitParse (DVS.Vector Word8) where- bitParse0 = option DVS.empty bitParse1+ bitParse0 = bitParse1 <|> return DVS.empty bitParse1 = fromList `fmap` bitParse0 instance BitParse (DVS.Vector Word16) where- bitParse0 = option DVS.empty bitParse1+ bitParse0 = bitParse1 <|> return DVS.empty bitParse1 = fromList `fmap` bitParse0 instance BitParse (DVS.Vector Word32) where- bitParse0 = option DVS.empty bitParse1+ bitParse0 = bitParse1 <|> return DVS.empty bitParse1 = fromList `fmap` bitParse0 instance BitParse (DVS.Vector Word64) where- bitParse0 = option DVS.empty bitParse1+ bitParse0 = bitParse1 <|> return DVS.empty bitParse1 = fromList `fmap` bitParse0
src/HaskellWorks/Data/Bits/BitRead.hs view
@@ -1,4 +1,5 @@ {-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE UndecidableInstances #-} module HaskellWorks.Data.Bits.BitRead@@ -6,11 +7,12 @@ ) where import qualified Data.ByteString as BS+import Data.Maybe import qualified Data.Vector as DV import qualified Data.Vector.Storable as DVS import Data.Word import HaskellWorks.Data.Bits.BitParse-import Text.ParserCombinators.Parsec+import HaskellWorks.Data.String.Parse -- | Bit string reader that produces a value of a type class BitRead a where@@ -18,7 +20,7 @@ bitRead :: String -> Maybe a bitRead' :: BitParse a => String -> Maybe a-bitRead' = either (const Nothing) Just . parse bitParse0 "" . filter (/= ' ')+bitRead' s = fst `fmap` listToMaybe (parse bitParse0 (filter (/= ' ') s)) bitCharToBool :: Char -> Maybe Bool bitCharToBool '1' = Just True
src/HaskellWorks/Data/Bits/PackedVector/PackedVector64.hs view
@@ -2,6 +2,7 @@ module HaskellWorks.Data.Bits.PackedVector.PackedVector64 ( PackedVector64(..)+ , empty , fromList , toList ) where@@ -23,13 +24,13 @@ , swBufferLen :: !Int } deriving (Eq, Show) --- empty :: PackedVector64--- empty =--- PackedVector64--- { swBuffer = DVS.empty--- , swBufferLen = 0--- , swBitSize = 1--- }+empty :: PackedVector64+empty =+ PackedVector64+ { swBuffer = DVS.empty+ , swBufferLen = 0+ , swBitSize = 1+ } instance Container PackedVector64 where type Elem PackedVector64 = Word64
test/HaskellWorks/Data/Bits/BitReadSpec.hs view
@@ -10,7 +10,7 @@ import HaskellWorks.Data.Bits.BitShow import Test.Hspec -{-# ANN module ("HLint: ignore Redundant do" :: String) #-}+{-# ANN module ("HLint: Ignore Redundant do" :: String) #-} spec :: Spec spec = describe "HaskellWorks.Data.BitReadSpec" $ do@@ -18,7 +18,7 @@ let w = bitRead "10000000 101" :: Maybe [Bool] in w `shouldBe` Just [True, False, False, False, False, False, False, False, True, False, True] it "bitRead \"10000000 101\" :: Maybe [Word8]"$- let w = bitRead "10000000 101" :: Maybe [Word8] in+ let w = bitRead "10000000 101" :: Maybe [Word8] in w `shouldBe` Just [1, 5] it "bitRead \"11100100 10101111 1\" :: Maybe [Word8]" $ let ws = bitRead "11100100 10101111 1" :: Maybe [Word8] in