regex-do-1.0: src/Regexdo/Trim.hs
module Regexdo.Trim where
import Regexdo.Pcre.Replace(replace,ReplaceCase(All))
import Regexdo.TypeDo
import Data.Char(isSpace)
import qualified Data.ByteString as B
import Regexdo.Convert
{- | removes leading and trailing spaces and tabs -}
class Trim a where
trim::a -> a
instance Trim B.ByteString where
trim bs1 = replace [All] (rx1,repl) $ Haystack bs1
where repl = Replacement B.empty
rx1 = rxFn "(^[\\s\\t]+)|([\\s\\t]+$)"
rxFn = Needle . toByteString
instance Trim String where
trim = f . f
where f = reverse . dropWhile isSpace