aboutsummaryrefslogtreecommitdiffhomepage
path: root/Pipes
diff options
context:
space:
mode:
authormichaelt <what_is_it_to_do_anything@yahoo.com>2014-02-05 00:20:11 -0500
committermichaelt <what_is_it_to_do_anything@yahoo.com>2014-02-05 00:20:11 -0500
commit4da91c37355b3d688c9dfc6f92ae92266ad4e883 (patch)
treee523b43654e0dc6dfb5d7a39115aca8bb4b2d1e2 /Pipes
parent7c9f2b8b11f51b2a4e9dcd6e8168e34f1135d6e2 (diff)
downloadtext-pipes-4da91c37355b3d688c9dfc6f92ae92266ad4e883.tar.gz
text-pipes-4da91c37355b3d688c9dfc6f92ae92266ad4e883.tar.zst
text-pipes-4da91c37355b3d688c9dfc6f92ae92266ad4e883.zip
little Haddock notes on Internal material
Diffstat (limited to 'Pipes')
-rw-r--r--Pipes/Text/Internal/Codec.hs13
-rw-r--r--Pipes/Text/Internal/Decoding.hs16
2 files changed, 18 insertions, 11 deletions
diff --git a/Pipes/Text/Internal/Codec.hs b/Pipes/Text/Internal/Codec.hs
index 4b9367f..63cbd74 100644
--- a/Pipes/Text/Internal/Codec.hs
+++ b/Pipes/Text/Internal/Codec.hs
@@ -3,8 +3,12 @@
3-- | 3-- |
4-- Copyright: 2014 Michael Thompson, 2011 Michael Snoyman, 2010-2011 John Millikin 4-- Copyright: 2014 Michael Thompson, 2011 Michael Snoyman, 2010-2011 John Millikin
5-- License: MIT 5-- License: MIT
6-- 6-- This Parts of this code were taken from enumerator and conduits, and adapted for pipes
7-- Parts of this code were taken from enumerator and conduits, and adapted for pipes. 7{- | This module follows the model of the enumerator and conduits libraries, and defines
8 'Codec' s for various encodings. Note that we do not export a 'Codec' for ascii and
9 iso8859_1. A 'Lens' in the sense of the pipes library cannot be defined for these, so
10 special functions appear in @Pipes.Text@
11-}
8 12
9module Pipes.Text.Internal.Codec 13module Pipes.Text.Internal.Codec
10 ( Decoding(..) 14 ( Decoding(..)
@@ -41,12 +45,11 @@ import Data.Maybe (catMaybes)
41import Pipes.Text.Internal.Decoding 45import Pipes.Text.Internal.Decoding
42import Pipes 46import Pipes
43-- | A specific character encoding. 47-- | A specific character encoding.
44-- 48
45-- Since 0.3.0
46data Codec = Codec 49data Codec = Codec
47 { codecName :: Text 50 { codecName :: Text
48 , codecEncode :: Text -> (ByteString, Maybe (TextException, Text)) 51 , codecEncode :: Text -> (ByteString, Maybe (TextException, Text))
49 , codecDecode :: ByteString -> Decoding -- (Text, Either (TextException, ByteString) ByteString) 52 , codecDecode :: ByteString -> Decoding
50 } 53 }
51 54
52instance Show Codec where 55instance Show Codec where
diff --git a/Pipes/Text/Internal/Decoding.hs b/Pipes/Text/Internal/Decoding.hs
index 531104a..4b4bbe6 100644
--- a/Pipes/Text/Internal/Decoding.hs
+++ b/Pipes/Text/Internal/Decoding.hs
@@ -2,9 +2,11 @@
2{-# LANGUAGE GeneralizedNewtypeDeriving, MagicHash, UnliftedFFITypes #-} 2{-# LANGUAGE GeneralizedNewtypeDeriving, MagicHash, UnliftedFFITypes #-}
3{-# LANGUAGE DeriveDataTypeable, RankNTypes #-} 3{-# LANGUAGE DeriveDataTypeable, RankNTypes #-}
4 4
5-- This module lifts assorted materials from Brian O'Sullivan's text package 5{- |
6-- especially Data.Text.Encoding in order to define a pipes-appropriate 6This module lifts assorted materials from Brian O'Sullivan's text package
7-- streamDecodeUtf8 7especially @Data.Text.Encoding@ in order to define a pipes-appropriate
8'streamDecodeUtf8'
9-}
8module Pipes.Text.Internal.Decoding 10module Pipes.Text.Internal.Decoding
9 ( Decoding(..) 11 ( Decoding(..)
10 , streamDecodeUtf8 12 , streamDecodeUtf8
@@ -41,9 +43,9 @@ import Data.Maybe (catMaybes)
41 43
42 44
43 45
44-- | A stream oriented decoding result. 46-- | A stream oriented decoding result. Distinct from the similar type in @Data.Text.Encoding@
45data Decoding = Some Text ByteString (ByteString -> Decoding) 47data Decoding = Some Text ByteString (ByteString -> Decoding) -- | Text, continuation and any undecoded fragment.
46 | Other Text ByteString 48 | Other Text ByteString -- | Text followed by an undecodable ByteString
47instance Show Decoding where 49instance Show Decoding where
48 showsPrec d (Some t bs _) = showParen (d > prec) $ 50 showsPrec d (Some t bs _) = showParen (d > prec) $
49 showString "Some " . showsPrec prec' t . 51 showString "Some " . showsPrec prec' t .
@@ -59,6 +61,7 @@ instance Show Decoding where
59newtype CodePoint = CodePoint Word32 deriving (Eq, Show, Num, Storable) 61newtype CodePoint = CodePoint Word32 deriving (Eq, Show, Num, Storable)
60newtype DecoderState = DecoderState Word32 deriving (Eq, Show, Num, Storable) 62newtype DecoderState = DecoderState Word32 deriving (Eq, Show, Num, Storable)
61 63
64-- | Resolve a 'ByteString' into 'Text' and a continuation that can handle further 'ByteStrings'.
62streamDecodeUtf8 :: ByteString -> Decoding 65streamDecodeUtf8 :: ByteString -> Decoding
63streamDecodeUtf8 = decodeChunkUtf8 B.empty 0 0 66streamDecodeUtf8 = decodeChunkUtf8 B.empty 0 0
64 where 67 where
@@ -92,6 +95,7 @@ streamDecodeUtf8 = decodeChunkUtf8 B.empty 0 0
92 {-# INLINE decodeChunkUtf8 #-} 95 {-# INLINE decodeChunkUtf8 #-}
93{-# INLINE streamDecodeUtf8 #-} 96{-# INLINE streamDecodeUtf8 #-}
94 97
98-- | Resolve a ByteString into an initial segment of intelligible 'Text' and whatever is unintelligble
95decodeSomeUtf8 :: ByteString -> (Text, ByteString) 99decodeSomeUtf8 :: ByteString -> (Text, ByteString)
96decodeSomeUtf8 bs@(PS fp off len) = runST $ do 100decodeSomeUtf8 bs@(PS fp off len) = runST $ do
97 dest <- A.new (len+1) 101 dest <- A.new (len+1)