Commits

Mikhail Vorozhtsov  committed 0afd100

Added Chunk.chunkElemToChar, needed to implement CharParsing.satisfy in ekmett/parsers.

  • Participants
  • Parent commits a09a5f0

Comments (0)

Files changed (1)

File Data/Attoparsec/Internal/Types.hs

 import Data.ByteString (ByteString)
 import qualified Data.ByteString as BS
 import qualified Data.ByteString.Unsafe as BS
+import Data.ByteString.Internal (w2c)
 import Data.Text (Text)
 import qualified Data.Text as T
 import qualified Data.Text.Unsafe as T
   unsafeChunkTail :: c -> c
   -- | Check if the chunk has the length of at least @n@ elements.
   chunkLengthAtLeast :: c -> Int -> Bool
+  -- | Map an element to the corresponding character.
+  --   The first argument is ignored.
+  chunkElemToChar :: c -> ChunkElem c -> Char
 
 instance Chunk ByteString where
   type ChunkElem ByteString = Word8
   {-# INLINE unsafeChunkTail #-}
   chunkLengthAtLeast bs n = BS.length bs >= n
   {-# INLINE chunkLengthAtLeast #-}
+  chunkElemToChar = const w2c
+  {-# INLINE chunkElemToChar #-}
 
 instance Chunk Text where
   type ChunkElem Text = Char
   {-# INLINE unsafeChunkTail #-}
   chunkLengthAtLeast t n = T.lengthWord16 t `quot` 2 >= n || T.length t >= n
   {-# INLINE chunkLengthAtLeast #-}
+  chunkElemToChar = const id
+  {-# INLINE chunkElemToChar #-}