2-- Module : Data.Text.Encoding
3-- Copyright : (c) Tom Harper 2008-2009,
4-- (c) Bryan O'Sullivan 2009,
5-- (c) Duncan Coutts 2009
8-- Maintainer : bos@serpentine.com, rtomharper@googlemail.com,
10-- Stability : experimental
11-- Portability : portable
13-- Functions for converting 'Text' values to and from 'ByteString',
14-- using several standard encodings.
16-- To make use of a much larger variety of encodings, use the @text-icu@
19module Data.Text.Encoding
21 -- * Decoding ByteStrings to Text
28 -- ** Controllable error handling
35 -- * Encoding Text to ByteStrings
43import Data.ByteString (ByteString)
44import qualified Data.Text.Fusion as F
45import Data.Text.Encoding.Error (OnDecodeError, strictDecode)
46import qualified Data.Text.Encoding.Fusion as E
47import Data.Text.Internal (Text)
49-- | Decode a 'ByteString' containing 7-bit ASCII encoded text.
50decodeASCII :: ByteString -> Text
51decodeASCII bs = F.unstream (E.streamASCII bs)
52{-# INLINE decodeASCII #-}
54-- | Decode a 'ByteString' containing UTF-8 encoded text.
55decodeUtf8With :: OnDecodeError -> ByteString -> Text
56decodeUtf8With onErr bs = F.unstream (E.streamUtf8 onErr bs)
57{-# INLINE decodeUtf8With #-}
59-- | Decode a 'ByteString' containing UTF-8 encoded text.
60decodeUtf8 :: ByteString -> Text
61decodeUtf8 = decodeUtf8With strictDecode
62{-# INLINE decodeUtf8 #-}
64-- | Encode text using UTF-8 encoding.
65encodeUtf8 :: Text -> ByteString
66encodeUtf8 txt = E.unstream (E.restreamUtf8 (F.stream txt))
67{-# INLINE encodeUtf8 #-}
69-- | Decode text from little endian UTF-16 encoding.
70decodeUtf16LEWith :: OnDecodeError -> ByteString -> Text
71decodeUtf16LEWith onErr bs = F.unstream (E.streamUtf16LE onErr bs)
72{-# INLINE decodeUtf16LEWith #-}
74-- | Decode text from little endian UTF-16 encoding.
75decodeUtf16LE :: ByteString -> Text
76decodeUtf16LE = decodeUtf16LEWith strictDecode
77{-# INLINE decodeUtf16LE #-}
79-- | Decode text from big endian UTF-16 encoding.
80decodeUtf16BEWith :: OnDecodeError -> ByteString -> Text
81decodeUtf16BEWith onErr bs = F.unstream (E.streamUtf16BE onErr bs)
82{-# INLINE decodeUtf16BEWith #-}
84-- | Decode text from big endian UTF-16 encoding.
85decodeUtf16BE :: ByteString -> Text
86decodeUtf16BE = decodeUtf16BEWith strictDecode
87{-# INLINE decodeUtf16BE #-}
89-- | Encode text using little endian UTF-16 encoding.
90encodeUtf16LE :: Text -> ByteString
91encodeUtf16LE txt = E.unstream (E.restreamUtf16LE (F.stream txt))
92{-# INLINE encodeUtf16LE #-}
94-- | Encode text using big endian UTF-16 encoding.
95encodeUtf16BE :: Text -> ByteString
96encodeUtf16BE txt = E.unstream (E.restreamUtf16BE (F.stream txt))
97{-# INLINE encodeUtf16BE #-}
99-- | Decode text from little endian UTF-32 encoding.
100decodeUtf32LEWith :: OnDecodeError -> ByteString -> Text
101decodeUtf32LEWith onErr bs = F.unstream (E.streamUtf32LE onErr bs)
102{-# INLINE decodeUtf32LEWith #-}
104-- | Decode text from little endian UTF-32 encoding.
105decodeUtf32LE :: ByteString -> Text
106decodeUtf32LE = decodeUtf32LEWith strictDecode
107{-# INLINE decodeUtf32LE #-}
109-- | Decode text from big endian UTF-32 encoding.
110decodeUtf32BEWith :: OnDecodeError -> ByteString -> Text
111decodeUtf32BEWith onErr bs = F.unstream (E.streamUtf32BE onErr bs)
112{-# INLINE decodeUtf32BEWith #-}
114-- | Decode text from big endian UTF-32 encoding.
115decodeUtf32BE :: ByteString -> Text
116decodeUtf32BE = decodeUtf32BEWith strictDecode
117{-# INLINE decodeUtf32BE #-}
119-- | Encode text using little endian UTF-32 encoding.
120encodeUtf32LE :: Text -> ByteString
121encodeUtf32LE txt = E.unstream (E.restreamUtf32LE (F.stream txt))
122{-# INLINE encodeUtf32LE #-}
124-- | Encode text using big endian UTF-32 encoding.
125encodeUtf32BE :: Text -> ByteString
126encodeUtf32BE txt = E.unstream (E.restreamUtf32BE (F.stream txt))
127{-# INLINE encodeUtf32BE #-}
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list