Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- dropLine :: Int -> [Word] -> Line
- dropLine len [] = []
- dropLine len (w:ws)
- | len >= length w = dropLine newlen ws
- | otherwise = (w:ws)
- where newlen = len - (length w)
- joinLine :: Line -> String
- joinLine [] = []
- joinLine (x:xs) = (x ++ " ") ++ joinLine xs
- appendSpaceToWord :: Word -> Word
- appendSpaceToWord w = w ++ " "
- appendSpaceToFirstElementOfLine :: Word -> (Int, Line) -> (Int, Line)
- appendSpaceToFirstElementOfLine x (n, xs) = (n, (appendSpaceToWord x):xs)
- joinLineN :: (Int, Line) -> (Int, Line)
- joinLineN (n, []) = (n, [])
- joinLineN (0, xs) = (0, xs)
- joinLineN (n, (x:xs))
- | (wordLength x) < n = (fst result, snd result)
- | otherwise = (n, (x:xs))
- where result = appendSpaceToFirstElementOfLine x (joinLineN (left, xs))
- wordLength x = length x
- left = n - wordLength x
- lineLength :: Line -> Int
- lineLength line = Prelude.sum [length x | x <- line]
- joinLineA :: Int -> Line -> Line
- joinLineA 0 xs = xs
- joinLineA _ [] = []
- joinLineA n xs
- | n > 0 = joinLineA (fst result) (snd result)
- | otherwise = snd result
- where
- result = joinLineN (n, xs)
- joinLines :: [Line] -> String
- joinLines [] = []
- joinLines (x:xs) = (line ++ "\n") ++ joinLines xs
- where line = joinLine x
- -- Splitting into lines.
- splitLines :: [Word] -> [Line]
- splitLines [] = []
- splitLines ws
- = getLine lineLen ws
- : splitLines (dropLine lineLen ws)
- -- To fill a text string into lines, we write
- fill :: String -> [Line]
- fill = splitLines . splitWords
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement