1{-# LANGUAGE BangPatterns #-}
4-- Module : Data.Text.Internal.Encoding.Fusion.Common
5-- Copyright : (c) Tom Harper 2008-2009,
6-- (c) Bryan O'Sullivan 2009,
7-- (c) Duncan Coutts 2009,
8-- (c) Jasper Van der Jeugt 2011
11-- Maintainer : bos@serpentine.com
12-- Stability : experimental
13-- Portability : portable
15-- /Warning/: this is an internal module, and does not have a stable
16-- API or name. Use at your own risk!
18-- Fusible 'Stream'-oriented functions for converting between 'Text'
19-- and several common encodings.
21module Data.Text.Internal.Encoding.Fusion.Common
24 -- Restreaming is the act of converting from one 'Stream'
25 -- representation to another.
32import Data.Bits ((.&.))
33import Data.Text.Internal.Fusion (Step(..), Stream(..))
34import Data.Text.Internal.Fusion.Types (RS(..))
35import Data.Text.Internal.Unsafe.Char (ord)
36import Data.Text.Internal.Unsafe.Shift (shiftR)
37import Data.Word (Word8)
39restreamUtf16BE :: Stream Char -> Stream Word8
40restreamUtf16BE (Stream next0 s0 len) = Stream next (RS0 s0) (len * 2)
42 next (RS0 s) = case next0 s of
44 Skip s' -> Skip (RS0 s')
46 | n < 0x10000 -> Yield (fromIntegral $ n `shiftR` 8) $
47 RS1 s' (fromIntegral n)
48 | otherwise -> Yield c1 $ RS3 s' c2 c3 c4
52 c1 = fromIntegral (n1 `shiftR` 18 + 0xD8)
53 c2 = fromIntegral (n1 `shiftR` 10)
55 c3 = fromIntegral (n2 `shiftR` 8 + 0xDC)
57 next (RS1 s x2) = Yield x2 (RS0 s)
58 next (RS2 s x2 x3) = Yield x2 (RS1 s x3)
59 next (RS3 s x2 x3 x4) = Yield x2 (RS2 s x3 x4)
61{-# INLINE restreamUtf16BE #-}
63restreamUtf16LE :: Stream Char -> Stream Word8
64restreamUtf16LE (Stream next0 s0 len) = Stream next (RS0 s0) (len * 2)
66 next (RS0 s) = case next0 s of
68 Skip s' -> Skip (RS0 s')
70 | n < 0x10000 -> Yield (fromIntegral n) $
71 RS1 s' (fromIntegral $ shiftR n 8)
72 | otherwise -> Yield c1 $ RS3 s' c2 c3 c4
76 c2 = fromIntegral (shiftR n1 18 + 0xD8)
77 c1 = fromIntegral (shiftR n1 10)
79 c4 = fromIntegral (shiftR n2 8 + 0xDC)
81 next (RS1 s x2) = Yield x2 (RS0 s)
82 next (RS2 s x2 x3) = Yield x2 (RS1 s x3)
83 next (RS3 s x2 x3 x4) = Yield x2 (RS2 s x3 x4)
85{-# INLINE restreamUtf16LE #-}
87restreamUtf32BE :: Stream Char -> Stream Word8
88restreamUtf32BE (Stream next0 s0 len) = Stream next (RS0 s0) (len * 2)
90 next (RS0 s) = case next0 s of
92 Skip s' -> Skip (RS0 s')
93 Yield x s' -> Yield c1 (RS3 s' c2 c3 c4)
96 c1 = fromIntegral $ shiftR n 24
97 c2 = fromIntegral $ shiftR n 16
98 c3 = fromIntegral $ shiftR n 8
100 next (RS1 s x2) = Yield x2 (RS0 s)
101 next (RS2 s x2 x3) = Yield x2 (RS1 s x3)
102 next (RS3 s x2 x3 x4) = Yield x2 (RS2 s x3 x4)
104{-# INLINE restreamUtf32BE #-}
106restreamUtf32LE :: Stream Char -> Stream Word8
107restreamUtf32LE (Stream next0 s0 len) = Stream next (RS0 s0) (len * 2)
109 next (RS0 s) = case next0 s of
111 Skip s' -> Skip (RS0 s')
112 Yield x s' -> Yield c1 (RS3 s' c2 c3 c4)
115 c4 = fromIntegral $ shiftR n 24
116 c3 = fromIntegral $ shiftR n 16
117 c2 = fromIntegral $ shiftR n 8
119 next (RS1 s x2) = Yield x2 (RS0 s)
120 next (RS2 s x2 x3) = Yield x2 (RS1 s x3)
121 next (RS3 s x2 x3 x4) = Yield x2 (RS2 s x3 x4)
123{-# INLINE restreamUtf32LE #-}
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