Created
February 25, 2017 04:57
-
-
Save jeiea/df13a645fdb3ca82be924354e13e8556 to your computer and use it in GitHub Desktop.
Windows CR/LF compatible lines
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ClassyPrelude | |
-- | Windows CR/LF compatible lines | |
rLines :: Textual t => t -> [t] | |
rLines str = res where | |
(firstLine, rems) = break (\c -> c == '\r' || c == '\n') str | |
res = case uncons rems of | |
Nothing -> case uncons firstLine of | |
Nothing -> [] | |
Just _ -> [firstLine] | |
Just (x,xs) -> (firstLine :) $ rLines $ if x == '\n' then xs else | |
case uncons xs of | |
Just ('\n', rem') -> rem' | |
_ -> xs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment