Mercurial > repo
comparison ZJCe @ 1343:379d72ea85b6
<GreyKnight> fetch http://sprunge.us/ZJCe
author | HackBot |
---|---|
date | Thu, 10 Jan 2013 13:24:00 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
1342:4b8ca994f6de | 1343:379d72ea85b6 |
---|---|
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 |