    \begin{code}
    {-# LANGUAGE RecordWildCards            #-}
    {-# LANGUAGE FlexibleInstances          #-}
    {-# LANGUAGE UndecidableInstances       #-}
    {-# LANGUAGE MultiParamTypeClasses      #-}
    {-# LANGUAGE DeriveDataTypeable         #-}
    \end{code}

    \begin{code}
    module Text.RE.ZeInternals.Types.Capture
      ( Capture(..)
      , hasCaptured
      , capturePrefix
      , captureSuffix
      ) where
    \end{code}

    \begin{code}
    import           Text.Regex.Base
    \end{code}

    \begin{code}
    -- | the matching of a single sub-expression against part of the source
    -- text
    data Capture a =
      Capture
        { forall a. Capture a -> a
    captureSource  :: !a    -- ^ the whole text that was searched
        , forall a. Capture a -> a
    capturedText   :: !a    -- ^ the text that was matched
        , forall a. Capture a -> Int
    captureOffset  :: !Int  -- ^ the number of characters preceding the
                                  -- match with -1 used if no text was captured
                                  -- by the RE (not even the empty string)
        , forall a. Capture a -> Int
    captureLength  :: !Int  -- ^ the number of chacter in the captured
                                  -- sub-string
        }
      deriving (Int -> Capture a -> ShowS
    [Capture a] -> ShowS
    Capture a -> String
    (Int -> Capture a -> ShowS)
    -> (Capture a -> String)
    -> ([Capture a] -> ShowS)
    -> Show (Capture a)
    forall a. Show a => Int -> Capture a -> ShowS
    forall a. Show a => [Capture a] -> ShowS
    forall a. Show a => Capture a -> String
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: forall a. Show a => Int -> Capture a -> ShowS
    showsPrec :: Int -> Capture a -> ShowS
    $cshow :: forall a. Show a => Capture a -> String
    show :: Capture a -> String
    $cshowList :: forall a. Show a => [Capture a] -> ShowS
    showList :: [Capture a] -> ShowS
    Show,Capture a -> Capture a -> Bool
    (Capture a -> Capture a -> Bool)
    -> (Capture a -> Capture a -> Bool) -> Eq (Capture a)
    forall a. Eq a => Capture a -> Capture a -> Bool
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: forall a. Eq a => Capture a -> Capture a -> Bool
    == :: Capture a -> Capture a -> Bool
    $c/= :: forall a. Eq a => Capture a -> Capture a -> Bool
    /= :: Capture a -> Capture a -> Bool
    Eq)
    \end{code}

    \begin{code}
    instance Functor Capture where
      fmap :: forall a b. (a -> b) -> Capture a -> Capture b
    fmap a -> b
    f c :: Capture a
    c@Capture{a
    Int
    captureSource :: forall a. Capture a -> a
    capturedText :: forall a. Capture a -> a
    captureOffset :: forall a. Capture a -> Int
    captureLength :: forall a. Capture a -> Int
    captureSource :: a
    capturedText :: a
    captureOffset :: Int
    captureLength :: Int
    ..} =
        Capture a
    c
          { captureSource = f captureSource
          , capturedText = f capturedText
          }
    \end{code}

    \begin{code}
    -- | test if the capture has matched any text
    hasCaptured :: Capture a -> Bool
    hasCaptured :: forall a. Capture a -> Bool
    hasCaptured = (Int -> Int -> Bool
    forall a. Ord a => a -> a -> Bool
    >=Int
    0) (Int -> Bool) -> (Capture a -> Int) -> Capture a -> Bool
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Capture a -> Int
    forall a. Capture a -> Int
    captureOffset

    -- | returns the text preceding the match
    capturePrefix :: Extract a => Capture a -> a
    capturePrefix :: forall a. Extract a => Capture a -> a
    capturePrefix Capture{a
    Int
    captureSource :: forall a. Capture a -> a
    capturedText :: forall a. Capture a -> a
    captureOffset :: forall a. Capture a -> Int
    captureLength :: forall a. Capture a -> Int
    captureSource :: a
    capturedText :: a
    captureOffset :: Int
    captureLength :: Int
    ..} = Int -> a -> a
    forall source. Extract source => Int -> source -> source
    before Int
    captureOffset a
    captureSource

    -- | returns the text after the match
    captureSuffix :: Extract a => Capture a -> a
    captureSuffix :: forall a. Extract a => Capture a -> a
    captureSuffix Capture{a
    Int
    captureSource :: forall a. Capture a -> a
    capturedText :: forall a. Capture a -> a
    captureOffset :: forall a. Capture a -> Int
    captureLength :: forall a. Capture a -> Int
    captureSource :: a
    capturedText :: a
    captureOffset :: Int
    captureLength :: Int
    ..} = Int -> a -> a
    forall source. Extract source => Int -> source -> source
    after (Int
    captureOffsetInt -> Int -> Int
    forall a. Num a => a -> a -> a
    +Int
    captureLength) a
    captureSource
    \end{code}