Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
import Data.Char (isSpace)
trim :: String -> String
trim = trimAndReverse . trimAndReverse
where trimAndReverse = reverse . dropWhile isSpace
reverseBreak :: (a -> Bool) -> [a] -> ([a], [a])
reverseBreak f xs = (reverse before, reverse after)
where (after, before) = break f $ reverse xs
wrapLine :: Int -> String -> [String]
wrapLine maxLen line
| length line <= maxLen = [line]
| any isSpace beforeMax = beforeSpace : (wrapLine maxLen $ afterSpace ++ afterMax)
| otherwise = beforeMax : wrapLine maxLen afterMax
where (beforeMax, afterMax) = splitAt maxLen line
(beforeSpace, afterSpace) = reverseBreak isSpace beforeMax
main :: IO ()
main = interact $ unlines . concatMap (map trim . wrapLine maxLen) . lines
where maxLen = 72
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.