{- |
Copyright  : Will Thompson, Iñaki García Etxebarria and Jonas Platte
License    : LGPL-2.1
Maintainer : Iñaki García Etxebarria (inaki@blueleaf.cc)

/No description available in the introspection data./
-}

#define ENABLE_OVERLOADING (MIN_VERSION_haskell_gi_overloading(1,0,0) \
       && !defined(__HADDOCK_VERSION__))

module GI.Vte.Structs.Regex
    (

-- * Exported types
    Regex(..)                               ,
    noRegex                                 ,


 -- * Methods
-- ** jit #method:jit#

#if ENABLE_OVERLOADING
    RegexJitMethodInfo                      ,
#endif
    regexJit                                ,


-- ** newForMatch #method:newForMatch#

    regexNewForMatch                        ,


-- ** newForSearch #method:newForSearch#

    regexNewForSearch                       ,


-- ** ref #method:ref#

#if ENABLE_OVERLOADING
    RegexRefMethodInfo                      ,
#endif
    regexRef                                ,


-- ** substitute #method:substitute#

#if ENABLE_OVERLOADING
    RegexSubstituteMethodInfo               ,
#endif
    regexSubstitute                         ,


-- ** unref #method:unref#

#if ENABLE_OVERLOADING
    RegexUnrefMethodInfo                    ,
#endif
    regexUnref                              ,




    ) where

import Data.GI.Base.ShortPrelude
import qualified Data.GI.Base.ShortPrelude as SP
import qualified Data.GI.Base.Overloading as O
import qualified Prelude as P

import qualified Data.GI.Base.Attributes as GI.Attributes
import qualified Data.GI.Base.ManagedPtr as B.ManagedPtr
import qualified Data.GI.Base.GClosure as B.GClosure
import qualified Data.GI.Base.GError as B.GError
import qualified Data.GI.Base.GVariant as B.GVariant
import qualified Data.GI.Base.GValue as B.GValue
import qualified Data.GI.Base.GParamSpec as B.GParamSpec
import qualified Data.GI.Base.CallStack as B.CallStack
import qualified Data.GI.Base.Properties as B.Properties
import qualified Data.Text as T
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as Map
import qualified Foreign.Ptr as FP
import qualified GHC.OverloadedLabels as OL


-- | Memory-managed wrapper type.
newtype Regex = Regex (ManagedPtr Regex)
foreign import ccall "vte_regex_get_type" c_vte_regex_get_type ::
    IO GType

instance BoxedObject Regex where
    boxedType _ = c_vte_regex_get_type

-- | A convenience alias for `Nothing` :: `Maybe` `Regex`.
noRegex :: Maybe Regex
noRegex = Nothing


#if ENABLE_OVERLOADING
instance O.HasAttributeList Regex
type instance O.AttributeList Regex = RegexAttributeList
type RegexAttributeList = ('[ ] :: [(Symbol, *)])
#endif

-- method Regex::new_for_match
-- method type : Constructor
-- Args : [Arg {argCName = "pattern", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Nothing, sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "pattern_length", argType = TBasicType TInt64, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Nothing, sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "flags", argType = TBasicType TUInt32, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Nothing, sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Vte", name = "Regex"}))
-- throws : True
-- Skip return : False

foreign import ccall "vte_regex_new_for_match" vte_regex_new_for_match ::
    CString ->                              -- pattern : TBasicType TUTF8
    Int64 ->                                -- pattern_length : TBasicType TInt64
    Word32 ->                               -- flags : TBasicType TUInt32
    Ptr (Ptr GError) ->                     -- error
    IO (Ptr Regex)

{- |
/No description available in the introspection data./
-}
regexNewForMatch ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    T.Text
    -> Int64
    -> Word32
    -> m Regex
    {- ^ /(Can throw 'Data.GI.Base.GError.GError')/ -}
regexNewForMatch pattern patternLength flags = liftIO $ do
    pattern' <- textToCString pattern
    onException (do
        result <- propagateGError $ vte_regex_new_for_match pattern' patternLength flags
        checkUnexpectedReturnNULL "regexNewForMatch" result
        result' <- (wrapBoxed Regex) result
        freeMem pattern'
        return result'
     ) (do
        freeMem pattern'
     )

#if ENABLE_OVERLOADING
#endif

-- method Regex::new_for_search
-- method type : Constructor
-- Args : [Arg {argCName = "pattern", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Nothing, sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "pattern_length", argType = TBasicType TInt64, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Nothing, sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "flags", argType = TBasicType TUInt32, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Nothing, sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Vte", name = "Regex"}))
-- throws : True
-- Skip return : False

foreign import ccall "vte_regex_new_for_search" vte_regex_new_for_search ::
    CString ->                              -- pattern : TBasicType TUTF8
    Int64 ->                                -- pattern_length : TBasicType TInt64
    Word32 ->                               -- flags : TBasicType TUInt32
    Ptr (Ptr GError) ->                     -- error
    IO (Ptr Regex)

{- |
/No description available in the introspection data./
-}
regexNewForSearch ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    T.Text
    -> Int64
    -> Word32
    -> m Regex
    {- ^ /(Can throw 'Data.GI.Base.GError.GError')/ -}
regexNewForSearch pattern patternLength flags = liftIO $ do
    pattern' <- textToCString pattern
    onException (do
        result <- propagateGError $ vte_regex_new_for_search pattern' patternLength flags
        checkUnexpectedReturnNULL "regexNewForSearch" result
        result' <- (wrapBoxed Regex) result
        freeMem pattern'
        return result'
     ) (do
        freeMem pattern'
     )

#if ENABLE_OVERLOADING
#endif

-- method Regex::jit
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "regex", argType = TInterface (Name {namespace = "Vte", name = "Regex"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Nothing, sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "flags", argType = TBasicType TUInt32, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Nothing, sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TBoolean)
-- throws : True
-- Skip return : False

foreign import ccall "vte_regex_jit" vte_regex_jit ::
    Ptr Regex ->                            -- regex : TInterface (Name {namespace = "Vte", name = "Regex"})
    Word32 ->                               -- flags : TBasicType TUInt32
    Ptr (Ptr GError) ->                     -- error
    IO CInt

{- |
/No description available in the introspection data./
-}
regexJit ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Regex
    -> Word32
    -> m ()
    {- ^ /(Can throw 'Data.GI.Base.GError.GError')/ -}
regexJit regex flags = liftIO $ do
    regex' <- unsafeManagedPtrGetPtr regex
    onException (do
        _ <- propagateGError $ vte_regex_jit regex' flags
        touchManagedPtr regex
        return ()
     ) (do
        return ()
     )

#if ENABLE_OVERLOADING
data RegexJitMethodInfo
instance (signature ~ (Word32 -> m ()), MonadIO m) => O.MethodInfo RegexJitMethodInfo Regex signature where
    overloadedMethod _ = regexJit

#endif

-- method Regex::ref
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "regex", argType = TInterface (Name {namespace = "Vte", name = "Regex"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Nothing, sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Vte", name = "Regex"}))
-- throws : False
-- Skip return : False

foreign import ccall "vte_regex_ref" vte_regex_ref ::
    Ptr Regex ->                            -- regex : TInterface (Name {namespace = "Vte", name = "Regex"})
    IO (Ptr Regex)

{- |
/No description available in the introspection data./
-}
regexRef ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Regex
    -> m Regex
regexRef regex = liftIO $ do
    regex' <- unsafeManagedPtrGetPtr regex
    result <- vte_regex_ref regex'
    checkUnexpectedReturnNULL "regexRef" result
    result' <- (wrapBoxed Regex) result
    touchManagedPtr regex
    return result'

#if ENABLE_OVERLOADING
data RegexRefMethodInfo
instance (signature ~ (m Regex), MonadIO m) => O.MethodInfo RegexRefMethodInfo Regex signature where
    overloadedMethod _ = regexRef

#endif

-- method Regex::substitute
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "regex", argType = TInterface (Name {namespace = "Vte", name = "Regex"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Nothing, sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "subject", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Nothing, sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "replacement", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Nothing, sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "flags", argType = TBasicType TUInt32, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Nothing, sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TUTF8)
-- throws : True
-- Skip return : False

foreign import ccall "vte_regex_substitute" vte_regex_substitute ::
    Ptr Regex ->                            -- regex : TInterface (Name {namespace = "Vte", name = "Regex"})
    CString ->                              -- subject : TBasicType TUTF8
    CString ->                              -- replacement : TBasicType TUTF8
    Word32 ->                               -- flags : TBasicType TUInt32
    Ptr (Ptr GError) ->                     -- error
    IO CString

{- |
/No description available in the introspection data./
-}
regexSubstitute ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Regex
    -> T.Text
    -> T.Text
    -> Word32
    -> m T.Text
    {- ^ /(Can throw 'Data.GI.Base.GError.GError')/ -}
regexSubstitute regex subject replacement flags = liftIO $ do
    regex' <- unsafeManagedPtrGetPtr regex
    subject' <- textToCString subject
    replacement' <- textToCString replacement
    onException (do
        result <- propagateGError $ vte_regex_substitute regex' subject' replacement' flags
        checkUnexpectedReturnNULL "regexSubstitute" result
        result' <- cstringToText result
        freeMem result
        touchManagedPtr regex
        freeMem subject'
        freeMem replacement'
        return result'
     ) (do
        freeMem subject'
        freeMem replacement'
     )

#if ENABLE_OVERLOADING
data RegexSubstituteMethodInfo
instance (signature ~ (T.Text -> T.Text -> Word32 -> m T.Text), MonadIO m) => O.MethodInfo RegexSubstituteMethodInfo Regex signature where
    overloadedMethod _ = regexSubstitute

#endif

-- method Regex::unref
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "regex", argType = TInterface (Name {namespace = "Vte", name = "Regex"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Nothing, sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Vte", name = "Regex"}))
-- throws : False
-- Skip return : False

foreign import ccall "vte_regex_unref" vte_regex_unref ::
    Ptr Regex ->                            -- regex : TInterface (Name {namespace = "Vte", name = "Regex"})
    IO (Ptr Regex)

{- |
/No description available in the introspection data./
-}
regexUnref ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Regex
    -> m Regex
regexUnref regex = liftIO $ do
    regex' <- unsafeManagedPtrGetPtr regex
    result <- vte_regex_unref regex'
    checkUnexpectedReturnNULL "regexUnref" result
    result' <- (wrapBoxed Regex) result
    touchManagedPtr regex
    return result'

#if ENABLE_OVERLOADING
data RegexUnrefMethodInfo
instance (signature ~ (m Regex), MonadIO m) => O.MethodInfo RegexUnrefMethodInfo Regex signature where
    overloadedMethod _ = regexUnref

#endif

#if ENABLE_OVERLOADING
type family ResolveRegexMethod (t :: Symbol) (o :: *) :: * where
    ResolveRegexMethod "jit" o = RegexJitMethodInfo
    ResolveRegexMethod "ref" o = RegexRefMethodInfo
    ResolveRegexMethod "substitute" o = RegexSubstituteMethodInfo
    ResolveRegexMethod "unref" o = RegexUnrefMethodInfo
    ResolveRegexMethod l o = O.MethodResolutionFailed l o

instance (info ~ ResolveRegexMethod t Regex, O.MethodInfo info Regex p) => OL.IsLabel t (Regex -> p) where
#if MIN_VERSION_base(4,10,0)
    fromLabel = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)
#else
    fromLabel _ = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)
#endif

#endif