summaryrefslogtreecommitdiff
path: root/bin/propellor_lines
blob: 8bdd28e1094caa2b984bb1cc0ff2fe36541a3cc6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/usr/bin/runhaskell

main = interact $ unlines . propellorLines . lines

propellorLines        :: [String] -> [String]
propellorLines (x:xs) = ("[ " ++ wrapEscapeLine x) : propellorLines' xs

propellorLines' :: [String] -> [String]
propellorLines' = foldr step ["]"]
  where
    step x xs = (", " ++ wrapEscapeLine x) : xs

wrapEscapeLine      :: String -> String
wrapEscapeLine line = "\"" ++ (foldr step "" line) ++ "\""
  where
    step x xs
    	| x == '\t' = "\\t" ++ xs
        | x == '\\' = x : x : xs
        | x == '"'  = '\\' : x : xs
        | otherwise = x : xs