Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 1st, 2012  |  syntax: None  |  size: 1.00 KB  |  hits: 8  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Changing <q> and </q> tags to " pairs in specific places
  2. [caption id="attachment_100" align="aligncenter" width="300" caption="This is an image caption"]
  3.        
  4. import Data.List
  5. import System.IO
  6.  
  7. main = do
  8.    inh  <- openFile "input.txt"  ReadMode
  9.    outh <- openFile "output.txt" WriteMode
  10.    str <- hGetContents inh
  11.    hPutStrLn outh (outsideCaption str)
  12.    hClose inh
  13.    hClose outh
  14.  
  15. outsideCaption::String->String
  16. outsideCaption [] = []
  17. outsideCaption str@(x:xs)
  18.     | isPrefixOf "[caption" str = insideCaption str
  19.     | otherwise                 = x:outsideCaption xs
  20.  
  21.  
  22. insideCaption::String->String
  23. insideCaption []       = []
  24. insideCaption (']':xs) = ']':outsideCaption xs
  25. insideCaption str@(x:xs)
  26.     | (isPrefixOf "<q>"  str) = '"':insideCaption (drop 3 str)
  27.     | (isPrefixOf "</q>" str) = '"':insideCaption (drop 4 str)
  28.     |  otherwise              = x   :insideCaption         xs
  29.        
  30. main = interact outsideCaption
  31.        
  32. [rothesay]Ygfijj: echo "testing <q> [caption<q></q>]" | ./test
  33. testing <q> [caption""]