packages feed

tableaux-0.2: src/Util.hs

module Util where
import Data.Char
import Test.QuickCheck


quote :: String -> String
quote = concatMap qchar 
    where qchar x | isUnquoted x = [x]
                  | otherwise  = '#':shows (ord x) ";"

isUnquoted :: Char -> Bool
isUnquoted x = x/='\"' && x/='\'' && x/='#'


unquote :: String -> String
unquote str
    | null str''= str
    | otherwise = str' ++ chr code : unquote str'''
    where (str',str'') = break (=='#') str
          (code,';':str'''):_ = reads (tail str'')


prop_roundtrip xs = collect (length xs) $ unquote (quote xs) == xs