Skip to content

Instantly share code, notes, and snippets.

@moonmaster9000
Created April 11, 2010 22:05
Show Gist options
  • Save moonmaster9000/363105 to your computer and use it in GitHub Desktop.
Save moonmaster9000/363105 to your computer and use it in GitHub Desktop.
module LineEndingConverter
where
-- splits a string into substrings based on the newlines
-- and handles both windows and unix style line endings
splitLines [] = []
splitLines string = firstLine : remainingLines
where
(firstLine, rest) = break carriageReturnOrLineFeed string
remainingLines =
case rest of
('\r':'\n':t) -> splitLines t
('\r':t) -> splitLines t
('\n':t) -> splitLines t
_ -> []
-- detects if the character passed to it is either
-- a carriage return or line feed
carriageReturnOrLineFeed c = c == '\r' || c == '\n'
-- convert a string to Unix style line endings
convertStringToUnixStyleLineEndings = unlines . splitLines
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment