1{-# LANGUAGE CPP, MagicHash #-}
4-- Module : Data.Text.UnsafeChar
5-- Copyright : (c) 2008, 2009 Tom Harper,
6-- (c) 2009, 2010 Bryan O'Sullivan,
7-- (c) 2009 Duncan Coutts
10-- Maintainer : bos@serpentine.com, rtomharper@googlemail.com,
12-- Stability : experimental
15-- Fast character manipulation functions.
16module Data.Text.UnsafeChar
27import Control.Exception (assert)
29import Control.Monad.ST (ST)
30import Data.Bits ((.&.))
31import Data.Text.UnsafeShift (shiftR)
32import GHC.Exts (Char(..), Int(..), chr#, ord#, word2Int#)
33import GHC.Word (Word8(..), Word16(..), Word32(..))
34import qualified Data.Text.Array as A
37ord (C# c#) = I# (ord# c#)
40unsafeChr :: Word16 -> Char
41unsafeChr (W16# w#) = C# (chr# (word2Int# w#))
42{-# INLINE unsafeChr #-}
44unsafeChr8 :: Word8 -> Char
45unsafeChr8 (W8# w#) = C# (chr# (word2Int# w#))
46{-# INLINE unsafeChr8 #-}
48unsafeChr32 :: Word32 -> Char
49unsafeChr32 (W32# w#) = C# (chr# (word2Int# w#))
50{-# INLINE unsafeChr32 #-}
52-- | Write a character into the array at the given offset. Returns
53-- the number of 'Word16's written.
54unsafeWrite :: A.MArray s -> Int -> Char -> ST s Int
58 assert (i >= 0) . assert (i < A.length marr) $ return ()
60 A.unsafeWrite marr i (fromIntegral n)
64 assert (i >= 0) . assert (i < A.length marr - 1) $ return ()
66 A.unsafeWrite marr i lo
67 A.unsafeWrite marr (i+1) hi
71 lo = fromIntegral $ (m `shiftR` 10) + 0xD800
72 hi = fromIntegral $ (m .&. 0x3FF) + 0xDC00
73{-# INLINE unsafeWrite #-}
76unsafeWriteRev :: A.MArray s Word16 -> Int -> Char -> ST s Int
77unsafeWriteRev marr i c
79 assert (i >= 0) . assert (i < A.length marr) $
80 A.unsafeWrite marr i (fromIntegral n)
83 assert (i >= 1) . assert (i < A.length marr) $
84 A.unsafeWrite marr (i-1) lo
85 A.unsafeWrite marr i hi
89 lo = fromIntegral $ (m `shiftR` 10) + 0xD800
90 hi = fromIntegral $ (m .&. 0x3FF) + 0xDC00
91{-# 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