mirror of
https://github.com/simonmichael/hledger.git
synced 2024-11-08 07:09:28 +03:00
more string utils
This commit is contained in:
parent
4ea30b7411
commit
063dce2642
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user