packages feed

bytestring-encodings 0.2.0.1 → 0.2.0.2

raw patch · 5 files changed

+44/−16 lines, 5 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

- Data.ByteString.Internal.Utf8: instance GHC.Classes.Eq Data.ByteString.Internal.Utf8.Utf8

Files

Data/ByteString/Internal/Ascii.hs view
@@ -1,13 +1,19 @@+--------------------------------------------------------------------------------+ {-# LANGUAGE BangPatterns #-} {-# LANGUAGE MagicHash #-} {-# LANGUAGE NoImplicitPrelude #-}  {-# OPTIONS_GHC -O2 #-} +--------------------------------------------------------------------------------+ module Data.ByteString.Internal.Ascii   ( isAscii   ) where +--------------------------------------------------------------------------------+ import Data.Bits ((.&.)) import Data.ByteString.Internal (ByteString(..), accursedUnutterablePerformIO) import Data.Word (Word8, Word64)@@ -18,6 +24,8 @@  import qualified Data.ByteString as B +--------------------------------------------------------------------------------+ -- | Binary:  1000000010000000100000001000000010000000100000001000000010000000 --   Decimal: 9259542123273814144 m64 :: Word64@@ -30,6 +38,8 @@ {-# inline m8 #-} m8 = 0x80 +--------------------------------------------------------------------------------+ isAsciiPtrW64 :: Ptr Word64 -> Ptr Word64 -> IO Bool isAsciiPtrW64 !p !q   | p == q    = pure True@@ -48,6 +58,8 @@         then isAsciiPtrW8 (p `plusPtr` 1) q         else pure False +--------------------------------------------------------------------------------+ isAsciiW64 :: Word64 -> Bool {-# inline isAsciiW64 #-} isAsciiW64 !w = w .&. m64 == 0@@ -60,6 +72,8 @@ {-# inline isAsciiSmall #-} isAsciiSmall !b = B.all (< m8) b +--------------------------------------------------------------------------------+ alignPtrPos :: Ptr a -> Ptr a {-# inline alignPtrPos #-} alignPtrPos addr@(Ptr a) @@ -74,7 +88,10 @@       0# -> addr       n  -> Ptr (plusAddr# a (negateInt# n)) --- | 'isAscii' can tell if a given 'ByteString' is ASCII-encoded.+--------------------------------------------------------------------------------++-- | /O(n\/8)/ detremine if a 'ByteString' is+--   ASCII-encoded. isAscii :: ByteString -> Bool {-# inline isAscii #-} isAscii   (PS _ _ 0)  = True@@ -104,3 +121,5 @@                   then isAsciiPtrW64 startMid endMid                   else pure False               else pure False++--------------------------------------------------------------------------------
Data/ByteString/Internal/Utf8.hs view
@@ -1,14 +1,20 @@+--------------------------------------------------------------------------------+ {-# LANGUAGE BangPatterns #-} {-# LANGUAGE MagicHash #-} {-# LANGUAGE NoImplicitPrelude #-}  {-# OPTIONS_GHC -O2 #-} +--------------------------------------------------------------------------------+ module Data.ByteString.Internal.Utf8   ( isUtf8    , isUtf8'    ) where +--------------------------------------------------------------------------------+ import Data.Bits ((.&.)) import Data.ByteString.Internal (ByteString(..), accursedUnutterablePerformIO) import Data.ByteString.Internal.Ascii (isAscii)@@ -18,8 +24,10 @@ import Foreign.ForeignPtr (withForeignPtr) import Foreign.Storable (peek) +--------------------------------------------------------------------------------+ data Utf8 = U8 | U16 | U24 | U32 | UNot-  deriving Eq+--  deriving Eq  which :: Word8 -> Utf8 {-# inline which #-}@@ -30,6 +38,8 @@   | isUtf8b32 c = U32   | otherwise   = UNot +--------------------------------------------------------------------------------+ isUtf8Ptr :: Ptr Word8 -> Ptr Word8 -> IO Bool isUtf8Ptr !p !q   | p == q    = pure True@@ -55,6 +65,8 @@                  else pure False         UNot -> pure False +--------------------------------------------------------------------------------+ -- Hex:     0x80 -- Binary:  10000000 -- Decimal: 128@@ -91,6 +103,8 @@ {-# inline isUtf8OtherBytes #-} isUtf8OtherBytes !w = w .&. 0xC0 == 0x80 +--------------------------------------------------------------------------------+ -- | 'isUtf8' firsts calls the very fast 'isAscii' to see if --    the data is ASCII (and thus UTF-8). Use this if you know most of your --    data is ASCII-encoded.@@ -98,17 +112,10 @@ --    best to use 'isUtf8'' to avoid this check. isUtf8 :: ByteString -> Bool isUtf8   (PS _ _ 0) = True-isUtf8 b@(PS fp (I# o#) (I# l#)) = if isAscii b then True else-  accursedUnutterablePerformIO-    $ withForeignPtr fp-      $ \(Ptr addr) ->-        do-          let-            start, end :: Ptr Word8-            start = Ptr (plusAddr# addr o#)-            end   = Ptr (plusAddr# addr (o# +# l#))-            -          isUtf8Ptr start end+isUtf8 b =+  if isAscii b+  then True+  else isUtf8' b {-# inline isUtf8 #-}  -- | 'isUtf8'' does not call 'isAscii'. Use this if@@ -129,3 +136,5 @@                        isUtf8Ptr start end {-# inline isUtf8' #-}++--------------------------------------------------------------------------------
bytestring-encodings.cabal view
@@ -1,7 +1,7 @@ name:   bytestring-encodings version:-  0.2.0.1+  0.2.0.2 synopsis:   checks to see if a given bytestring adheres to a certain encoding  description:
tests/Ascii.hs view
@@ -6,7 +6,7 @@  import Control.Applicative (liftA2) import Data.Bits ((.&.), xor)-import Data.ByteString.Ascii (isAscii)+import Data.ByteString.Encodings (isAscii) import Data.Word (Word8, Word64) import Hedgehog import qualified Hedgehog.Gen as Gen
tests/Utf8.hs view
@@ -12,7 +12,7 @@ import Control.Applicative (liftA2) import Control.Monad (join, sequence) import Data.Bits ((.&.), xor)-import Data.ByteString.Utf8 (isUtf8)+import Data.ByteString.Encodings (isUtf8) import Data.Char (chr) import Data.Foldable (foldl') import Data.Word (Word8)