Source

text / Data / Text / UnsafeChar.hs

Full commit
{-# LANGUAGE MagicHash #-}

-- |
-- Module      : Data.Text.UnsafeChar
-- Copyright   : (c) Tom Harper 2008-2009,
--               (c) Bryan O'Sullivan 2009,
--               (c) Duncan Coutts 2009
--
-- License     : BSD-style
-- Maintainer  : rtharper@aftereternity.co.uk, bos@serpentine.com,
--               duncan@haskell.org
-- Stability   : experimental
-- Portability : GHC
--
-- Fast character manipulation function.
module Data.Text.UnsafeChar
    (
      unsafeChr
    , unsafeChr8
    , unsafeChr32
    ) where

import GHC.Exts (Char(..), chr#, word2Int#)
import GHC.Word (Word8(..), Word16(..), Word32(..))

unsafeChr :: Word16 -> Char
unsafeChr (W16# w#) = C# (chr# (word2Int# w#))
{-# INLINE unsafeChr #-}

unsafeChr8 :: Word8 -> Char
unsafeChr8 (W8# w#) = C# (chr# (word2Int# w#))
{-# INLINE unsafeChr8 #-}

unsafeChr32 :: Word32 -> Char
unsafeChr32 (W32# w#) = C# (chr# (word2Int# w#))
{-# INLINE unsafeChr32 #-}