summaryrefslogtreecommitdiff
path: root/Codec/SafeBlob.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Codec/SafeBlob.hs')
-rw-r--r--Codec/SafeBlob.hs22
1 files changed, 0 insertions, 22 deletions
diff --git a/Codec/SafeBlob.hs b/Codec/SafeBlob.hs
deleted file mode 100644
index a6db80e..0000000
--- a/Codec/SafeBlob.hs
+++ /dev/null
@@ -1,22 +0,0 @@
1{-# LANGUAGE ViewPatterns #-}
2module Codec.SafeBlob where
3
4import qualified Data.ByteString.Char8 as B
5import Data.Monoid
6import Data.List (foldl')
7import Data.Maybe
8
9toSafe :: B.ByteString -> B.ByteString
10toSafe blob = let as = zip [0..] (B.unpack blob)
11 bs = filter ((=='\n') . snd) as
12 is = map fst bs
13 in B.pack (show is) <> foldl' (replaceCharStrIndex '#') blob is
14
15replaceCharStrIndex :: Char -> B.ByteString -> Int -> B.ByteString
16replaceCharStrIndex c str i = a <> B.singleton c <> b
17 where (a,B.uncons -> Just (_,b)) = B.splitAt i str
18
19fromSafe str = foldl' (replaceCharStrIndex '\n') (B.drop 1 str') is
20 where is = map fst . mapMaybe B.readInt $
21 B.groupBy (\c d -> (c/=',')&&(d/=',')) ls
22 (ls,str') = B.break (==']') (B.tail str)