1{-# OPTIONS_GHC -Wall -fno-warn-name-shadowing #-}
2{-# LANGUAGE BangPatterns, EmptyDataDecls, FlexibleInstances #-}
13import Prelude hiding (String)
14import Data.Binary (Binary, get, put)
15import Data.Bits ((.&.), shiftR)
16import qualified Data.ByteString.Builder as B
17import qualified Data.Utf8 as Utf8
18import Data.Utf8 (MBA, newByteArray, copyFromPtr, freeze, writeWord8)
19import GHC.Exts (RealWorld, Ptr)
20import GHC.IO (stToIO, unsafeDupablePerformIO)
22import GHC.Word (Word8)
40toChars :: String -> [Char]
45{-# INLINE toBuilder #-}
46toBuilder :: String -> B.Builder
56 = Slice (Ptr Word8) Int
61fromChunks :: [Chunk] -> String
63 unsafeDupablePerformIO (stToIO (
64 do let !len = sum (map chunkToWidth chunks)
65 mba <- newByteArray len
66 writeChunks mba 0 chunks
71chunkToWidth :: Chunk -> Int
76 CodePoint c -> if c < 0xFFFF then 6 else 12
79writeChunks :: MBA RealWorld -> Int -> [Chunk] -> ST RealWorld ()
80writeChunks mba offset chunks =
88 do copyFromPtr ptr mba offset len
89 let !newOffset = offset + len
90 writeChunks mba newOffset chunks
93 do writeWord8 mba offset 0x5C {- \ -}
94 writeWord8 mba (offset + 1) word
95 let !newOffset = offset + 2
96 writeChunks mba newOffset chunks
100 do writeCode mba offset code
101 let !newOffset = offset + 6
102 writeChunks mba newOffset chunks
104 do let (hi,lo) = divMod (code - 0x10000) 0x400
105 writeCode mba (offset ) (hi + 0xD800)
106 writeCode mba (offset + 6) (lo + 0xDC00)
107 let !newOffset = offset + 12
108 writeChunks mba newOffset chunks
111writeCode :: MBA RealWorld -> Int -> Int -> ST RealWorld ()
112writeCode mba offset code =
113 do writeWord8 mba offset 0x5C {- \ -}
114 writeWord8 mba (offset + 1) 0x75 {- u -}
115 writeHex mba (offset + 2) (shiftR code 12)
116 writeHex mba (offset + 3) (shiftR code 8)
117 writeHex mba (offset + 4) (shiftR code 4)
118 writeHex mba (offset + 5) code
121writeHex :: MBA RealWorld -> Int -> Int -> ST RealWorld ()
122writeHex mba !offset !bits =
123 do let !n = fromIntegral bits .&. 0x0F
124 writeWord8 mba offset (if n < 10 then 0x30 + n else 0x37 + n)
131instance Binary (Utf8.Utf8 ELM_STRING) where
132 get = Utf8.getVeryLong
133 put = Utf8.putVeryLong
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