Last active
October 3, 2017 03:54
-
-
Save naohaq/b90edfa7308dd8db51314829d005df5e to your computer and use it in GitHub Desktop.
Stripping '\r' at the end of the string.
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
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