+ return $! (chunkText, remaining)
+{-# INLINE decodeSomeUtf8 #-}
+
+-- decodeSomeUtf8 :: ByteString -> (Text, ByteString)
+-- decodeSomeUtf8 bs@(PS fp off len) =
+-- runST $ do marray <- A.new (len+1)
+-- unsafeIOToST (decodeChunkToBuffer marray)
+--
+-- where
+-- decodeChunkToBuffer :: A.MArray s -> IO (Text, ByteString)
+-- decodeChunkToBuffer dest = withForeignPtr fp $ \ptr ->
+-- with (0::CSize) $ \destOffPtr ->
+-- with (0::CodePoint) $ \codepointPtr ->
+-- with (0::DecoderState) $ \statePtr ->
+-- with nullPtr $ \curPtrPtr ->
+-- do let end = ptr `plusPtr` (off + len)
+-- curPtr = ptr `plusPtr` off
+-- poke curPtrPtr curPtr
+-- c_decode_utf8_with_state (A.maBA dest) destOffPtr curPtrPtr end codepointPtr statePtr
+-- state <- peek statePtr
+-- lastPtr <- peek curPtrPtr
+-- codepoint <- peek codepointPtr
+-- n <- peek destOffPtr
+-- chunkText <- unsafeSTToIO $ do arr <- A.unsafeFreeze dest
+-- return $! textP arr 0 (fromIntegral n)
+-- let left = lastPtr `minusPtr` curPtr
+-- remaining = B.drop left bs
+-- return $! (chunkText, remaining)
+-- {-# INLINE decodeChunkToBuffer #-}
+-- {-# INLINE decodeSomeUtf8 #-}
+