@@ -1,6 +1,7 @@
11--writes Relation to a String suitable for terminal output
22module RelationTerm where
33import RelationType
4+import RelationTuple
45import Relation
56import qualified Data.Set as S
67import qualified Data.Map as M
@@ -48,10 +49,15 @@ cellLocations tab@(header, body) = (maxWidths, maxHeights)
4849 maxHeights = map (L.maximumBy compare) rowHeights
4950 mergeMax a b = map (\(a,b) -> max a b) (zip a b)
5051
52+--the normal "lines" function returns an empty list for an empty string which is not what we want
53+breakLines :: String -> [String]
54+breakLines "" = [""]
55+breakLines x = lines x
56+
5157cellSizes :: Table -> [([Int], [Int])]
52−cellSizes (header, body) = map (\row -> (map maxRowWidth row, map (length . lines) row)) allRows
58+cellSizes (header, body) = map (\row -> (map maxRowWidth row, map (length . breakLines) row)) allRows
5359 where
54− maxRowWidth row = L.maximumBy compare (map length (lines row))
60+ maxRowWidth row = L.maximumBy compare (map length (breakLines row))
5561 allRows = [header] ++ body
5662
5763relationAsTable :: Relation -> Table
@@ -87,7 +93,7 @@ renderHBar left middle end columnLocations = left ++ concat (L.intersperse middl
8793leftPaddedString :: Int -> Int -> String -> String
8894leftPaddedString lineNum size str = paddedLines !! lineNum
8995 where
90− paddedLines = map (\s -> s ++ repeatString (size - length s) " ") (lines str ++ repeat "")
96+ paddedLines = map (\s -> s ++ repeatString (size - length s) " ") (breakLines str ++ repeat "")
9197
9298renderRow :: [Cell] -> [Int] -> Int -> String -> String
9399renderRow cells columnLocations rowHeight interspersed = unlines $ map renderOneLine [0..rowHeight-1]
@@ -118,4 +124,11 @@ showRelation rel
118124
119125simpleExample = s
120126groupedExample = case group (S.fromList ["CITY"]) "CITYREL" s of {Right rel -> rel}
121−
127+
128+emptyStringExample = case mkRelation attributes tupleSet of
129+ Right x -> x
130+ _ -> undefined
131+ where
132+ attributes = M.fromList [("x", Attribute "x" StringAtomType)]
133+ tupleSet = HS.singleton $ mkRelationTuple (S.fromList ["x"]) (M.singleton "x" $ StringAtom "")
134+