-- | Copyright  : Will Thompson and Iñaki García Etxebarria
-- License    : LGPL-2.1
-- Maintainer : Iñaki García Etxebarria

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

module GI.GtkSource.Functions
    ( 

 -- * Methods


-- ** utilsEscapeSearchText #method:utilsEscapeSearchText#

    utilsEscapeSearchText                   ,


-- ** utilsUnescapeSearchText #method:utilsUnescapeSearchText#

    utilsUnescapeSearchText                 ,




    ) 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.BasicTypes as B.Types
import qualified Data.GI.Base.ManagedPtr as B.ManagedPtr
import qualified Data.GI.Base.GArray as B.GArray
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.GI.Base.Signals as B.Signals
import qualified Control.Monad.IO.Class as MIO
import qualified Data.Coerce as Coerce
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
import qualified GHC.Records as R


-- function utils_unescape_search_text
-- Args: [ Arg
--           { argCName = "text"
--           , argType = TBasicType TUTF8
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "the text to unescape."
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just (TBasicType TUTF8)
-- throws : False
-- Skip return : False

foreign import ccall "gtk_source_utils_unescape_search_text" gtk_source_utils_unescape_search_text :: 
    CString ->                              -- text : TBasicType TUTF8
    IO CString

-- | Use this function before 'GI.GtkSource.Objects.SearchSettings.searchSettingsSetSearchText', to
-- unescape the following sequences of characters: @\\n@, @\\r@, @\\t@ and @\\\\@.
-- The purpose is to easily write those characters in a search entry.
-- 
-- Note that unescaping the search text is not needed for regular expression
-- searches.
-- 
-- See also: 'GI.GtkSource.Functions.utilsEscapeSearchText'.
-- 
-- /Since: 3.10/
utilsUnescapeSearchText ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    T.Text
    -- ^ /@text@/: the text to unescape.
    -> m T.Text
    -- ^ __Returns:__ the unescaped /@text@/.
utilsUnescapeSearchText :: forall (m :: * -> *). (HasCallStack, MonadIO m) => Text -> m Text
utilsUnescapeSearchText Text
text = IO Text -> m Text
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Text -> m Text) -> IO Text -> m Text
forall a b. (a -> b) -> a -> b
$ do
    CString
text' <- Text -> IO CString
textToCString Text
text
    CString
result <- CString -> IO CString
gtk_source_utils_unescape_search_text CString
text'
    Text -> CString -> IO ()
forall a. HasCallStack => Text -> Ptr a -> IO ()
checkUnexpectedReturnNULL Text
"utilsUnescapeSearchText" CString
result
    Text
result' <- HasCallStack => CString -> IO Text
CString -> IO Text
cstringToText CString
result
    CString -> IO ()
forall a. Ptr a -> IO ()
freeMem CString
result
    CString -> IO ()
forall a. Ptr a -> IO ()
freeMem CString
text'
    Text -> IO Text
forall (m :: * -> *) a. Monad m => a -> m a
return Text
result'


-- function utils_escape_search_text
-- Args: [ Arg
--           { argCName = "text"
--           , argType = TBasicType TUTF8
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "the text to escape."
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just (TBasicType TUTF8)
-- throws : False
-- Skip return : False

foreign import ccall "gtk_source_utils_escape_search_text" gtk_source_utils_escape_search_text :: 
    CString ->                              -- text : TBasicType TUTF8
    IO CString

-- | Use this function to escape the following characters: @\\n@, @\\r@, @\\t@ and @\\@.
-- 
-- For a regular expression search, use 'GI.GLib.Functions.regexEscapeString' instead.
-- 
-- One possible use case is to take the t'GI.Gtk.Objects.TextBuffer.TextBuffer'\'s selection and put it in a
-- search entry. The selection can contain tabulations, newlines, etc. So it\'s
-- better to escape those special characters to better fit in the search entry.
-- 
-- See also: 'GI.GtkSource.Functions.utilsUnescapeSearchText'.
-- 
-- \<warning>
-- Warning: the escape and unescape functions are not reciprocal! For example,
-- escape (unescape (\\)) = \\. So avoid cycles such as: search entry -> unescape
-- -> search settings -> escape -> search entry. The original search entry text
-- may be modified.
-- \<\/warning>
-- 
-- /Since: 3.10/
utilsEscapeSearchText ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    T.Text
    -- ^ /@text@/: the text to escape.
    -> m T.Text
    -- ^ __Returns:__ the escaped /@text@/.
utilsEscapeSearchText :: forall (m :: * -> *). (HasCallStack, MonadIO m) => Text -> m Text
utilsEscapeSearchText Text
text = IO Text -> m Text
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Text -> m Text) -> IO Text -> m Text
forall a b. (a -> b) -> a -> b
$ do
    CString
text' <- Text -> IO CString
textToCString Text
text
    CString
result <- CString -> IO CString
gtk_source_utils_escape_search_text CString
text'
    Text -> CString -> IO ()
forall a. HasCallStack => Text -> Ptr a -> IO ()
checkUnexpectedReturnNULL Text
"utilsEscapeSearchText" CString
result
    Text
result' <- HasCallStack => CString -> IO Text
CString -> IO Text
cstringToText CString
result
    CString -> IO ()
forall a. Ptr a -> IO ()
freeMem CString
result
    CString -> IO ()
forall a. Ptr a -> IO ()
freeMem CString
text'
    Text -> IO Text
forall (m :: * -> *) a. Monad m => a -> m a
return Text
result'