module Pipes.Text.Internal
- ( Decoding(..)
- , streamDecodeUtf8
- , decodeSomeUtf8
- , Codec(..)
- , TextException(..)
- , utf8
- , utf16_le
- , utf16_be
- , utf32_le
- , utf32_be
+ (module Pipes.Text.Internal.Codec
+ , module Pipes.Text.Internal.Decoding
) where
-import Pipes.Text.Internal.Decoding
-import Pipes.Text.Internal.Codec
\ No newline at end of file
+import Pipes.Text.Internal.Codec
+import Pipes.Text.Internal.Decoding
\ No newline at end of file
-- Copyright: 2014 Michael Thompson, 2011 Michael Snoyman, 2010-2011 John Millikin
-- License: MIT
-- This Parts of this code were taken from enumerator and conduits, and adapted for pipes
-{- | This module follows the model of the enumerator and conduits libraries, and defines
- 'Codec' s for various encodings. Note that we do not export a 'Codec' for ascii and
- iso8859_1. A 'Lens' in the sense of the pipes library cannot be defined for these, so
- special functions appear in @Pipes.Text@
--}
+
+-- This module follows the model of the enumerator and conduits libraries, and defines
+-- 'Codec' s for various encodings. Note that we do not export a 'Codec' for ascii and
+-- iso8859_1. A 'Lens' in the sense of the pipes library cannot be defined for these, so
+-- special functions appear in @Pipes.Text@
+
module Pipes.Text.Internal.Codec
- ( Decoding(..)
- , streamDecodeUtf8
- , decodeSomeUtf8
- , Codec(..)
+ ( Codec(..)
, TextException(..)
, utf8
, utf16_le
{-# LANGUAGE GeneralizedNewtypeDeriving, MagicHash, UnliftedFFITypes #-}
{-# LANGUAGE DeriveDataTypeable, RankNTypes #-}
-{- |
-This module lifts assorted materials from Brian O'Sullivan's text package
-especially @Data.Text.Encoding@ in order to define a pipes-appropriate
-'streamDecodeUtf8'
--}
+-- This module lifts assorted materials from Brian O'Sullivan's text package
+-- especially @Data.Text.Encoding@ in order to define a pipes-appropriate
+-- 'streamDecodeUtf8'
+
module Pipes.Text.Internal.Decoding
( Decoding(..)
, streamDecodeUtf8
--- | A stream oriented decoding result. Distinct from the similar type in @Data.Text.Encoding@
-data Decoding = Some Text ByteString (ByteString -> Decoding) -- | Text, continuation and any undecoded fragment.
- | Other Text ByteString -- | Text followed by an undecodable ByteString
+-- A stream oriented decoding result. Distinct from the similar type in Data.Text.Encoding
+
+data Decoding = Some Text ByteString (ByteString -> Decoding)
+ -- Text, continuation and any undecoded fragment.
+ | Other Text ByteString
+ -- Text followed by an undecodable ByteString
+
instance Show Decoding where
showsPrec d (Some t bs _) = showParen (d > prec) $
showString "Some " . showsPrec prec' t .
newtype CodePoint = CodePoint Word32 deriving (Eq, Show, Num, Storable)
newtype DecoderState = DecoderState Word32 deriving (Eq, Show, Num, Storable)
--- | Resolve a 'ByteString' into 'Text' and a continuation that can handle further 'ByteStrings'.
+-- Resolve a 'ByteString' into 'Text' and a continuation that can handle further 'ByteStrings'.
streamDecodeUtf8 :: ByteString -> Decoding
streamDecodeUtf8 = decodeChunkUtf8 B.empty 0 0
where
{-# INLINE decodeChunkUtf8 #-}
{-# INLINE streamDecodeUtf8 #-}
--- | Resolve a ByteString into an initial segment of intelligible 'Text' and whatever is unintelligble
+-- Resolve a ByteString into an initial segment of intelligible 'Text' and whatever is unintelligble
decodeSomeUtf8 :: ByteString -> (Text, ByteString)
decodeSomeUtf8 bs@(PS fp off len) = runST $ do
dest <- A.new (len+1)