Skip to content

Instantly share code, notes, and snippets.

@naohaq
Last active October 3, 2017 03:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save naohaq/b90edfa7308dd8db51314829d005df5e to your computer and use it in GitHub Desktop.
Save naohaq/b90edfa7308dd8db51314829d005df5e to your computer and use it in GitHub Desktop.
Stripping '\r' at the end of the string.
module Main where
import qualified Data.ByteString.Char8 as C
chomp :: C.ByteString -> C.ByteString
chomp str = chompCRLF $ chompCRLF str
where chompCRLF s =
case C.unsnoc s of
Nothing -> s
Just (s_c, '\r') -> s_c
Just (s_c, '\n') -> s_c
Just _ -> s
main :: IO ()
main = do ln <- chomp <$> C.getLine
C.putStrLn ln
-- EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment