{-# LANGUAGE TemplateHaskell #-}
module Text.Collate.CanonicalCombiningClass
  ( canonicalCombiningClass )
where
import Text.Collate.UnicodeData (genCanonicalCombiningClassMap)
import qualified Data.IntMap as M
import Data.Maybe (fromMaybe)

-- | Map from code points to canonical combining classes.
-- Only nonzero elements are included.
combiningClassMap :: M.IntMap Int
combiningClassMap :: IntMap Int
combiningClassMap = $(genCanonicalCombiningClassMap)

-- | Determine the canonical combining class for a code point.
canonicalCombiningClass :: Int -> Int
canonicalCombiningClass :: Int -> Int
canonicalCombiningClass Int
cp
  | Int
cp forall a. Ord a => a -> a -> Bool
< Int
0x300 = Int
0  -- optimization
  | Bool
otherwise  = forall a. a -> Maybe a -> a
fromMaybe Int
0 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Int -> IntMap a -> Maybe a
M.lookup Int
cp forall a b. (a -> b) -> a -> b
$! IntMap Int
combiningClassMap