From 063dce264230be0fe304110be4b648b746e1fdc4 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Sat, 6 Dec 2008 07:15:19 +0000 Subject: [PATCH] more string utils --- Ledger/Utils.hs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Ledger/Utils.hs b/Ledger/Utils.hs index 79cfb4f24..492d23c1e 100644 --- a/Ledger/Utils.hs +++ b/Ledger/Utils.hs @@ -114,6 +114,18 @@ padright :: Int -> String -> String padright w "" = concat $ replicate w " " padright w s = intercalate "\n" $ map (printf (printf "%%-%ds" w)) $ lines s +-- | Clip a multi-line string to the specified width and height from the top left. +cliptopleft :: Int -> Int -> String -> String +cliptopleft w h s = intercalate "\n" $ take h $ map (take w) $ lines s + +-- | Clip and pad a multi-line string to fill the specified width and height. +fitto :: Int -> Int -> String -> String +fitto w h s = intercalate "\n" $ take h $ rows ++ repeat blankline + where + rows = map (fit w) $ lines s + fit w s = take w $ s ++ repeat ' ' + blankline = replicate w ' ' + -- math difforzero :: (Num a, Ord a) => a -> a -> a