module Agda.Utils.Char where
import Data.Char
replacementChar :: Char
replacementChar :: Char
replacementChar = Char
'\xFFFD'
isSurrogateCodePoint :: Char -> Bool
isSurrogateCodePoint :: Char -> Bool
isSurrogateCodePoint Char
c = Char -> GeneralCategory
generalCategory Char
c GeneralCategory -> GeneralCategory -> Bool
forall a. Eq a => a -> a -> Bool
== GeneralCategory
Surrogate
replaceSurrogateCodePoint :: Char -> Char
replaceSurrogateCodePoint :: Char -> Char
replaceSurrogateCodePoint Char
c
| Char -> Bool
isSurrogateCodePoint Char
c = Char
replacementChar
| Bool
otherwise = Char
c
integerToChar :: Integer -> Char
integerToChar :: Integer -> Char
integerToChar = Char -> Char
replaceSurrogateCodePoint (Char -> Char) -> (Integer -> Char) -> Integer -> Char
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Char
forall a. Enum a => Int -> a
toEnum (Int -> Char) -> (Integer -> Int) -> Integer -> Char
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Integer -> Int) -> (Integer -> Integer) -> Integer -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Integer -> Integer -> Integer
forall a. Integral a => a -> a -> a
`mod` Integer
0x110000)