module Unicode.Char.General
(
CodePointType(..)
, codePointType
, GeneralCategory(..)
, generalCategoryAbbr
, generalCategory
, isAlphabetic
, isAlphaNum
, isControl
, isMark
, isPrint
, isPunctuation
, isSeparator
, isSymbol
, isWhiteSpace
, isNoncharacter
, isAscii
, isLatin1
, isAsciiUpper
, isAsciiLower
, isJamo
, jamoNCount
, jamoLFirst
, jamoLCount
, jamoLIndex
, jamoLLast
, jamoVFirst
, jamoVCount
, jamoVIndex
, jamoVLast
, jamoTFirst
, jamoTCount
, jamoTIndex
, jamoTLast
, hangulFirst
, hangulLast
, isHangul
, isHangulLV
)
where
import Control.Exception (assert)
import Data.Bits ((.&.))
import Data.Char (isAscii, isLatin1, isAsciiUpper, isAsciiLower, ord)
import Data.Ix (Ix)
import qualified Unicode.Char.General.Compat as Compat
import qualified Unicode.Internal.Char.DerivedCoreProperties as P
import qualified Unicode.Internal.Char.PropList as P
import qualified Unicode.Internal.Char.UnicodeData.GeneralCategory as UC
import Unicode.Internal.Division (quotRem28)
data GeneralCategory
= UppercaseLetter
| LowercaseLetter
| TitlecaseLetter
| ModifierLetter
| OtherLetter
| NonSpacingMark
| SpacingCombiningMark
| EnclosingMark
| DecimalNumber
| LetterNumber
| OtherNumber
| ConnectorPunctuation
| DashPunctuation
| OpenPunctuation
| ClosePunctuation
| InitialQuote
| FinalQuote
| OtherPunctuation
| MathSymbol
| CurrencySymbol
| ModifierSymbol
| OtherSymbol
| Space
| LineSeparator
| ParagraphSeparator
| Control
| Format
| Surrogate
| PrivateUse
| NotAssigned
deriving ( Int -> GeneralCategory -> ShowS
[GeneralCategory] -> ShowS
GeneralCategory -> String
(Int -> GeneralCategory -> ShowS)
-> (GeneralCategory -> String)
-> ([GeneralCategory] -> ShowS)
-> Show GeneralCategory
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> GeneralCategory -> ShowS
showsPrec :: Int -> GeneralCategory -> ShowS
$cshow :: GeneralCategory -> String
show :: GeneralCategory -> String
$cshowList :: [GeneralCategory] -> ShowS
showList :: [GeneralCategory] -> ShowS
Show
, GeneralCategory -> GeneralCategory -> Bool
(GeneralCategory -> GeneralCategory -> Bool)
-> (GeneralCategory -> GeneralCategory -> Bool)
-> Eq GeneralCategory
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: GeneralCategory -> GeneralCategory -> Bool
== :: GeneralCategory -> GeneralCategory -> Bool
$c/= :: GeneralCategory -> GeneralCategory -> Bool
/= :: GeneralCategory -> GeneralCategory -> Bool
Eq
, Eq GeneralCategory
Eq GeneralCategory
-> (GeneralCategory -> GeneralCategory -> Ordering)
-> (GeneralCategory -> GeneralCategory -> Bool)
-> (GeneralCategory -> GeneralCategory -> Bool)
-> (GeneralCategory -> GeneralCategory -> Bool)
-> (GeneralCategory -> GeneralCategory -> Bool)
-> (GeneralCategory -> GeneralCategory -> GeneralCategory)
-> (GeneralCategory -> GeneralCategory -> GeneralCategory)
-> Ord GeneralCategory
GeneralCategory -> GeneralCategory -> Bool
GeneralCategory -> GeneralCategory -> Ordering
GeneralCategory -> GeneralCategory -> GeneralCategory
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: GeneralCategory -> GeneralCategory -> Ordering
compare :: GeneralCategory -> GeneralCategory -> Ordering
$c< :: GeneralCategory -> GeneralCategory -> Bool
< :: GeneralCategory -> GeneralCategory -> Bool
$c<= :: GeneralCategory -> GeneralCategory -> Bool
<= :: GeneralCategory -> GeneralCategory -> Bool
$c> :: GeneralCategory -> GeneralCategory -> Bool
> :: GeneralCategory -> GeneralCategory -> Bool
$c>= :: GeneralCategory -> GeneralCategory -> Bool
>= :: GeneralCategory -> GeneralCategory -> Bool
$cmax :: GeneralCategory -> GeneralCategory -> GeneralCategory
max :: GeneralCategory -> GeneralCategory -> GeneralCategory
$cmin :: GeneralCategory -> GeneralCategory -> GeneralCategory
min :: GeneralCategory -> GeneralCategory -> GeneralCategory
Ord
, Int -> GeneralCategory
GeneralCategory -> Int
GeneralCategory -> [GeneralCategory]
GeneralCategory -> GeneralCategory
GeneralCategory -> GeneralCategory -> [GeneralCategory]
GeneralCategory
-> GeneralCategory -> GeneralCategory -> [GeneralCategory]
(GeneralCategory -> GeneralCategory)
-> (GeneralCategory -> GeneralCategory)
-> (Int -> GeneralCategory)
-> (GeneralCategory -> Int)
-> (GeneralCategory -> [GeneralCategory])
-> (GeneralCategory -> GeneralCategory -> [GeneralCategory])
-> (GeneralCategory -> GeneralCategory -> [GeneralCategory])
-> (GeneralCategory
-> GeneralCategory -> GeneralCategory -> [GeneralCategory])
-> Enum GeneralCategory
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: GeneralCategory -> GeneralCategory
succ :: GeneralCategory -> GeneralCategory
$cpred :: GeneralCategory -> GeneralCategory
pred :: GeneralCategory -> GeneralCategory
$ctoEnum :: Int -> GeneralCategory
toEnum :: Int -> GeneralCategory
$cfromEnum :: GeneralCategory -> Int
fromEnum :: GeneralCategory -> Int
$cenumFrom :: GeneralCategory -> [GeneralCategory]
enumFrom :: GeneralCategory -> [GeneralCategory]
$cenumFromThen :: GeneralCategory -> GeneralCategory -> [GeneralCategory]
enumFromThen :: GeneralCategory -> GeneralCategory -> [GeneralCategory]
$cenumFromTo :: GeneralCategory -> GeneralCategory -> [GeneralCategory]
enumFromTo :: GeneralCategory -> GeneralCategory -> [GeneralCategory]
$cenumFromThenTo :: GeneralCategory
-> GeneralCategory -> GeneralCategory -> [GeneralCategory]
enumFromThenTo :: GeneralCategory
-> GeneralCategory -> GeneralCategory -> [GeneralCategory]
Enum
, GeneralCategory
GeneralCategory -> GeneralCategory -> Bounded GeneralCategory
forall a. a -> a -> Bounded a
$cminBound :: GeneralCategory
minBound :: GeneralCategory
$cmaxBound :: GeneralCategory
maxBound :: GeneralCategory
Bounded
, Ord GeneralCategory
Ord GeneralCategory
-> ((GeneralCategory, GeneralCategory) -> [GeneralCategory])
-> ((GeneralCategory, GeneralCategory) -> GeneralCategory -> Int)
-> ((GeneralCategory, GeneralCategory) -> GeneralCategory -> Int)
-> ((GeneralCategory, GeneralCategory) -> GeneralCategory -> Bool)
-> ((GeneralCategory, GeneralCategory) -> Int)
-> ((GeneralCategory, GeneralCategory) -> Int)
-> Ix GeneralCategory
(GeneralCategory, GeneralCategory) -> Int
(GeneralCategory, GeneralCategory) -> [GeneralCategory]
(GeneralCategory, GeneralCategory) -> GeneralCategory -> Bool
(GeneralCategory, GeneralCategory) -> GeneralCategory -> Int
forall a.
Ord a
-> ((a, a) -> [a])
-> ((a, a) -> a -> Int)
-> ((a, a) -> a -> Int)
-> ((a, a) -> a -> Bool)
-> ((a, a) -> Int)
-> ((a, a) -> Int)
-> Ix a
$crange :: (GeneralCategory, GeneralCategory) -> [GeneralCategory]
range :: (GeneralCategory, GeneralCategory) -> [GeneralCategory]
$cindex :: (GeneralCategory, GeneralCategory) -> GeneralCategory -> Int
index :: (GeneralCategory, GeneralCategory) -> GeneralCategory -> Int
$cunsafeIndex :: (GeneralCategory, GeneralCategory) -> GeneralCategory -> Int
unsafeIndex :: (GeneralCategory, GeneralCategory) -> GeneralCategory -> Int
$cinRange :: (GeneralCategory, GeneralCategory) -> GeneralCategory -> Bool
inRange :: (GeneralCategory, GeneralCategory) -> GeneralCategory -> Bool
$crangeSize :: (GeneralCategory, GeneralCategory) -> Int
rangeSize :: (GeneralCategory, GeneralCategory) -> Int
$cunsafeRangeSize :: (GeneralCategory, GeneralCategory) -> Int
unsafeRangeSize :: (GeneralCategory, GeneralCategory) -> Int
Ix
)
generalCategoryAbbr :: GeneralCategory -> String
generalCategoryAbbr :: GeneralCategory -> String
generalCategoryAbbr = \case
GeneralCategory
UppercaseLetter -> String
"Lu"
GeneralCategory
LowercaseLetter -> String
"Ll"
GeneralCategory
TitlecaseLetter -> String
"Lt"
GeneralCategory
ModifierLetter -> String
"Lm"
GeneralCategory
OtherLetter -> String
"Lo"
GeneralCategory
NonSpacingMark -> String
"Mn"
GeneralCategory
SpacingCombiningMark -> String
"Mc"
GeneralCategory
EnclosingMark -> String
"Me"
GeneralCategory
DecimalNumber -> String
"Nd"
GeneralCategory
LetterNumber -> String
"Nl"
GeneralCategory
OtherNumber -> String
"No"
GeneralCategory
ConnectorPunctuation -> String
"Pc"
GeneralCategory
DashPunctuation -> String
"Pd"
GeneralCategory
OpenPunctuation -> String
"Ps"
GeneralCategory
ClosePunctuation -> String
"Pe"
GeneralCategory
InitialQuote -> String
"Pi"
GeneralCategory
FinalQuote -> String
"Pf"
GeneralCategory
OtherPunctuation -> String
"Po"
GeneralCategory
MathSymbol -> String
"Sm"
GeneralCategory
CurrencySymbol -> String
"Sc"
GeneralCategory
ModifierSymbol -> String
"Sk"
GeneralCategory
OtherSymbol -> String
"So"
GeneralCategory
Space -> String
"Zs"
GeneralCategory
LineSeparator -> String
"Zl"
GeneralCategory
ParagraphSeparator -> String
"Zp"
GeneralCategory
Control -> String
"Cc"
GeneralCategory
Format -> String
"Cf"
GeneralCategory
Surrogate -> String
"Cs"
GeneralCategory
PrivateUse -> String
"Co"
GeneralCategory
NotAssigned -> String
"Cn"
{-# INLINE generalCategory #-}
generalCategory :: Char -> GeneralCategory
generalCategory :: Char -> GeneralCategory
generalCategory = Int -> GeneralCategory
forall a. Enum a => Int -> a
toEnum (Int -> GeneralCategory)
-> (Char -> Int) -> Char -> GeneralCategory
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Int
UC.generalCategory
data CodePointType
= GraphicType
| FormatType
| ControlType
| PrivateUseType
| SurrogateType
| NoncharacterType
| ReservedType
deriving ( Int -> CodePointType -> ShowS
[CodePointType] -> ShowS
CodePointType -> String
(Int -> CodePointType -> ShowS)
-> (CodePointType -> String)
-> ([CodePointType] -> ShowS)
-> Show CodePointType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CodePointType -> ShowS
showsPrec :: Int -> CodePointType -> ShowS
$cshow :: CodePointType -> String
show :: CodePointType -> String
$cshowList :: [CodePointType] -> ShowS
showList :: [CodePointType] -> ShowS
Show
, CodePointType -> CodePointType -> Bool
(CodePointType -> CodePointType -> Bool)
-> (CodePointType -> CodePointType -> Bool) -> Eq CodePointType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CodePointType -> CodePointType -> Bool
== :: CodePointType -> CodePointType -> Bool
$c/= :: CodePointType -> CodePointType -> Bool
/= :: CodePointType -> CodePointType -> Bool
Eq
, Eq CodePointType
Eq CodePointType
-> (CodePointType -> CodePointType -> Ordering)
-> (CodePointType -> CodePointType -> Bool)
-> (CodePointType -> CodePointType -> Bool)
-> (CodePointType -> CodePointType -> Bool)
-> (CodePointType -> CodePointType -> Bool)
-> (CodePointType -> CodePointType -> CodePointType)
-> (CodePointType -> CodePointType -> CodePointType)
-> Ord CodePointType
CodePointType -> CodePointType -> Bool
CodePointType -> CodePointType -> Ordering
CodePointType -> CodePointType -> CodePointType
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: CodePointType -> CodePointType -> Ordering
compare :: CodePointType -> CodePointType -> Ordering
$c< :: CodePointType -> CodePointType -> Bool
< :: CodePointType -> CodePointType -> Bool
$c<= :: CodePointType -> CodePointType -> Bool
<= :: CodePointType -> CodePointType -> Bool
$c> :: CodePointType -> CodePointType -> Bool
> :: CodePointType -> CodePointType -> Bool
$c>= :: CodePointType -> CodePointType -> Bool
>= :: CodePointType -> CodePointType -> Bool
$cmax :: CodePointType -> CodePointType -> CodePointType
max :: CodePointType -> CodePointType -> CodePointType
$cmin :: CodePointType -> CodePointType -> CodePointType
min :: CodePointType -> CodePointType -> CodePointType
Ord
, Int -> CodePointType
CodePointType -> Int
CodePointType -> [CodePointType]
CodePointType -> CodePointType
CodePointType -> CodePointType -> [CodePointType]
CodePointType -> CodePointType -> CodePointType -> [CodePointType]
(CodePointType -> CodePointType)
-> (CodePointType -> CodePointType)
-> (Int -> CodePointType)
-> (CodePointType -> Int)
-> (CodePointType -> [CodePointType])
-> (CodePointType -> CodePointType -> [CodePointType])
-> (CodePointType -> CodePointType -> [CodePointType])
-> (CodePointType
-> CodePointType -> CodePointType -> [CodePointType])
-> Enum CodePointType
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: CodePointType -> CodePointType
succ :: CodePointType -> CodePointType
$cpred :: CodePointType -> CodePointType
pred :: CodePointType -> CodePointType
$ctoEnum :: Int -> CodePointType
toEnum :: Int -> CodePointType
$cfromEnum :: CodePointType -> Int
fromEnum :: CodePointType -> Int
$cenumFrom :: CodePointType -> [CodePointType]
enumFrom :: CodePointType -> [CodePointType]
$cenumFromThen :: CodePointType -> CodePointType -> [CodePointType]
enumFromThen :: CodePointType -> CodePointType -> [CodePointType]
$cenumFromTo :: CodePointType -> CodePointType -> [CodePointType]
enumFromTo :: CodePointType -> CodePointType -> [CodePointType]
$cenumFromThenTo :: CodePointType -> CodePointType -> CodePointType -> [CodePointType]
enumFromThenTo :: CodePointType -> CodePointType -> CodePointType -> [CodePointType]
Enum
, CodePointType
CodePointType -> CodePointType -> Bounded CodePointType
forall a. a -> a -> Bounded a
$cminBound :: CodePointType
minBound :: CodePointType
$cmaxBound :: CodePointType
maxBound :: CodePointType
Bounded
, Ord CodePointType
Ord CodePointType
-> ((CodePointType, CodePointType) -> [CodePointType])
-> ((CodePointType, CodePointType) -> CodePointType -> Int)
-> ((CodePointType, CodePointType) -> CodePointType -> Int)
-> ((CodePointType, CodePointType) -> CodePointType -> Bool)
-> ((CodePointType, CodePointType) -> Int)
-> ((CodePointType, CodePointType) -> Int)
-> Ix CodePointType
(CodePointType, CodePointType) -> Int
(CodePointType, CodePointType) -> [CodePointType]
(CodePointType, CodePointType) -> CodePointType -> Bool
(CodePointType, CodePointType) -> CodePointType -> Int
forall a.
Ord a
-> ((a, a) -> [a])
-> ((a, a) -> a -> Int)
-> ((a, a) -> a -> Int)
-> ((a, a) -> a -> Bool)
-> ((a, a) -> Int)
-> ((a, a) -> Int)
-> Ix a
$crange :: (CodePointType, CodePointType) -> [CodePointType]
range :: (CodePointType, CodePointType) -> [CodePointType]
$cindex :: (CodePointType, CodePointType) -> CodePointType -> Int
index :: (CodePointType, CodePointType) -> CodePointType -> Int
$cunsafeIndex :: (CodePointType, CodePointType) -> CodePointType -> Int
unsafeIndex :: (CodePointType, CodePointType) -> CodePointType -> Int
$cinRange :: (CodePointType, CodePointType) -> CodePointType -> Bool
inRange :: (CodePointType, CodePointType) -> CodePointType -> Bool
$crangeSize :: (CodePointType, CodePointType) -> Int
rangeSize :: (CodePointType, CodePointType) -> Int
$cunsafeRangeSize :: (CodePointType, CodePointType) -> Int
unsafeRangeSize :: (CodePointType, CodePointType) -> Int
Ix
)
codePointType :: Char -> CodePointType
codePointType :: Char -> CodePointType
codePointType Char
c = case Char -> GeneralCategory
generalCategory Char
c of
GeneralCategory
UppercaseLetter -> CodePointType
GraphicType
GeneralCategory
LowercaseLetter -> CodePointType
GraphicType
GeneralCategory
TitlecaseLetter -> CodePointType
GraphicType
GeneralCategory
ModifierLetter -> CodePointType
GraphicType
GeneralCategory
OtherLetter -> CodePointType
GraphicType
GeneralCategory
NonSpacingMark -> CodePointType
GraphicType
GeneralCategory
SpacingCombiningMark -> CodePointType
GraphicType
GeneralCategory
EnclosingMark -> CodePointType
GraphicType
GeneralCategory
DecimalNumber -> CodePointType
GraphicType
GeneralCategory
LetterNumber -> CodePointType
GraphicType
GeneralCategory
OtherNumber -> CodePointType
GraphicType
GeneralCategory
ConnectorPunctuation -> CodePointType
GraphicType
GeneralCategory
DashPunctuation -> CodePointType
GraphicType
GeneralCategory
OpenPunctuation -> CodePointType
GraphicType
GeneralCategory
ClosePunctuation -> CodePointType
GraphicType
GeneralCategory
InitialQuote -> CodePointType
GraphicType
GeneralCategory
FinalQuote -> CodePointType
GraphicType
GeneralCategory
OtherPunctuation -> CodePointType
GraphicType
GeneralCategory
MathSymbol -> CodePointType
GraphicType
GeneralCategory
CurrencySymbol -> CodePointType
GraphicType
GeneralCategory
ModifierSymbol -> CodePointType
GraphicType
GeneralCategory
OtherSymbol -> CodePointType
GraphicType
GeneralCategory
Space -> CodePointType
GraphicType
GeneralCategory
LineSeparator -> CodePointType
FormatType
GeneralCategory
ParagraphSeparator -> CodePointType
FormatType
GeneralCategory
Control -> CodePointType
ControlType
GeneralCategory
Format -> CodePointType
FormatType
GeneralCategory
Surrogate -> CodePointType
SurrogateType
GeneralCategory
PrivateUse -> CodePointType
PrivateUseType
GeneralCategory
NotAssigned
| Char -> Bool
isNoncharacter Char
c -> CodePointType
NoncharacterType
| Bool
otherwise -> CodePointType
ReservedType
{-# INLINE isAlphabetic #-}
isAlphabetic :: Char -> Bool
isAlphabetic :: Char -> Bool
isAlphabetic = Char -> Bool
P.isAlphabetic
{-# INLINE isAlphaNum #-}
{-# DEPRECATED isAlphaNum "Use Unicode.Char.General.Compat.isAlphaNum instead." #-}
isAlphaNum :: Char -> Bool
isAlphaNum :: Char -> Bool
isAlphaNum = Char -> Bool
Compat.isAlphaNum
isControl :: Char -> Bool
isControl :: Char -> Bool
isControl Char
c = Int
cp Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
0x9F Bool -> Bool -> Bool
&& Int -> Int
UC.generalCategoryPlanes0To3 Int
cp Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
UC.Control
where cp :: Int
cp = Char -> Int
ord Char
c
isMark :: Char -> Bool
isMark :: Char -> Bool
isMark Char
c = Int
UC.NonSpacingMark Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
gc Bool -> Bool -> Bool
&& Int
gc Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
UC.EnclosingMark
where gc :: Int
gc = Char -> Int
UC.generalCategory Char
c
isPrint :: Char -> Bool
isPrint :: Char -> Bool
isPrint Char
c = Char -> Int
UC.generalCategory Char
c Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
UC.LineSeparator
isPunctuation :: Char -> Bool
isPunctuation :: Char -> Bool
isPunctuation Char
c = Int
UC.ConnectorPunctuation Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
gc Bool -> Bool -> Bool
&& Int
gc Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
UC.OtherPunctuation
where gc :: Int
gc = Char -> Int
UC.generalCategory Char
c
{-# INLINE isWhiteSpace #-}
isWhiteSpace :: Char -> Bool
isWhiteSpace :: Char -> Bool
isWhiteSpace = Char -> Bool
P.isWhite_Space
isSeparator :: Char -> Bool
isSeparator :: Char -> Bool
isSeparator Char
c =
let !cp :: Int
cp = Char -> Int
ord Char
c
in Int
cp Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
UC.MaxIsSeparator Bool -> Bool -> Bool
&&
let !gc :: Int
gc = Int -> Int
UC.generalCategoryPlanes0To3 Int
cp
in Int
UC.Space Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
gc Bool -> Bool -> Bool
&& Int
gc Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
UC.ParagraphSeparator
isSymbol :: Char -> Bool
isSymbol :: Char -> Bool
isSymbol Char
c = Int
UC.MathSymbol Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
gc Bool -> Bool -> Bool
&& Int
gc Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
UC.OtherSymbol
where gc :: Int
gc = Char -> Int
UC.generalCategory Char
c
isNoncharacter :: Char -> Bool
isNoncharacter :: Char -> Bool
isNoncharacter Char
c
= (Char
'\xFDD0' Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
<= Char
c Bool -> Bool -> Bool
&& Char
c Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
<= Char
'\xFDEF')
Bool -> Bool -> Bool
|| (Char -> Int
ord Char
c Int -> Int -> Int
forall a. Bits a => a -> a -> a
.&. Int
0xFFFF) Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
0xFFFE
jamoLFirst, jamoLCount, jamoLLast :: Int
jamoLFirst :: Int
jamoLFirst = Int
0x1100
jamoLCount :: Int
jamoLCount = Int
19
jamoLLast :: Int
jamoLLast = Int
jamoLFirst Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
jamoLCount Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1
jamoVFirst, jamoVCount, jamoVLast :: Int
jamoVFirst :: Int
jamoVFirst = Int
0x1161
jamoVCount :: Int
jamoVCount = Int
21
jamoVLast :: Int
jamoVLast = Int
jamoVFirst Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
jamoVCount Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1
jamoTFirst, jamoTCount :: Int
jamoTFirst :: Int
jamoTFirst = Int
0x11a7
jamoTCount :: Int
jamoTCount = Int
28
jamoTLast :: Int
jamoTLast :: Int
jamoTLast = Int
jamoTFirst Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
jamoTCount Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1
jamoNCount :: Int
jamoNCount :: Int
jamoNCount = Int
588
hangulFirst, hangulLast :: Int
hangulFirst :: Int
hangulFirst = Int
0xac00
hangulLast :: Int
hangulLast = Int
hangulFirst Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
jamoLCount Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
jamoVCount Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
jamoTCount Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1
isHangul :: Char -> Bool
isHangul :: Char -> Bool
isHangul Char
c = Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
hangulFirst Bool -> Bool -> Bool
&& Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
hangulLast
where n :: Int
n = Char -> Int
ord Char
c
isHangulLV :: Char -> Bool
isHangulLV :: Char -> Bool
isHangulLV Char
c = 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
forall a b. (a, b) -> b
snd (Int -> (Int, Int)
quotRem28 (Char -> Int
ord Char
c Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
hangulFirst)) Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0
isJamo :: Char -> Bool
isJamo :: Char -> Bool
isJamo Char
c = Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
jamoLFirst Bool -> Bool -> Bool
&& Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
jamoTLast
where n :: Int
n = Char -> Int
ord Char
c
jamoLIndex :: Char -> Maybe Int
jamoLIndex :: Char -> Maybe Int
jamoLIndex Char
c
| Int
index Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
0 Bool -> Bool -> Bool
&& Int
index Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
jamoLCount = Int -> Maybe Int
forall a. a -> Maybe a
Just Int
index
| Bool
otherwise = Maybe Int
forall a. Maybe a
Nothing
where index :: Int
index = Char -> Int
ord Char
c Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
jamoLFirst
jamoVIndex :: Char -> Maybe Int
jamoVIndex :: Char -> Maybe Int
jamoVIndex Char
c
| Int
index Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
0 Bool -> Bool -> Bool
&& Int
index Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
jamoVCount = Int -> Maybe Int
forall a. a -> Maybe a
Just Int
index
| Bool
otherwise = Maybe Int
forall a. Maybe a
Nothing
where index :: Int
index = Char -> Int
ord Char
c Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
jamoVFirst
jamoTIndex :: Char -> Maybe Int
jamoTIndex :: Char -> Maybe Int
jamoTIndex Char
c
| Int
index Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
0 Bool -> Bool -> Bool
&& Int
index Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
jamoTCount = Int -> Maybe Int
forall a. a -> Maybe a
Just Int
index
| Bool
otherwise = Maybe Int
forall a. Maybe a
Nothing
where index :: Int
index = Char -> Int
ord Char
c Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
jamoTFirst