Haskell :: Sprache |
Fremder (unbekannt) |
|
Mehrfachtests 29.11.2002 (05:03 Uhr) amo | ||||
Re: Aufgabe 2 - allDifferent 29.11.2002 (05:12 Uhr) amo | ||||
allDifferent2 01.12.2002 (19:39 Uhr) amo | ||||
allDifferent3 01.12.2002 (19:41 Uhr) amo | ||||
allDifferent -> allDifferent3 01.12.2002 (19:57 Uhr) amo | ||||
allDifferent -> allDifferent3 29.11.2002 (04:56 Uhr) amo | ||||
allDifferent4 01.12.2002 (20:08 Uhr) amo | ||||
allDifferent5 01.12.2002 (20:16 Uhr) amo | ||||
allDifferents 01.12.2002 (20:24 Uhr) amo | ||||
Aufgabe 3 - substring 27.11.2002 (22:59 Uhr) amo | ||||
modul mit Funktion zum Testen von checkHTML 04.12.2002 (03:27 Uhr) amo | ||||
Re: modul mit Funktion zum Testen von checkHTML 04.12.2002 (03:36 Uhr) amo | ||||
checkHTML - Primitivversion 04.12.2002 (05:03 Uhr) amo | ||||
Re: checkHTML - Primitivversion 04.12.2002 (05:09 Uhr) amo | ||||
ganze Datei für Blatt 6 04.12.2002 (12:52 Uhr) amo | ||||
module Uebungsblatt_06 ( allDifferent, substring, checkHTML ) where allDifferent2 :: Eq a => [a] -> Bool allDifferent2 [] = True allDifferent2 (x:[]) = True allDifferent2 (x:y:xs) = (x /= y) && allDifferent2 (x:xs) && allDifferent2 (y:xs) allDifferent3 :: Eq a => [a] -> Bool allDifferent3 [] = True allDifferent3 (x:[]) = True allDifferent3 (x:y:l) | x == y = False | otherwise = allDifferent3 (x:l) && allDifferent3 (y:l) allDifferent4 :: Eq a => [a] -> Bool allDifferent4 [] = True allDifferent4 (x:[]) = True allDifferent4 (x:xs) = notInList x xs && allDifferent4 xs allDifferent :: Eq a => [a] -> Bool allDifferent [] = True allDifferent (x:[]) = True allDifferent (x:xs) | inList x xs = False | otherwise = allDifferent xs inList :: Eq a => a -> [a] -> Bool inList _ [] = False inList x (y:ys) | x == y = True | otherwise = inList x ys notInList :: Eq a => a -> [a] -> Bool notInList _ [] = True notInList x (y:ys) | x == y = False | otherwise = notInList x ys substring :: String -> String -> Bool substring [] _ = True substring _ [] = False substring (e:es) (c:cs) = (e == c && substring es cs) || substring (e:es) cs klammerInhalt :: [a] -> [a] klammerInhalt xs = tail (init (xs)) isGeklammert :: Eq a => a -> a -> [a] -> Bool isGeklammert o s xs = (head xs == o) && (last xs == s) isHtmlKlammer :: [[Char]] -> Bool isHtmlKlammer = isGeklammert "<html>" "</html>" isHeadKlammer :: [[Char]] -> Bool isHeadKlammer = isGeklammert "<head>" "</head>" isTitleKlammer :: [[Char]] -> Bool isTitleKlammer = isGeklammert "<title>" "</title>" isMetaKlammer :: [[Char]] -> Bool isMetaKlammer = isGeklammert "<meta>" "</meta>" isBodyKlammer :: [[Char]] -> Bool isBodyKlammer = isGeklammert "<body>" "</body>" listeBis :: Eq a => a -> [a] -> [a] listeBis _ [] = [] listeBis e (x:xs) | e == x = [x] | otherwise = x : listeBis e xs anfKlammer :: (Eq a, Show a) => a -> a -> [a] -> [a] anfKlammer _ _ [] = [] anfKlammer o s (x:xs) | notInList s xs = error("Uebungsblatt_06.anfKlammer: Klammerungsfehler: " ++ show (xs) ++ " enthält die schließende Klammer " ++ show s ++ " nicht.") | o == x = x : listeBis s xs | otherwise = error ("Uebungsblatt_06.anfKlammer: Klammerungsfehler: " ++ show (x:xs) ++ " beginnt nicht mit " ++ show o ++ ".") trenneAnfKlammernAb :: String -> String -> Char -> [String] -> [[String]] trenneAnfKlammernAb _ _ _ [] = [[]] trenneAnfKlammernAb o s a (x:xs) | a == '1' = if x == o && inList s xs then let ak = anfKlammer o s (x:xs) in ak : [drop (length ak - 1) xs] else [x:xs] | a == '*' = if x == o && inList s xs then let ak = anfKlammer o s (x:xs) in ak : trenneAnfKlammernAb o s a (drop (length ak - 1) xs) else [x:xs] | a == '+' = if x == o && inList s xs then let ak = anfKlammer o s (x:xs) in ak : trenneAnfKlammernAb o s '*' (drop (length ak - 1) xs) else error ("Uebungsblatt_06.trenneAnfKlammernAb: Aktion " ++ show a ++ ": Klammerpaar " ++ show o ++ " - " ++ show s ++ " nicht in " ++ show (x:xs) ++ " enthalten.") | otherwise = error ("Uebungsblatt_06.trenneAnfKlammernAb: Aktion " ++ show a ++ " nicht definiert.") trenneAnfHeadAb = trenneAnfKlammernAb "<head>" "</head>" '1' trenneAnfTitleAb = trenneAnfKlammernAb "<title>" "</title>" '1' trenneAnfMetasAb = trenneAnfKlammernAb "<meta>" "</meta>" '*' klammerAnListAnf o s (x:xs) | o == x && inList s xs = True | otherwise = False headAnListAnf = klammerAnListAnf "<head>" "</head>" titleAnListAnf = klammerAnListAnf "<title>" "</title>" metaAnListAnf = klammerAnListAnf "<meta>" "</meta>" bodyAnListAnf = klammerAnListAnf "<body>" "</body>" {-- isHeadBodyKlassen xs | headAnListAnf xs = isHead hl && notInList "<head>" rL && notInList "</head>" rL && isBody rL where headTrenn = trenneAnfHeadAb xs hL = head headTrenn rL = tail headTrenn isHead hL = isHeadKlammer hL && isTitleMetaKlassen hI where hI = klammerInhalt hL isTitleMetaKlassen hI | titleAnListAnf hI = isTitle titL && notInList "<title>" titRL && notInList "</title>" titRL && isMetaKlassen titRL where titTrenn = trenneAnfTitleAb hI titL = head titTrenn titRL = tail titTrenn isTitle titL = isTitleKlammer titL isMetaKlassen titRL | titRL == [] = True | metaAnListAnf titRL = isMetas mL && mRL == [] where mTr = trenneAnfMetasAb titRL mL = init mTr mRL = last mTr isMetas [] = True isMetas (m:ms) = isMetaKlammer m && isMetas ms | otherwise = False | otherwise = False isBody rL = isBodyKlammer rL | otherwise = False checkHTML :: String -> Bool checkHTML s = let w = words s i = klammerInhalt w in isHtmlKlammer w && isHeadBodyKlassen i --} checkHTML :: String -> Bool checkHTML s = isAnf sa && isMetas sm && isEnde se where sw = words s anf = ["<html>","<head>","<title>","</title>"] meta = ["<meta>","</meta>"] end = ["</head>","<body>","</body>","</html>"] sa = take (length anf) sw soa = drop (length anf) sw se = drop (length sw - length end) sw sm = take (length soa - length end) soa isAnf sa = sa == anf isMetas [] = True isMetas sm | sm == [] = True | take 2 sm /= meta = False | otherwise = isMetas (drop 2 sm) isEnde se = se == end tCH :: IO () tCH = putStr (tch htmlTestList) where tch [] = "" tch (s:htl) = "checkHTML " ++ show s ++ " = " ++ show (checkHTML s) ++ "\n" ++ tch htl htmlTestList = [ html0, html1, html2, html3, html4, khtml0, khtml1, khtml2, khtml3, khtml4, khtml5, khtml6, khtml7, khtml8 ] html0 = "<html> <head> <title> </title> </head> <body> </body> </html>" html1 = "<html> <head> <title> </title> <meta> </meta> </head> <body> </body> </html>" html2 = "<html> <head> <title> </title> <meta> </meta> <meta> </meta> </head> <body> </body> </html>" html3 = "<html> <head> <title> </title> <meta> </meta> <meta> </meta> <meta> </meta> </head> <body> </body> </html>" html4 = "<html> <head> <title> </title> <meta> </meta> <meta> </meta> <meta> </meta> <meta> </meta> </head> <body> </body> </html>" khtml0 = "<html> <head> <title> </title> </head> <body> </body> " khtml1 = "<html> <head> <title> </title> </head> <body> </body> </htmll>" khtml2 = "<head> <title> </title> </head> <body> </body> </html>" khtml3 = "<html> <head> <title> Hallo Leute! </title> </head> <body> </body> </html>" khtml4 = "<html> <head> <title> </title> <meta name=\"test\" value=\"blafasel\"> </meta> <meta> </meta> </head> <body> </body> </html>" khtml5 = "<html> <head> <title> </title> <meta> </meta> <meta> MetaInhalt </meta> </head> <body> </body> </html>" khtml6 = "<html> <head> <title> </title> <meta> </meta> <meta> </meta> </head> <body> </body> </khtml>" khtml7 = "<html> <head> <title> </title> <meta> </meta> <meta> </meta> </head> <body> HTML-Text, der angezeigt wird, oder auch nicht... </body> </html>" khtml8 = "<html> <head> <meta> </meta> <meta> </meta> </head> <body> </body> </html>" -- trenneAnfKlammernAb "<html>" "</html>" '1' ["<html>","<head>","<title>","</title>","<meta>","</meta>","<meta>","</meta>","<meta>","</meta>","<meta>","</meta>","<meta>","</meta>","<meta>","</meta>","</head>","<body>","</body>","</html>"] | ||||
Zeige Beitrag 86 |
|
0 User im Forum. Kostenloses Forumhosting von plaudern.de. Dieses Forum im eigenen Design entführen. Impressum |