1{-# LANGUAGE MagicHash #-}
4-- Module : Data.Text.UnsafeChar
5-- Copyright : (c) Tom Harper 2008-2009,
6-- (c) Bryan O'Sullivan 2009,
7-- (c) Duncan Coutts 2009
10-- Maintainer : bos@serpentine.com, rtharper@aftereternity.co.uk,
12-- Stability : experimental
15-- Fast character manipulation functions.
16module Data.Text.UnsafeChar
25import Control.Exception (assert)
26import Control.Monad.ST (ST)
27import Data.Bits ((.&.))
29import Data.Text.UnsafeShift (shiftR)
30import GHC.Exts (Char(..), chr#, word2Int#)
31import GHC.Word (Word8(..), Word16(..), Word32(..))
32import qualified Data.Text.Array as A
34unsafeChr :: Word16 -> Char
35unsafeChr (W16# w#) = C# (chr# (word2Int# w#))
36{-# INLINE unsafeChr #-}
38unsafeChr8 :: Word8 -> Char
39unsafeChr8 (W8# w#) = C# (chr# (word2Int# w#))
40{-# INLINE unsafeChr8 #-}
42unsafeChr32 :: Word32 -> Char
43unsafeChr32 (W32# w#) = C# (chr# (word2Int# w#))
44{-# INLINE unsafeChr32 #-}
46unsafeWrite :: A.MArray s Word16 -> Int -> Char -> ST s Int
49 assert (i >= 0) . assert (i < A.length marr) $
50 A.unsafeWrite marr i (fromIntegral n)
53 assert (i >= 0) . assert (i < A.length marr - 1) $
54 A.unsafeWrite marr i lo
55 A.unsafeWrite marr (i+1) hi
59 lo = fromIntegral $ (m `shiftR` 10) + 0xD800
60 hi = fromIntegral $ (m .&. 0x3FF) + 0xDC00
61{-# INLINE unsafeWrite #-}
64unsafeWriteRev :: A.MArray s Word16 -> Int -> Char -> ST s Int
65unsafeWriteRev marr i c
67 assert (i >= 0) . assert (i < A.length marr) $
68 A.unsafeWrite marr i (fromIntegral n)
71 assert (i >= 1) . assert (i < A.length marr) $
72 A.unsafeWrite marr (i-1) lo
73 A.unsafeWrite marr i hi
77 lo = fromIntegral $ (m `shiftR` 10) + 0xD800
78 hi = fromIntegral $ (m .&. 0x3FF) + 0xDC00
79{-# INLINE unsafeWriteRev #-}
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