
15 Jul
2012
15 Jul
'12
8:08 a.m.
Hi, I've written a small haskell program to extract a section from a file between start and end markers. For example, if I have a file such as below - a b c <bug> d e f </bug> g h i I'd like to extract the contents between <bug> and </bug> (including the markers). startTag = "<bug>"endTag = "</bug>" process = unlines . specialTakeWhile (f endTag) . dropWhile (f startTag) . lines where f t x = not (x =~ t) specialTakeWhile :: (a -> Bool) -> [a] -> [a] specialTakeWhile ff [] = [] specialTakeWhile ff (x:xs) = if ff x then x:(specialTakeWhile ff xs) else [x] It'll be great if I could get some feedback on this. Regards, Kashyap