
Untitled
By: a guest on
Aug 1st, 2012 | syntax:
None | size: 1.00 KB | hits: 8 | expires: Never
Changing <q> and </q> tags to " pairs in specific places
[caption id="attachment_100" align="aligncenter" width="300" caption="This is an image caption"]
import Data.List
import System.IO
main = do
inh <- openFile "input.txt" ReadMode
outh <- openFile "output.txt" WriteMode
str <- hGetContents inh
hPutStrLn outh (outsideCaption str)
hClose inh
hClose outh
outsideCaption::String->String
outsideCaption [] = []
outsideCaption str@(x:xs)
| isPrefixOf "[caption" str = insideCaption str
| otherwise = x:outsideCaption xs
insideCaption::String->String
insideCaption [] = []
insideCaption (']':xs) = ']':outsideCaption xs
insideCaption str@(x:xs)
| (isPrefixOf "<q>" str) = '"':insideCaption (drop 3 str)
| (isPrefixOf "</q>" str) = '"':insideCaption (drop 4 str)
| otherwise = x :insideCaption xs
main = interact outsideCaption
[rothesay]Ygfijj: echo "testing <q> [caption<q></q>]" | ./test
testing <q> [caption""]