@@ -31,6 +31,7 @@ import Control.Monad (MonadPlus(..))
3131import Data.Word (Word8)
3232import Data.ByteString (ByteString)
3333import qualified Data.ByteString as BS
34+import Data.ByteString.Internal (w2c)
3435import Data.Monoid (Monoid(..))
3536import Data.Text (Text)
3637import qualified Data.Text as Text
@@ -214,6 +215,9 @@ class Monoid c => Chunk c where
214215 atBufferEnd :: c -> State c -> Pos
215216 -- | Return the buffer element at the given position along with its length.
216217 bufferElemAt :: c -> Pos -> State c -> Maybe (ChunkElem c, Int)
218+ -- | Map an element to the corresponding character.
219+ -- The first argument is ignored.
220+ chunkElemToChar :: c -> ChunkElem c -> Char
217221
218222instance Chunk ByteString where
219223 type ChunkElem ByteString = Word8
@@ -227,6 +231,8 @@ instance Chunk ByteString where
227231 | i < B.length buf = Just (B.unsafeIndex buf i, 1)
228232 | otherwise = Nothing
229233 {-# INLINE bufferElemAt #-}
234+ chunkElemToChar _ = w2c
235+ {-# INLINE chunkElemToChar #-}
230236
231237instance Chunk Text where
232238 type ChunkElem Text = Char
@@ -240,3 +246,5 @@ instance Chunk Text where
240246 | i < T.length buf = let Iter c l = T.iter buf i in Just (c, l)
241247 | otherwise = Nothing
242248 {-# INLINE bufferElemAt #-}
249+ chunkElemToChar _ = id
250+ {-# INLINE chunkElemToChar #-}