{-# LANGUAGE Trustworthy #-}
{-# LANGUAGE NoImplicitPrelude, MagicHash #-}

module GHC.Internal.Char
    ( -- * Utilities
      chr

      -- * Monomorphic equality operators
      -- | See GHC.Internal.Classes#matching_overloaded_methods_in_rules
    , eqChar, neChar
    ) where

import GHC.Internal.Classes (eqChar, neChar)
import GHC.Internal.Base (otherwise, (++))
import GHC.Internal.Err (error)
import GHC.Internal.Show
import GHC.Internal.Prim (chr#, int2Word#, leWord#, Int#, Char#)
import GHC.Internal.Types (Char(..), Int(..), isTrue#)

-- | The 'Prelude.toEnum' method restricted to the type 'Data.Char.Char'.
chr :: Int -> Char
chr :: Int -> Char
chr (I# Int#
i#) = Char# -> Char
C# (Int# -> Char#
safe_chr# Int#
i#)

{-# INLINABLE safe_chr# #-}
safe_chr# :: Int# -> Char#
safe_chr# :: Int# -> Char#
safe_chr# Int#
i#
 | Int# -> Bool
isTrue# (Int# -> Word#
int2Word# Int#
i# Word# -> Word# -> Int#
`leWord#` Word#
0x10FFFF##) = Int# -> Char#
chr# Int#
i#
 | Bool
otherwise = Int# -> Char#
chr_error Int#
i#

{-# NOINLINE chr_error #-}
chr_error :: Int# -> Char#
chr_error :: Int# -> Char#
chr_error Int#
i# = [Char] -> Char#
forall a. HasCallStack => [Char] -> a
error ([Char]
"Data.Char.chr: argument outside Unicode range: 0..1114111: " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ Int -> Int -> [Char] -> [Char]
showSignedInt (Int# -> Int
I# Int#
9#) (Int# -> Int
I# Int#
i#) [Char]
"")
-- It's not really "Data.Char", but we assume that
-- the majority of users will import it from "base:Data.Char"
-- and not from "ghc-internal:GHC.Internal.Char".