module Text.Regex.Do.Split
(Split(..),
SplitFront(..),
SplitEnd(..),
T,L
) where
import qualified Data.ByteString.Search as S
import Data.ByteString as B hiding (break, breakEnd, split)
import Prelude hiding (break,(/))
import Text.Regex.Do.Match.Matchf
type T = (B.ByteString,B.ByteString)
type L = [B.ByteString]
class Split out where
(/)::ByteString -> ByteString -> out
instance Split (ByteString,ByteString) where
(/) body0 pat0 = (h1,t2)
where (h1,t1) = S.breakOn pat1 body0
len1 = B.length pat1
t2 = B.drop len1 t1
!pat1 = checkPattern pat0
class SplitFront out where
(-/)::ByteString
-> ByteString
-> out
instance SplitFront (ByteString,ByteString) where
(-/) body0 pat0 = S.breakOn pat1 body0
where !pat1 = checkPattern pat0
class SplitEnd out where
(/-)::ByteString
-> ByteString
-> out
instance SplitEnd (ByteString,ByteString) where
(/-) body0 pat0 = S.breakAfter pat1 body0
where !pat1 = checkPattern pat0
instance Split [ByteString] where
(/) body0 pat0 = S.split pat1 body0
where !pat1 = checkPattern pat0
instance SplitFront [ByteString] where
(-/) body0 pat0 = S.splitKeepFront pat1 body0
where !pat1 = checkPattern pat0
instance SplitEnd [ByteString] where
(/-) body0 pat0 = S.splitKeepEnd pat1 body0
where !pat1 = checkPattern pat0