module Unicode.Char.Normalization
(
isCombining
, combiningClass
, isCombiningStarter
, compose
, composeStarters
, DecomposeMode(..)
, isDecomposable
, decompose
, decomposeHangul
)
where
import Control.Exception (assert)
import Data.Char (ord)
import GHC.Base (unsafeChr)
import Unicode.Internal.Division (quotRem21, quotRem28)
import Unicode.Char.General
(hangulFirst, jamoLFirst, jamoTCount, jamoTFirst, jamoVCount, jamoVFirst)
import qualified Unicode.Internal.Char.UnicodeData.CombiningClass as CC
import qualified Unicode.Internal.Char.UnicodeData.Compositions as C
import qualified Unicode.Internal.Char.UnicodeData.Decomposable as D
import qualified Unicode.Internal.Char.UnicodeData.DecomposableK as K
import qualified Unicode.Internal.Char.UnicodeData.Decompositions as D
import qualified Unicode.Internal.Char.UnicodeData.DecompositionsK as K
{-# INLINE compose #-}
compose :: Char -> Char -> Maybe Char
compose :: Char -> Char -> Maybe Char
compose = Char -> Char -> Maybe Char
C.compose
{-# INLINE composeStarters #-}
composeStarters :: Char -> Char -> Maybe Char
composeStarters :: Char -> Char -> Maybe Char
composeStarters = Char -> Char -> Maybe Char
C.composeStarters
{-# INLINE isCombiningStarter #-}
isCombiningStarter :: Char -> Bool
isCombiningStarter :: Char -> Bool
isCombiningStarter = Char -> Bool
C.isSecondStarter
data DecomposeMode = Canonical | Kompat
{-# INLINE decompose #-}
decompose :: DecomposeMode -> Char -> [Char]
decompose :: DecomposeMode -> Char -> [Char]
decompose DecomposeMode
Canonical = Char -> [Char]
D.decompose
decompose DecomposeMode
Kompat = Char -> [Char]
K.decompose
{-# INLINE isDecomposable #-}
isDecomposable :: DecomposeMode -> Char -> Bool
isDecomposable :: DecomposeMode -> Char -> Bool
isDecomposable DecomposeMode
Canonical = Char -> Bool
D.isDecomposable
isDecomposable DecomposeMode
Kompat = Char -> Bool
K.isDecomposable
{-# INLINE decomposeHangul #-}
decomposeHangul :: Char -> (Char, Char, Char)
decomposeHangul :: Char -> (Char, Char, Char)
decomposeHangul Char
c = (Char
l, Char
v, Char
t)
where
i :: Int
i = Char -> Int
ord Char
c Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
hangulFirst
!(Int
tn, Int
ti) = Bool -> (Int -> (Int, Int)) -> Int -> (Int, Int)
forall a. (?callStack::CallStack) => Bool -> a -> a
assert (Int
jamoTCount Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
28) Int -> (Int, Int)
quotRem28 Int
i
!(Int
li, Int
vi) = Bool -> (Int -> (Int, Int)) -> Int -> (Int, Int)
forall a. (?callStack::CallStack) => Bool -> a -> a
assert (Int
jamoVCount Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
21) Int -> (Int, Int)
quotRem21 Int
tn
l :: Char
l = Int -> Char
unsafeChr (Int
jamoLFirst Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
li)
v :: Char
v = Int -> Char
unsafeChr (Int
jamoVFirst Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
vi)
t :: Char
t = Int -> Char
unsafeChr (Int
jamoTFirst Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
ti)
{-# INLINE combiningClass #-}
combiningClass :: Char -> Int
combiningClass :: Char -> Int
combiningClass = Char -> Int
CC.combiningClass
{-# INLINE isCombining #-}
isCombining :: Char -> Bool
isCombining :: Char -> Bool
isCombining = Char -> Bool
CC.isCombining