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 : rtharper@aftereternity.co.uk, bos@serpentine.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
29 -- * Encoding Text to ByteStrings
37import Data.ByteString (ByteString)
38import qualified Data.Text.Fusion as F
39import qualified Data.Text.Encoding.Fusion as E
40import Data.Text.Internal (Text)
42-- | Decode a 'ByteString' containing 7-bit ASCII encoded text.
43decodeASCII :: ByteString -> Text
44decodeASCII bs = F.unstream (E.streamASCII bs)
45{-# INLINE decodeASCII #-}
47-- | Decode a 'ByteString' containing UTF-8 encoded text.
48decodeUtf8 :: ByteString -> Text
49decodeUtf8 bs = F.unstream (E.streamUtf8 bs)
50{-# INLINE decodeUtf8 #-}
52-- | Encode text using UTF-8 encoding.
53encodeUtf8 :: Text -> ByteString
54encodeUtf8 txt = E.unstream (E.restreamUtf8 (F.stream txt))
55{-# INLINE encodeUtf8 #-}
57-- | Decode text from little endian UTF-16 encoding.
58decodeUtf16LE :: ByteString -> Text
59decodeUtf16LE bs = F.unstream (E.streamUtf16LE bs)
60{-# INLINE decodeUtf16LE #-}
62-- | Decode text from big endian UTF-16 encoding.
63decodeUtf16BE :: ByteString -> Text
64decodeUtf16BE bs = F.unstream (E.streamUtf16BE bs)
65{-# INLINE decodeUtf16BE #-}
67-- | Encode text using little endian UTF-16 encoding.
68encodeUtf16LE :: Text -> ByteString
69encodeUtf16LE txt = E.unstream (E.restreamUtf16LE (F.stream txt))
70{-# INLINE encodeUtf16LE #-}
72-- | Encode text using big endian UTF-16 encoding.
73encodeUtf16BE :: Text -> ByteString
74encodeUtf16BE txt = E.unstream (E.restreamUtf16BE (F.stream txt))
75{-# INLINE encodeUtf16BE #-}
77-- | Decode text from little endian UTF-32 encoding.
78decodeUtf32LE :: ByteString -> Text
79decodeUtf32LE bs = F.unstream (E.streamUtf32LE bs)
80{-# INLINE decodeUtf32LE #-}
82-- | Decode text from big endian UTF-32 encoding.
83decodeUtf32BE :: ByteString -> Text
84decodeUtf32BE bs = F.unstream (E.streamUtf32BE bs)
85{-# INLINE decodeUtf32BE #-}
87-- | Encode text using little endian UTF-32 encoding.
88encodeUtf32LE :: Text -> ByteString
89encodeUtf32LE txt = E.unstream (E.restreamUtf32LE (F.stream txt))
90{-# INLINE encodeUtf32LE #-}
92-- | Encode text using big endian UTF-32 encoding.
93encodeUtf32BE :: Text -> ByteString
94encodeUtf32BE txt = E.unstream (E.restreamUtf32BE (F.stream txt))
95{-# 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