
2 Jan
2012
2 Jan
'12
5:45 a.m.
On Mon, Jan 02, 2012 at 12:44:23PM +0300, max wrote:
I want to write a function whose behavior is as follows:
foo "string1\nstring2\r\nstring3\nstring4" = ["string1", "string2\r\nstring3", "string4"]
Note the sequence "\r\n", which is ignored. How can I do this?
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
unixLines :: String -> [String] unixLines xs = reverse . map reverse $ go xs "" [] where go [] l ls = l:ls go ('\r':'\n':xs) l ls = go xs ('\n':'\r':l) ls go ('\n':xs) l ls = go xs "" (l:ls) go (x:xs) l ls = go xs (x:l) ls