[project @ 1996-06-27 16:55:06 by partain]
[ghc-hetmet.git] / ghc / lib / required / Char.hs
1 module Char ( 
2     isAscii, isControl, isPrint, isSpace, isUpper, isLower,
3     isAlpha, isDigit, isOctDigit, isHexDigit, isAlphanum, toUpper, toLower ) where
4
5 isAscii, isControl, isPrint, isSpace, isUpper,
6  isLower, isAlpha, isDigit, isOctDigit, isHexDigit, isAlphanum :: Char -> Bool
7 isAscii c               =  fromEnum c < 128
8 isControl c             =  c < ' ' || c >= '\DEL' && c <= '\x9f'
9 isPrint c               =  not (isControl c)
10 -- This includes non-breaking space
11 isSpace c               =  c `elem` " \t\n\r\f\v\xa0"
12 -- The upper case ISO characters have the multiplication sign dumped
13 -- randomly in the middle of the range.  Go figure.
14 isUpper c               =  c >= 'A' && c <= 'Z' || 
15                            c >= '\xC0' && c <= '\xD6' ||
16                            c >= '\xD8' && c <= '\xDE'
17 -- The lower case ISO characters have the division sign dumped
18 -- randomly in the middle of the range.  Go figure.
19 isLower c               =  c >= 'a' && c <= 'z' ||
20                            c >= '\xDF' && c <= '\xF6' ||
21                            c >= '\xF8' && c <= '\xFF'
22 isAlpha c               =  isUpper c || isLower c
23 isDigit c               =  c >= '0' && c <= '9'
24 isOctDigit c            =  c >= '0' && c <= '7'
25 isHexDigit c            =  isDigit c || c >= 'A' && c <= 'F' ||
26                                         c >= 'a' && c <= 'f'
27 isAlphanum c            =  isAlpha c || isDigit c
28
29 -- These almost work for ISO-Latin-1 (except for =DF <-> =FF)
30
31 toUpper, toLower        :: Char -> Char
32 toUpper c | isLower c   =  toEnum (fromEnum c - fromEnum 'a'
33                                               + fromEnum 'A')
34           | otherwise   =  c
35
36 toLower c | isUpper c   =  toEnum (fromEnum c - fromEnum 'A' 
37                                               + fromEnum 'a')
38           | otherwise   =  c