packages feed

SVG2Q-0.3: Helpers.hs

module Helpers where
import Data.List (groupBy)
import Data.Char (isSpace)

-- splits a string into a list of strings
-- split "," "a,b" = ["a", "b"]
split :: String -> String -> [String]
split "" _ = error "empty delemiter."
split d s = let f = (== head d)
            in (filter (/= d)
                           (groupBy (\x y -> f x == f y)
                                    s))

-- replace. we sometimes need to replace stuff.
-- replace "hut" "u" "a" = "hat"
replace :: Eq a => [a] -> [a] -> [a] -> [a]
replace [] _ _ = []
replace s find repl =
    if take (length find) s == find
        then repl ++ replace (drop (length find) s) find repl
        else head s : replace (tail s) find repl


-- removes whitespaces
clean :: String -> String
clean = filter (not . isSpace)



-- determines, if a String represents a Float.
isFloat :: String -> Bool
isFloat s = let rds = reads s::[(Float, String)]
            in
            if rds == []
            then False
            else snd (head rds) == ""