1 Character classification
4 {-# OPTIONS -#include "hs_ctype.h" #-}
7 ( is_ident -- Char# -> Bool
8 , is_symbol -- Char# -> Bool
9 , is_any -- Char# -> Bool
10 , is_space -- Char# -> Bool
11 , is_lower -- Char# -> Bool
12 , is_upper -- Char# -> Bool
13 , is_digit -- Char# -> Bool
18 import Bits ( Bits((.&.)) )
22 import PrelBase ( Char#, Char(..) )
28 The predicates below look costly, but aren't, GHC+GCC do a great job
29 at the big case below.
32 {-# INLINE is_ctype #-}
33 is_ctype :: Int -> Char# -> Bool
34 is_ctype mask c = (fromIntegral (charType (C# c)) .&. fromIntegral mask) /= (0::Int32)
36 cIdent, cSymbol, cAny, cSpace, cLower, cUpper, cDigit :: Int
37 cIdent = C_Ident :: Int
38 cSymbol = C_Symbol :: Int
40 cSpace = C_Space :: Int
41 cLower = C_Lower :: Int
42 cUpper = C_Upper :: Int
43 cDigit = C_Digit :: Int
45 is_ident, is_symbol, is_any, is_space, is_lower, is_upper, is_digit :: Char# -> Bool
46 is_ident = is_ctype cIdent
47 is_symbol = is_ctype cSymbol
48 is_any = is_ctype cAny
49 is_space = is_ctype cSpace
50 is_lower = is_ctype cLower
51 is_upper = is_ctype cUpper
52 is_digit = is_ctype cDigit
54 foreign label "hs_char_types" hs_char_types :: Addr
56 charType :: Char -> Int
57 charType c = ord (indexCharOffAddr hs_char_types (ord c))