summaryrefslogtreecommitdiff
path: root/Codec/Encryption/OpenPGP/ASCIIArmor/Utils.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Codec/Encryption/OpenPGP/ASCIIArmor/Utils.hs')
-rw-r--r--Codec/Encryption/OpenPGP/ASCIIArmor/Utils.hs16
1 files changed, 14 insertions, 2 deletions
diff --git a/Codec/Encryption/OpenPGP/ASCIIArmor/Utils.hs b/Codec/Encryption/OpenPGP/ASCIIArmor/Utils.hs
index f1068fe..e36b8db 100644
--- a/Codec/Encryption/OpenPGP/ASCIIArmor/Utils.hs
+++ b/Codec/Encryption/OpenPGP/ASCIIArmor/Utils.hs
@@ -14,11 +14,23 @@ import qualified Data.ByteString.Char8 as BC8
14import qualified Data.ByteString.Lazy as BL 14import qualified Data.ByteString.Lazy as BL
15import qualified Data.ByteString.Lazy.Char8 as BLC8 15import qualified Data.ByteString.Lazy.Char8 as BLC8
16import Data.List (intersperse) 16import Data.List (intersperse)
17import Data.Char (isSpace)
18
19removeTrailingSpaces :: ByteString -> ByteString
20removeTrailingSpaces bs = fst $ BC8.spanEnd isSpace bs
21
22toLast :: (a -> a) -> [a] -> [a]
23toLast _ [] = []
24toLast f [x] = [f x]
25toLast f (x:xs) = x : toLast f xs
26
27removeTrailingSpacesLazy :: BL.ByteString -> BL.ByteString
28removeTrailingSpacesLazy bs = BL.fromChunks $ toLast removeTrailingSpaces $ BL.toChunks bs
17 29
18crlfUnlines :: [ByteString] -> ByteString 30crlfUnlines :: [ByteString] -> ByteString
19crlfUnlines [] = B.empty 31crlfUnlines [] = B.empty
20crlfUnlines ss = B.concat $ intersperse (BC8.pack "\r\n") ss 32crlfUnlines ss = B.concat $ intersperse (BC8.pack "\r\n") $ map removeTrailingSpaces ss
21 33
22crlfUnlinesLazy :: [BL.ByteString] -> BL.ByteString 34crlfUnlinesLazy :: [BL.ByteString] -> BL.ByteString
23crlfUnlinesLazy [] = BL.empty 35crlfUnlinesLazy [] = BL.empty
24crlfUnlinesLazy ss = BL.concat $ intersperse (BLC8.pack "\r\n") ss 36crlfUnlinesLazy ss = BL.concat $ intersperse (BLC8.pack "\r\n") $ map removeTrailingSpacesLazy ss