{-# LANGUAGE CPP #-}
module Ctype
( is_ident
, is_symbol
, is_any
, is_space
, is_lower
, is_upper
, is_digit
, is_alphanum
, is_decdigit, is_hexdigit, is_octdigit, is_bindigit
, hexDigit, octDecDigit
) where
#include "HsVersions.h"
import GhcPrelude
import Data.Int ( Int32 )
import Data.Bits ( Bits((.&.)) )
import Data.Char ( ord, chr )
import Panic
cIdent, cSymbol, cAny, cSpace, cLower, cUpper, cDigit :: Int
cIdent :: Int
cIdent = 1
cSymbol :: Int
cSymbol = 2
cAny :: Int
cAny = 4
cSpace :: Int
cSpace = 8
cLower :: Int
cLower = 16
cUpper :: Int
cUpper = 32
cDigit :: Int
cDigit = 64
{-# INLINE is_ctype #-}
is_ctype :: Int -> Char -> Bool
is_ctype :: Int -> Char -> Bool
is_ctype mask :: Int
mask c :: Char
c = (Int -> Int32
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Char -> Int
charType Char
c) Int32 -> Int32 -> Int32
forall a. Bits a => a -> a -> a
.&. Int -> Int32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
mask) Int32 -> Int32 -> Bool
forall a. Eq a => a -> a -> Bool
/= (0::Int32)
is_ident, is_symbol, is_any, is_space, is_lower, is_upper, is_digit,
is_alphanum :: Char -> Bool
is_ident :: Char -> Bool
is_ident = Int -> Char -> Bool
is_ctype Int
cIdent
is_symbol :: Char -> Bool
is_symbol = Int -> Char -> Bool
is_ctype Int
cSymbol
is_any :: Char -> Bool
is_any = Int -> Char -> Bool
is_ctype Int
cAny
is_space :: Char -> Bool
is_space = Int -> Char -> Bool
is_ctype Int
cSpace
is_lower :: Char -> Bool
is_lower = Int -> Char -> Bool
is_ctype Int
cLower
is_upper :: Char -> Bool
is_upper = Int -> Char -> Bool
is_ctype Int
cUpper
is_digit :: Char -> Bool
is_digit = Int -> Char -> Bool
is_ctype Int
cDigit
is_alphanum :: Char -> Bool
is_alphanum = Int -> Char -> Bool
is_ctype (Int
cLowerInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
cUpperInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
cDigit)
hexDigit :: Char -> Int
hexDigit :: Char -> Int
hexDigit c :: Char
c | Char -> Bool
is_decdigit Char
c = Char -> Int
ord Char
c Int -> Int -> Int
forall a. Num a => a -> a -> a
- Char -> Int
ord '0'
| Bool
otherwise = Char -> Int
ord (Char -> Char
to_lower Char
c) Int -> Int -> Int
forall a. Num a => a -> a -> a
- Char -> Int
ord 'a' Int -> Int -> Int
forall a. Num a => a -> a -> a
+ 10
octDecDigit :: Char -> Int
octDecDigit :: Char -> Int
octDecDigit c :: Char
c = Char -> Int
ord Char
c Int -> Int -> Int
forall a. Num a => a -> a -> a
- Char -> Int
ord '0'
is_decdigit :: Char -> Bool
is_decdigit :: Char -> Bool
is_decdigit c :: Char
c
= Char
c Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
>= '0' Bool -> Bool -> Bool
&& Char
c Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
<= '9'
is_hexdigit :: Char -> Bool
is_hexdigit :: Char -> Bool
is_hexdigit c :: Char
c
= Char -> Bool
is_decdigit Char
c
Bool -> Bool -> Bool
|| (Char
c Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
>= 'a' Bool -> Bool -> Bool
&& Char
c Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
<= 'f')
Bool -> Bool -> Bool
|| (Char
c Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
>= 'A' Bool -> Bool -> Bool
&& Char
c Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
<= 'F')
is_octdigit :: Char -> Bool
is_octdigit :: Char -> Bool
is_octdigit c :: Char
c = Char
c Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
>= '0' Bool -> Bool -> Bool
&& Char
c Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
<= '7'
is_bindigit :: Char -> Bool
is_bindigit :: Char -> Bool
is_bindigit c :: Char
c = Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== '0' Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== '1'
to_lower :: Char -> Char
to_lower :: Char -> Char
to_lower c :: Char
c
| Char
c Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
>= 'A' Bool -> Bool -> Bool
&& Char
c Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
<= 'Z' = Int -> Char
chr (Char -> Int
ord Char
c Int -> Int -> Int
forall a. Num a => a -> a -> a
- (Char -> Int
ord 'A' Int -> Int -> Int
forall a. Num a => a -> a -> a
- Char -> Int
ord 'a'))
| Bool
otherwise = Char
c
charType :: Char -> Int
charType :: Char -> Int
charType c :: Char
c = case Char
c of
'\0' -> 0
'\1' -> 0
'\2' -> 0
'\3' -> 0
'\4' -> 0
'\5' -> 0
'\6' -> 0
'\7' -> 0
'\8' -> 0
'\9' -> Int
cSpace
'\10' -> Int
cSpace
'\11' -> Int
cSpace
'\12' -> Int
cSpace
'\13' -> Int
cSpace
'\14' -> 0
'\15' -> 0
'\16' -> 0
'\17' -> 0
'\18' -> 0
'\19' -> 0
'\20' -> 0
'\21' -> 0
'\22' -> 0
'\23' -> 0
'\24' -> 0
'\25' -> 0
'\26' -> 0
'\27' -> 0
'\28' -> 0
'\29' -> 0
'\30' -> 0
'\31' -> 0
'\32' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cSpace
'\33' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cSymbol
'\34' -> Int
cAny
'\35' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cSymbol
'\36' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cSymbol
'\37' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cSymbol
'\38' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cSymbol
'\39' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cIdent
'\40' -> Int
cAny
'\41' -> Int
cAny
'\42' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cSymbol
'\43' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cSymbol
'\44' -> Int
cAny
'\45' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cSymbol
'\46' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cSymbol
'\47' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cSymbol
'\48' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cIdent Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cDigit
'\49' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cIdent Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cDigit
'\50' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cIdent Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cDigit
'\51' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cIdent Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cDigit
'\52' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cIdent Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cDigit
'\53' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cIdent Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cDigit
'\54' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cIdent Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cDigit
'\55' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cIdent Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cDigit
'\56' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cIdent Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cDigit
'\57' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cIdent Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cDigit
'\58' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cSymbol
'\59' -> Int
cAny
'\60' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cSymbol
'\61' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cSymbol
'\62' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cSymbol
'\63' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cSymbol
'\64' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cSymbol
'\65' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cIdent Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cUpper
'\66' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cIdent Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cUpper
'\67' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cIdent Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cUpper
'\68' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cIdent Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cUpper
'\69' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cIdent Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cUpper
'\70' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cIdent Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cUpper
'\71' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cIdent Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cUpper
'\72' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cIdent Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cUpper
'\73' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cIdent Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cUpper
'\74' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cIdent Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cUpper
'\75' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cIdent Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cUpper
'\76' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cIdent Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cUpper
'\77' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cIdent Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cUpper
'\78' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cIdent Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cUpper
'\79' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cIdent Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cUpper
'\80' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cIdent Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cUpper
'\81' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cIdent Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cUpper
'\82' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cIdent Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cUpper
'\83' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cIdent Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cUpper
'\84' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cIdent Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cUpper
'\85' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cIdent Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cUpper
'\86' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cIdent Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cUpper
'\87' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cIdent Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cUpper
'\88' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cIdent Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cUpper
'\89' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cIdent Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cUpper
'\90' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cIdent Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cUpper
'\91' -> Int
cAny
'\92' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cSymbol
'\93' -> Int
cAny
'\94' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cSymbol
'\95' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cIdent Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cLower
'\96' -> Int
cAny
'\97' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cIdent Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cLower
'\98' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cIdent Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cLower
'\99' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cIdent Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cLower
'\100' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cIdent Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cLower
'\101' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cIdent Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cLower
'\102' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cIdent Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cLower
'\103' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cIdent Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cLower
'\104' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cIdent Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cLower
'\105' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cIdent Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cLower
'\106' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cIdent Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cLower
'\107' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cIdent Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cLower
'\108' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cIdent Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cLower
'\109' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cIdent Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cLower
'\110' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cIdent Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cLower
'\111' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cIdent Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cLower
'\112' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cIdent Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cLower
'\113' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cIdent Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cLower
'\114' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cIdent Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cLower
'\115' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cIdent Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cLower
'\116' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cIdent Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cLower
'\117' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cIdent Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cLower
'\118' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cIdent Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cLower
'\119' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cIdent Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cLower
'\120' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cIdent Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cLower
'\121' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cIdent Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cLower
'\122' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cIdent Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cLower
'\123' -> Int
cAny
'\124' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cSymbol
'\125' -> Int
cAny
'\126' -> Int
cAny Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cSymbol
'\127' -> 0
_ -> String -> Int
forall a. String -> a
panic ("charType: " String -> String -> String
forall a. [a] -> [a] -> [a]
++ Char -> String
forall a. Show a => a -> String
show Char
c)