summaryrefslogtreecommitdiff
path: root/Codec/LineReady.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Codec/LineReady.hs')
-rw-r--r--Codec/LineReady.hs23
1 files changed, 0 insertions, 23 deletions
diff --git a/Codec/LineReady.hs b/Codec/LineReady.hs
deleted file mode 100644
index a6961ca..0000000
--- a/Codec/LineReady.hs
+++ /dev/null
@@ -1,23 +0,0 @@
1module Codec.LineReady where
2
3import qualified Data.ByteString.Char8 as B
4import Data.Monoid
5import Data.List (foldl')
6import Data.Maybe
7
8toLineReady :: B.ByteString -> B.ByteString
9toLineReady blob =
10 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.drop 1 b
17 where (a,b) = B.splitAt i str
18
19fromLineReady :: B.ByteString -> B.ByteString
20fromLineReady str = foldl' (replaceCharStrIndex '\n') (B.drop 1 str') is
21 where is = map fst . mapMaybe B.readInt $
22 B.groupBy (\c d -> (c/=',')&&(d/=',')) ls
23 (ls,str') = B.break (==']') (B.drop 1 str)