-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtil.hs
More file actions
59 lines (45 loc) · 1.58 KB
/
Util.hs
File metadata and controls
59 lines (45 loc) · 1.58 KB
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
module Util (
module Data.List,
module Console,
module Util,
module Data.Char
)
where
import Database.HDBC
import Database.HDBC.PostgreSQL
import Console
import Data.List (intercalate)
import Data.Char (isSpace)
gs :: SqlValue -> String
gs y@(SqlByteString x) = fromSql y
gs SqlNull = ""
gb :: SqlValue -> Bool
gb y@(SqlBool x) = fromSql y
gi :: SqlValue -> Int
gi y@(SqlInt32 x) = fromSql y
data Comparison a = Equal a | LeftOnly a | RightOnly a | Unequal a a
sok = concat [ setColor dullGreen, [charCheck] , " "]
nok = concat [setColor dullRed, setAttr bold, [charNotEquals], " "]
trim [] = []
trim x@(a:y) = if (isSpace a) then trim y else x
compareIgnoringWhiteSpace :: String -> String -> Bool
compareIgnoringWhiteSpace x y = ciws (trim x) (trim y)
where ciws x@(a:p) y@(b:q) =
if (isSpace a && isSpace b) then ciws (trim p) (trim q) else
if (a == b) then ciws p q else False
ciws x [] = null (trim x)
ciws [] y = null (trim y)
count x a = foldl (flip ((+) . fromEnum . x)) 0 a
dcount x y = foldl (\(a,b) z -> if (x z) then (a+1,b) else (a,b+1)) (0,0) y
iseq x = case x of { Equal _ -> True; otherwise -> False }
class Ord a => Comparable a where
-- doDbCompare :: [a] -> [a] -> [Comparison a]
dbCompare :: [a] -> [a] -> [Comparison a]
dbCompare x@(a:r) [] = map LeftOnly x
dbCompare [] y@(a:r) = map RightOnly y
dbCompare [] [] = []
dbCompare x@(a:r) y@(b:s) = case compare a b of
EQ -> objCmp a b : dbCompare r s
LT -> LeftOnly a : dbCompare r y
GT -> RightOnly b : dbCompare x s
objCmp :: a -> a -> Comparison a