module Util where import Data.List import Data.Time.LocalTime replace _ _ [] = [] replace s1 s2 s@(x:s') | isPrefixOf s1 s = s2 ++ replace s1 s2 (drop (length s1) s) | otherwise = x:replace s1 s2 s' pos = ["ab","aba","abh","abm","al","av","ava","avh","avm","ie","in","inm","kn","kna","knm","mxc","nl","nlm","nn","nna","nnh","nnm","pm","pma","pmm","pn","pnm","pp","ppa","ppm","sn","snm","ssm","sxc","vb","vba","vbm"] replaces = foldr1 (.) [replace (p++":") " " | p <- pos] . replace ";" " " . replace "," " " untab [] = [] untab xs = case span (/= '\t') xs of (x,[]) -> [x] (x,(_:r)) -> x:untab r is_substring :: String -> String -> Bool is_substring str [] = False is_substring str s@(x:xs) | isPrefixOf str s = True | otherwise = is_substring str xs splitWith s s' = sp s' [] where sp [] [] = [] sp [] xs = [reverse xs] sp xs@(x:xs') ys | isPrefixOf s xs = (reverse ys) : sp (drop (length s) xs) [] | otherwise = sp xs' (x:ys) table_abbr :: String -> [(String,String)] table_abbr = process . map (words . rp) . splitWith "," where rp = filter (\c -> not (elem c "()")) process [] = [] process ([x]:xs) = (x,x) : process xs process ([x,y]:xs) = (y,x) : process xs process (_:xs) = process xs html :: String -> IO() html s = do t <- getZonedTime let time = takeWhile (/= '.') $ show t putStr $ unlines [ "", " ", " ", " ", " Svenskt Frasnät++", " ", " ", "

", " \"SweFN\"
", time, "

", s, " ", "" ]