Added student numbers
[fp1415.git] / fp1 / week1 / mart / MatchStrings.icl
1 implementation module MatchStrings
2
3 import StdEnv
4
5 head :: String -> Char
6 head "" = abort "Empty String"
7 head s = s.[0]
8
9 tail :: String -> String
10 tail "" = abort "Empty String"
11 tail s = s % (1, size s - 1)
12
13 is_gelijk :: String String -> Bool
14 is_gelijk "" "" = True
15 is_gelijk a b = (size a == size b) && (head a == head b) && is_gelijk (tail a) (tail b)
16
17 is_deelstring :: String String -> Bool
18 is_deelstring _ "" = False
19 is_deelstring a b = is_begin a b || is_deelstring a (tail b)
20
21 is_begin :: String String -> Bool
22 is_begin "" _ = True
23 is_begin _ "" = False
24 is_begin a b = head a == head b && is_begin (tail a) (tail b)
25
26 is_deel :: String String -> Bool
27 is_deel "" _ = True
28 is_deel _ "" = False
29 is_deel a b = head a == head b && is_deel (tail a) (tail b) || is_deel a (tail b)
30
31 is_match :: String String -> Bool
32 is_match a b = is_begin_match a b || size b > 0 && is_begin_match a (tail b)
33
34 is_begin_match :: String String -> Bool
35 is_begin_match "" _ = True
36 is_begin_match a "" = head a == '*' && size a == 1
37 is_begin_match a b
38 | head a == '.' || head a == head b = is_begin_match (tail a) (tail b)
39 | head a == '*' = is_begin_match a (tail b) || is_begin_match (tail a) b
40 | otherwise = False
41
42 //Start= (head pink_floyd, tail pink_floyd)
43 //Start= is_gelijk "" " "
44 //Start= is_deelstring "there" pink_floyd
45 //Start= is_deelstring "there" marillion
46 //Start= is_deel "there" marillion
47 //Start= is_deel "she and her" pink_floyd
48 //Start= is_deel radiohead pink_floyd
49 //Start= is_match "*.here*.here*." pink_floyd
50 //Start= is_match ".here.here." pink_floyd
51
52 pink_floyd= "Is there anybody in there?"
53 marillion= "Just for the record"
54 radiohead= "There there"