1343
|
1 import Data.List
|
|
2 import Data.Char
|
|
3
|
|
4 standardURL = "http://esolangs.org/wiki/Main_Page"
|
|
5
|
|
6
|
|
7 replace :: (Eq a) => [a] -> [a] -> [a] -> [a]
|
|
8 replace _ _ [] = []
|
|
9 replace old new (y:ys) =
|
|
10 case stripPrefix old (y:ys) of
|
|
11 Nothing -> y : replace old new ys
|
|
12 Just ys' -> new ++ replace old new ys'
|
|
13
|
|
14 applyGenTemplate :: String -> String -> String -> String -- nick url template -> result
|
|
15 applyGenTemplate nick url template = nick ++ ": " ++ replace "^" nick (replace "@" url template)
|
|
16
|
|
17 applyTemplate :: String -> String -> String -- nick template -> result
|
|
18 applyTemplate nick template = applyGenTemplate nick standardURL template
|
|
19
|
|
20
|
|
21 main = do
|
|
22 template <- getLine
|
|
23 putStrLn (applyTemplate nick template)
|
|
24
|