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