packages feed

string-interpolate-0.3.1.1 / src / lib / Data / String / Interpolate / Whitespace.hs

module Data.String.Interpolate.Whitespace whereimport Data.List ( intercalate )import Data.String.Interpolate.Types-- |-- Collapse all the lines given into a single line, collapsing any whitespace-- found into a single space and removing begining/trailing whitespace.collapseWhitespace :: Lines -> LinecollapseWhitespace lines =  let oneliner = intercalate [Spaces 1] lines  in removeSurroundingWS $ toSingleSpace onelinertoSingleSpace :: Line -> LinetoSingleSpace [] = []toSingleSpace (x:y:xs) | isSpace x && isSpace y =  toSingleSpace (Spaces 1 : xs)toSingleSpace (x:xs) | isSpace x =  Spaces 1 : toSingleSpace xstoSingleSpace (x:xs) =  x : toSingleSpace xsremoveSurroundingWS :: Line -> LineremoveSurroundingWS =    dropWhile isSpace  . reverse  . dropWhile isSpace  . reverseisSpace :: InterpSegment -> BoolisSpace (Spaces _) = TrueisSpace (Tabs _)   = TrueisSpace _other     = False