eternal-0.0.8: src/Control/Eternal/String.hs
module Control.Eternal.String
( trim
) where
import Data.Char (isSpace)
trim :: String -> String
trim xs = dropSpaceTail "" $ dropWhile isSpace xs
dropSpaceTail :: String -> String -> String
dropSpaceTail maybeStuff "" = ""
dropSpaceTail maybeStuff (x:xs)
| isSpace x = dropSpaceTail (x:maybeStuff) xs
| null maybeStuff = x : dropSpaceTail "" xs
| otherwise = reverse maybeStuff ++ x : dropSpaceTail "" xs