Printer.hs 444 Bytes
Newer Older
1
module Printer
2
    (validateId,intercalate)
3 4
where

5
import Data.Char
6 7
import Data.ByteString.Builder
import Data.Monoid
8

9
validateId :: String -> String
10
validateId "" = "_"
11 12
validateId (x:xs) = (if isAlpha x then x else '_') :
        map (\c -> if isAlphaNum c then c else '_') xs
13 14 15 16 17 18 19


intercalate :: Builder -> [Builder] -> Builder
intercalate _ [] = mempty
intercalate sep (x:xs) = x <> go xs
      where go = foldr (\y -> (<>) (sep <> y)) mempty