remove empty dir
[ghc-hetmet.git] / ghc / lib / compat / Compat / Unicode.hs
1 {-# OPTIONS -cpp #-}
2 module Compat.Unicode (
3     GeneralCategory(..), generalCategory, isPrint, isUpper
4   ) where
5
6 #if __GLASGOW_HASKELL__ > 604
7
8 import Data.Char (GeneralCategory(..), generalCategory,isPrint,isUpper)
9
10 #else
11
12 import Foreign.C        ( CInt )
13 import Data.Char        ( ord )
14
15 -- | Unicode General Categories (column 2 of the UnicodeData table)
16 -- in the order they are listed in the Unicode standard.
17
18 data GeneralCategory
19         = UppercaseLetter       -- Lu  Letter, Uppercase
20         | LowercaseLetter       -- Ll  Letter, Lowercase
21         | TitlecaseLetter       -- Lt  Letter, Titlecase
22         | ModifierLetter        -- Lm  Letter, Modifier
23         | OtherLetter           -- Lo  Letter, Other
24         | NonSpacingMark        -- Mn  Mark, Non-Spacing
25         | SpacingCombiningMark  -- Mc  Mark, Spacing Combining
26         | EnclosingMark         -- Me  Mark, Enclosing
27         | DecimalNumber         -- Nd  Number, Decimal
28         | LetterNumber          -- Nl  Number, Letter
29         | OtherNumber           -- No  Number, Other
30         | ConnectorPunctuation  -- Pc  Punctuation, Connector
31         | DashPunctuation       -- Pd  Punctuation, Dash
32         | OpenPunctuation       -- Ps  Punctuation, Open
33         | ClosePunctuation      -- Pe  Punctuation, Close
34         | InitialQuote          -- Pi  Punctuation, Initial quote
35         | FinalQuote            -- Pf  Punctuation, Final quote
36         | OtherPunctuation      -- Po  Punctuation, Other
37         | MathSymbol            -- Sm  Symbol, Math
38         | CurrencySymbol        -- Sc  Symbol, Currency
39         | ModifierSymbol        -- Sk  Symbol, Modifier
40         | OtherSymbol           -- So  Symbol, Other
41         | Space                 -- Zs  Separator, Space
42         | LineSeparator         -- Zl  Separator, Line
43         | ParagraphSeparator    -- Zp  Separator, Paragraph
44         | Control               -- Cc  Other, Control
45         | Format                -- Cf  Other, Format
46         | Surrogate             -- Cs  Other, Surrogate
47         | PrivateUse            -- Co  Other, Private Use
48         | NotAssigned           -- Cn  Other, Not Assigned
49         deriving (Eq, Ord, Enum, Read, Show, Bounded)
50
51 -- | Retrieves the general Unicode category of the character.
52 generalCategory :: Char -> GeneralCategory
53 generalCategory c = toEnum (wgencat (fromIntegral (ord c)))
54
55 foreign import ccall unsafe "u_gencat"
56   wgencat :: CInt -> Int
57
58 isPrint c = iswprint (fromIntegral (ord c)) /= 0
59 isUpper c = iswupper (fromIntegral (ord c)) /= 0
60
61 foreign import ccall unsafe "u_iswprint"
62   iswprint :: CInt -> CInt
63
64 foreign import ccall unsafe "u_iswupper"
65   iswupper :: CInt -> CInt
66 #endif