File: Char.hs

package info (click to toggle)
bali-phy 4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 15,392 kB
  • sloc: cpp: 120,442; xml: 13,966; haskell: 9,975; python: 2,936; yacc: 1,328; perl: 1,169; lex: 912; sh: 343; makefile: 26
file content (130 lines) | stat: -rw-r--r-- 3,297 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
{-# LANGUAGE NoImplicitPrelude #-}
module Data.Char where

-- Current Char is just a char, but it probably should be a unicode code point (32-bits).

import Compiler.Error
import Compiler.Base
import Compiler.Num
import Data.Eq
import Data.Ord

foreign import bpcall "Char:isControl" builtin_isControl :: Char -> Int

isControl :: Char -> Bool
isControl c = if builtin_isControl c == 1 then True else False

foreign import bpcall "Char:isSpace" builtin_isSpace :: Char -> Int

isSpace :: Char -> Bool
isSpace c = if builtin_isSpace c == 1 then True else False

foreign import bpcall "Char:isLower" builtin_isLower :: Char -> Int

isLower :: Char -> Bool
isLower c = if builtin_isLower c == 1 then True else False

foreign import bpcall "Char:isUpper" builtin_isUpper :: Char -> Int

isUpper :: Char -> Bool
isUpper c = if builtin_isUpper c == 1 then True else False

foreign import bpcall "Char:isAlpha" builtin_isAlpha :: Char -> Int

isAlpha :: Char -> Bool
isAlpha c = if builtin_isAlpha c == 1 then True else False

foreign import bpcall "Char:isAlphaNum" builtin_isAlphaNum :: Char -> Int

isAlphaNum :: Char -> Bool
isAlphaNum c = if builtin_isAlphaNum c == 1 then True else False

foreign import bpcall "Char:isPrint" builtin_isPrint :: Char -> Int

isPrint :: Char -> Bool
isPrint c = if builtin_isPrint c == 1 then True else False

foreign import bpcall "Char:isDigit" builtin_isDigit :: Char -> Int

isDigit :: Char -> Bool
isDigit c = if builtin_isDigit c == 1 then True else False

-- isOctDigit :: Char -> Bool
-- not implemented

foreign import bpcall "Char:isHexDigit" builtin_isHexDigit :: Char -> Int

isHexDigit :: Char -> Bool
isHexDigit c = if builtin_isHexDigit c == 1 then True else False

isLetter :: Char -> Bool
isLetter = isAlpha

-- isMark :: Char -> Bool
-- not implemented

-- isNumber :: Char -> Bool
-- not implemented

foreign import bpcall "Char:isPunctuation" builtin_isPunctuation :: Char -> Int

isPunctuation :: Char -> Bool
isPunctuation c = if builtin_isPunctuation c == 1 then True else False

-- isSymbol :: Char -> Bool
-- not implemented

-- isSeparator :: Char -> Bool
-- not implemented

-- subranges
isAscii :: Char -> Bool
isAscii _ = True

isLatin1 :: Char -> Bool
isLatin1 _ = True

isAsciiUpper :: Char -> Bool
isAsciiUpper = isUpper

isAsciiLower :: Char -> Bool
isAsciiLower = isLower

-- Unicode general categories
-- GeneralCategory(..), generalCategory

-- case conversion
foreign import bpcall "Char:toUpper" toUpper :: Char -> Char

foreign import bpcall "Char:toLower" toLower :: Char -> Char

-- toTitle :: Char -> Char
-- not implemented

-- single digit characters
digitToInt :: Char -> Int
digitToInt c | dec <= 9  = dec
             | hexl <= 5 = hexl + 10
             | hexu <= 5 = hexu + 10
             | otherwise = error ("digitToInt: bad digit") --  ++ show c)
  where
    dec  = ord c - ord '0'
    hexl = ord c - ord 'a'
    hexu = ord c - ord 'A'

foreign import bpcall "Char:intToDigit" intToDigit :: Int -> Char

-- numeric representations
foreign import bpcall "Char:ord" ord :: Char -> Int

foreign import bpcall "Char:chr" chr :: Int -> Char

-- string representations
-- showLitChar :: Char -> ShowS
-- not implemented

-- lexLitChar :: ReadS String
-- not implemented

-- readLitChar :: ReadS Char
-- not implemented