    {-# LANGUAGE TypeApplications #-}

    -- | Copyright  : Will Thompson and Iñaki García Etxebarria
    -- License    : LGPL-2.1
    -- Maintainer : Iñaki García Etxebarria
    --
    -- The @PangoLanguage@ structure is used to
    -- represent a language.
    --
    -- @PangoLanguage@ pointers can be efficiently
    -- copied and compared with each other.

    #if !defined(__HADDOCK_VERSION__)
    #define ENABLE_OVERLOADING
    #endif

    module GI.Pango.Structs.Language
        (

    -- * Exported types
        Language(..)                            ,

     -- * Methods
    -- |
    --
    --  === __Click to display all available methods, including inherited ones__
    -- ==== Methods
    -- [includesScript]("GI.Pango.Structs.Language#g:method:includesScript"), [matches]("GI.Pango.Structs.Language#g:method:matches"), [toString]("GI.Pango.Structs.Language#g:method:toString").
    --
    -- ==== Getters
    -- [getSampleString]("GI.Pango.Structs.Language#g:method:getSampleString"), [getScripts]("GI.Pango.Structs.Language#g:method:getScripts").
    --
    -- ==== Setters
    -- /None/.

    #if defined(ENABLE_OVERLOADING)
        ResolveLanguageMethod                   ,
    #endif

    -- ** fromString #method:fromString#

        languageFromString                      ,

    -- ** getDefault #method:getDefault#

        languageGetDefault                      ,

    -- ** getPreferred #method:getPreferred#

        languageGetPreferred                    ,

    -- ** getSampleString #method:getSampleString#

    #if defined(ENABLE_OVERLOADING)
        LanguageGetSampleStringMethodInfo       ,
    #endif
        languageGetSampleString                 ,

    -- ** getScripts #method:getScripts#

    #if defined(ENABLE_OVERLOADING)
        LanguageGetScriptsMethodInfo            ,
    #endif
        languageGetScripts                      ,

    -- ** includesScript #method:includesScript#

    #if defined(ENABLE_OVERLOADING)
        LanguageIncludesScriptMethodInfo        ,
    #endif
        languageIncludesScript                  ,

    -- ** matches #method:matches#

    #if defined(ENABLE_OVERLOADING)
        LanguageMatchesMethodInfo               ,
    #endif
        languageMatches                         ,

    -- ** toString #method:toString#

    #if defined(ENABLE_OVERLOADING)
        LanguageToStringMethodInfo              ,
    #endif
        languageToString                        ,

        ) 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.GHashTable as B.GHT
    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.Kind as DK
    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
    import qualified Data.Word as DW
    import qualified Data.Int as DI
    import qualified System.Posix.Types as SPT
    import qualified Foreign.C.Types as FCT

    -- Workaround for https://gitlab.haskell.org/ghc/ghc/-/issues/23392
    #if MIN_VERSION_base(4,18,0)
    import {-# SOURCE #-} qualified GI.Pango.Enums as Pango.Enums

    #else
    import {-# SOURCE #-} qualified GI.Pango.Enums as Pango.Enums

    #endif

    -- | Memory-managed wrapper type.
    newtype Language = Language (SP.ManagedPtr Language)
        deriving (Language -> Language -> Bool
    (Language -> Language -> Bool)
    -> (Language -> Language -> Bool) -> Eq Language
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: Language -> Language -> Bool
    == :: Language -> Language -> Bool
    $c/= :: Language -> Language -> Bool
    /= :: Language -> Language -> Bool
    Eq)

    instance SP.ManagedPtrNewtype Language where
        toManagedPtr :: Language -> ManagedPtr Language
    toManagedPtr (Language ManagedPtr Language
    p) = ManagedPtr Language
    p

    foreign import ccall "pango_language_get_type" c_pango_language_get_type ::
        IO GType

    type instance O.ParentTypes Language = '[]
    instance O.HasParentTypes Language

    instance B.Types.TypedObject Language where
        glibType :: IO GType
    glibType = IO GType
    c_pango_language_get_type

    instance B.Types.GBoxed Language

    -- | Convert 'Language' to and from 'Data.GI.Base.GValue.GValue'. See 'Data.GI.Base.GValue.toGValue' and 'Data.GI.Base.GValue.fromGValue'.
    instance B.GValue.IsGValue (Maybe Language) where
        gvalueGType_ :: IO GType
    gvalueGType_ = IO GType
    c_pango_language_get_type
        gvalueSet_ :: Ptr GValue -> Maybe Language -> IO ()
    gvalueSet_ Ptr GValue
    gv Maybe Language
    P.Nothing = Ptr GValue -> Ptr Language -> IO ()
    forall a. Ptr GValue -> Ptr a -> IO ()
    B.GValue.set_boxed Ptr GValue
    gv (Ptr Language
    forall a. Ptr a
    FP.nullPtr :: FP.Ptr Language)
        gvalueSet_ Ptr GValue
    gv (P.Just Language
    obj) = Language -> (Ptr Language -> IO ()) -> IO ()
    forall a c.
    (HasCallStack, ManagedPtrNewtype a) =>
    a -> (Ptr a -> IO c) -> IO c
    B.ManagedPtr.withManagedPtr Language
    obj (Ptr GValue -> Ptr Language -> IO ()
    forall a. Ptr GValue -> Ptr a -> IO ()
    B.GValue.set_boxed Ptr GValue
    gv)
        gvalueGet_ :: Ptr GValue -> IO (Maybe Language)
    gvalueGet_ Ptr GValue
    gv = do
            Ptr Language
    ptr <- Ptr GValue -> IO (Ptr Language)
    forall b. Ptr GValue -> IO (Ptr b)
    B.GValue.get_boxed Ptr GValue
    gv :: IO (Ptr Language)
            if Ptr Language
    ptr Ptr Language -> Ptr Language -> Bool
    forall a. Eq a => a -> a -> Bool
    /= Ptr Language
    forall a. Ptr a
    FP.nullPtr
            then Language -> Maybe Language
    forall a. a -> Maybe a
    P.Just (Language -> Maybe Language) -> IO Language -> IO (Maybe Language)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> (ManagedPtr Language -> Language) -> Ptr Language -> IO Language
    forall a.
    (HasCallStack, GBoxed a) =>
    (ManagedPtr a -> a) -> Ptr a -> IO a
    B.ManagedPtr.newBoxed ManagedPtr Language -> Language
    Language Ptr Language
    ptr
            else Maybe Language -> IO (Maybe Language)
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return Maybe Language
    forall a. Maybe a
    P.Nothing

    #if defined(ENABLE_OVERLOADING)
    instance O.HasAttributeList Language
    type instance O.AttributeList Language = LanguageAttributeList
    type LanguageAttributeList = ('[ ] :: [(Symbol, DK.Type)])
    #endif

    -- method Language::get_sample_string
    -- method type : OrdinaryMethod
    -- Args: [ Arg
    --           { argCName = "language"
    --           , argType =
    --               TInterface Name { namespace = "Pango" , name = "Language" }
    --           , direction = DirectionIn
    --           , mayBeNull = True
    --           , argDoc =
    --               Documentation
    --                 { rawDocText = Just "a `PangoLanguage`" , sinceVersion = Nothing }
    --           , argScope = ScopeTypeInvalid
    --           , argClosure = -1
    --           , argDestroy = -1
    --           , argCallerAllocates = False
    --           , argCallbackUserData = False
    --           , transfer = TransferNothing
    --           }
    --       ]
    -- Lengths: []
    -- returnType: Just (TBasicType TUTF8)
    -- throws : False
    -- Skip return : False

    foreign import ccall "pango_language_get_sample_string" pango_language_get_sample_string ::
        Ptr Language ->                         -- language : TInterface (Name {namespace = "Pango", name = "Language"})
        IO CString

    -- | Get a string that is representative of the characters needed to
    -- render a particular language.
    --
    -- The sample text may be a pangram, but is not necessarily. It is chosen
    -- to be demonstrative of normal text in the language, as well as exposing
    -- font feature requirements unique to the language. It is suitable for use
    -- as sample text in a font selection dialog.
    --
    -- If /@language@/ is 'P.Nothing', the default language as found by
    -- [func/@pango@/.Language.get_default] is used.
    --
    -- If Pango does not have a sample string for /@language@/, the classic
    -- \"The quick brown fox...\" is returned.  This can be detected by
    -- comparing the returned pointer value to that returned for (non-existent)
    -- language code \"xx\".  That is, compare to:
    --
    -- >pango_language_get_sample_string (pango_language_from_string ("xx"))
    languageGetSampleString ::
        (B.CallStack.HasCallStack, MonadIO m) =>
        Maybe (Language)
        -- ^ /@language@/: a @PangoLanguage@
        -> m T.Text
        -- ^ __Returns:__ the sample string
    languageGetSampleString :: forall (m :: * -> *).
    (HasCallStack, MonadIO m) =>
    Maybe Language -> m Text
    languageGetSampleString Maybe Language
    language = IO Text -> m Text
    forall a. IO a -> m a
    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
        Ptr Language
    maybeLanguage <- case Maybe Language
    language of
            Maybe Language
    Nothing -> Ptr Language -> IO (Ptr Language)
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return Ptr Language
    forall a. Ptr a
    FP.nullPtr
            Just Language
    jLanguage -> do
                Ptr Language
    jLanguage' <- Language -> IO (Ptr Language)
    forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
    unsafeManagedPtrGetPtr Language
    jLanguage
                Ptr Language -> IO (Ptr Language)
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return Ptr Language
    jLanguage'
        CString
    result <- Ptr Language -> IO CString
    pango_language_get_sample_string Ptr Language
    maybeLanguage
        Text -> CString -> IO ()
    forall a. HasCallStack => Text -> Ptr a -> IO ()
    checkUnexpectedReturnNULL Text
    "languageGetSampleString" CString
    result
        Text
    result' <- HasCallStack => CString -> IO Text
    CString -> IO Text
    cstringToText CString
    result
        Maybe Language -> (Language -> IO ()) -> IO ()
    forall (m :: * -> *) a. Monad m => Maybe a -> (a -> m ()) -> m ()
    whenJust Maybe Language
    language Language -> IO ()
    forall a. ManagedPtrNewtype a => a -> IO ()
    touchManagedPtr
        Text -> IO Text
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return Text
    result'

    #if defined(ENABLE_OVERLOADING)
    data LanguageGetSampleStringMethodInfo
    instance (signature ~ (m T.Text), MonadIO m) => O.OverloadedMethod LanguageGetSampleStringMethodInfo Language signature where
        overloadedMethod i = languageGetSampleString (Just i)

    instance O.OverloadedMethodInfo LanguageGetSampleStringMethodInfo Language where
        overloadedMethodInfo = P.Just (O.ResolvedSymbolInfo {
            O.resolvedSymbolName = "GI.Pango.Structs.Language.languageGetSampleString",
            O.resolvedSymbolURL = "https://hackage.haskell.org/package/gi-pango-1.0.30/docs/GI-Pango-Structs-Language.html#v:languageGetSampleString"
            })

    #endif

    -- method Language::get_scripts
    -- method type : OrdinaryMethod
    -- Args: [ Arg
    --           { argCName = "language"
    --           , argType =
    --               TInterface Name { namespace = "Pango" , name = "Language" }
    --           , direction = DirectionIn
    --           , mayBeNull = True
    --           , argDoc =
    --               Documentation
    --                 { rawDocText = Just "a `PangoLanguage`" , sinceVersion = Nothing }
    --           , argScope = ScopeTypeInvalid
    --           , argClosure = -1
    --           , argDestroy = -1
    --           , argCallerAllocates = False
    --           , argCallbackUserData = False
    --           , transfer = TransferNothing
    --           }
    --       , Arg
    --           { argCName = "num_scripts"
    --           , argType = TBasicType TInt
    --           , direction = DirectionOut
    --           , mayBeNull = False
    --           , argDoc =
    --               Documentation
    --                 { rawDocText = Just "location to return number of scripts"
    --                 , sinceVersion = Nothing
    --                 }
    --           , argScope = ScopeTypeInvalid
    --           , argClosure = -1
    --           , argDestroy = -1
    --           , argCallerAllocates = False
    --           , argCallbackUserData = False
    --           , transfer = TransferEverything
    --           }
    --       ]
    -- Lengths: [ Arg
    --              { argCName = "num_scripts"
    --              , argType = TBasicType TInt
    --              , direction = DirectionOut
    --              , mayBeNull = False
    --              , argDoc =
    --                  Documentation
    --                    { rawDocText = Just "location to return number of scripts"
    --                    , sinceVersion = Nothing
    --                    }
    --              , argScope = ScopeTypeInvalid
    --              , argClosure = -1
    --              , argDestroy = -1
    --              , argCallerAllocates = False
    --              , argCallbackUserData = False
    --              , transfer = TransferEverything
    --              }
    --          ]
    -- returnType: Just
    --               (TCArray
    --                  False
    --                  (-1)
    --                  1
    --                  (TInterface Name { namespace = "Pango" , name = "Script" }))
    -- throws : False
    -- Skip return : False

    foreign import ccall "pango_language_get_scripts" pango_language_get_scripts ::
        Ptr Language ->                         -- language : TInterface (Name {namespace = "Pango", name = "Language"})
        Ptr Int32 ->                            -- num_scripts : TBasicType TInt
        IO (Ptr CInt)

    -- | Determines the scripts used to to write /@language@/.
    --
    -- If nothing is known about the language tag /@language@/,
    -- or if /@language@/ is 'P.Nothing', then 'P.Nothing' is returned.
    -- The list of scripts returned starts with the script that the
    -- language uses most and continues to the one it uses least.
    --
    -- The value /@numScript@/ points at will be set to the number
    -- of scripts in the returned array (or zero if 'P.Nothing' is returned).
    --
    -- Most languages use only one script for writing, but there are
    -- some that use two (Latin and Cyrillic for example), and a few
    -- use three (Japanese for example). Applications should not make
    -- any assumptions on the maximum number of scripts returned
    -- though, except that it is positive if the return value is not
    -- 'P.Nothing', and it is a small number.
    --
    -- The 'GI.Pango.Structs.Language.languageIncludesScript' function uses this
    -- function internally.
    --
    -- Note: while the return value is declared as @PangoScript@, the
    -- returned values are from the @GUnicodeScript@ enumeration, which
    -- may have more values. Callers need to handle unknown values.
    --
    -- /Since: 1.22/
    languageGetScripts ::
        (B.CallStack.HasCallStack, MonadIO m) =>
        Maybe (Language)
        -- ^ /@language@/: a @PangoLanguage@
        -> m (Maybe [Pango.Enums.Script])
        -- ^ __Returns:__
        --   An array of @PangoScript@ values, with the number of entries in
        --   the array stored in /@numScripts@/, or 'P.Nothing' if Pango does not have
        --   any information about this particular language tag (also the case
        --   if /@language@/ is 'P.Nothing').
    languageGetScripts :: forall (m :: * -> *).
    (HasCallStack, MonadIO m) =>
    Maybe Language -> m (Maybe [Script])
    languageGetScripts Maybe Language
    language = IO (Maybe [Script]) -> m (Maybe [Script])
    forall a. IO a -> m a
    forall (m :: * -> *) a. MonadIO m => IO a -> m a
    liftIO (IO (Maybe [Script]) -> m (Maybe [Script]))
    -> IO (Maybe [Script]) -> m (Maybe [Script])
    forall a b. (a -> b) -> a -> b
    $ do
        Ptr Language
    maybeLanguage <- case Maybe Language
    language of
            Maybe Language
    Nothing -> Ptr Language -> IO (Ptr Language)
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return Ptr Language
    forall a. Ptr a
    FP.nullPtr
            Just Language
    jLanguage -> do
                Ptr Language
    jLanguage' <- Language -> IO (Ptr Language)
    forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
    unsafeManagedPtrGetPtr Language
    jLanguage
                Ptr Language -> IO (Ptr Language)
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return Ptr Language
    jLanguage'
        Ptr Int32
    numScripts <- IO (Ptr Int32)
    forall a. Storable a => IO (Ptr a)
    allocMem :: IO (Ptr Int32)
        Ptr CInt
    result <- Ptr Language -> Ptr Int32 -> IO (Ptr CInt)
    pango_language_get_scripts Ptr Language
    maybeLanguage Ptr Int32
    numScripts
        Int32
    numScripts' <- Ptr Int32 -> IO Int32
    forall a. Storable a => Ptr a -> IO a
    peek Ptr Int32
    numScripts
        Maybe [Script]
    maybeResult <- Ptr CInt -> (Ptr CInt -> IO [Script]) -> IO (Maybe [Script])
    forall a b. Ptr a -> (Ptr a -> IO b) -> IO (Maybe b)
    convertIfNonNull Ptr CInt
    result ((Ptr CInt -> IO [Script]) -> IO (Maybe [Script]))
    -> (Ptr CInt -> IO [Script]) -> IO (Maybe [Script])
    forall a b. (a -> b) -> a -> b
    $ \Ptr CInt
    result' -> do
            [CInt]
    result'' <- (Int32 -> Ptr CInt -> IO [CInt]
    forall a b. (Integral a, Storable b) => a -> Ptr b -> IO [b]
    unpackStorableArrayWithLength Int32
    numScripts') Ptr CInt
    result'
            let result''' :: [Script]
    result''' = (CInt -> Script) -> [CInt] -> [Script]
    forall a b. (a -> b) -> [a] -> [b]
    map (Int -> Script
    forall a. Enum a => Int -> a
    toEnum (Int -> Script) -> (CInt -> Int) -> CInt -> Script
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . CInt -> Int
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral) [CInt]
    result''
            [Script] -> IO [Script]
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return [Script]
    result'''
        Maybe Language -> (Language -> IO ()) -> IO ()
    forall (m :: * -> *) a. Monad m => Maybe a -> (a -> m ()) -> m ()
    whenJust Maybe Language
    language Language -> IO ()
    forall a. ManagedPtrNewtype a => a -> IO ()
    touchManagedPtr
        Ptr Int32 -> IO ()
    forall a. Ptr a -> IO ()
    freeMem Ptr Int32
    numScripts
        Maybe [Script] -> IO (Maybe [Script])
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return Maybe [Script]
    maybeResult

    #if defined(ENABLE_OVERLOADING)
    data LanguageGetScriptsMethodInfo
    instance (signature ~ (m (Maybe [Pango.Enums.Script])), MonadIO m) => O.OverloadedMethod LanguageGetScriptsMethodInfo Language signature where
        overloadedMethod i = languageGetScripts (Just i)

    instance O.OverloadedMethodInfo LanguageGetScriptsMethodInfo Language where
        overloadedMethodInfo = P.Just (O.ResolvedSymbolInfo {
            O.resolvedSymbolName = "GI.Pango.Structs.Language.languageGetScripts",
            O.resolvedSymbolURL = "https://hackage.haskell.org/package/gi-pango-1.0.30/docs/GI-Pango-Structs-Language.html#v:languageGetScripts"
            })

    #endif

    -- method Language::includes_script
    -- method type : OrdinaryMethod
    -- Args: [ Arg
    --           { argCName = "language"
    --           , argType =
    --               TInterface Name { namespace = "Pango" , name = "Language" }
    --           , direction = DirectionIn
    --           , mayBeNull = True
    --           , argDoc =
    --               Documentation
    --                 { rawDocText = Just "a `PangoLanguage`" , sinceVersion = Nothing }
    --           , argScope = ScopeTypeInvalid
    --           , argClosure = -1
    --           , argDestroy = -1
    --           , argCallerAllocates = False
    --           , argCallbackUserData = False
    --           , transfer = TransferNothing
    --           }
    --       , Arg
    --           { argCName = "script"
    --           , argType =
    --               TInterface Name { namespace = "Pango" , name = "Script" }
    --           , direction = DirectionIn
    --           , mayBeNull = False
    --           , argDoc =
    --               Documentation
    --                 { rawDocText = Just "a `PangoScript`" , sinceVersion = Nothing }
    --           , argScope = ScopeTypeInvalid
    --           , argClosure = -1
    --           , argDestroy = -1
    --           , argCallerAllocates = False
    --           , argCallbackUserData = False
    --           , transfer = TransferNothing
    --           }
    --       ]
    -- Lengths: []
    -- returnType: Just (TBasicType TBoolean)
    -- throws : False
    -- Skip return : False

    foreign import ccall "pango_language_includes_script" pango_language_includes_script ::
        Ptr Language ->                         -- language : TInterface (Name {namespace = "Pango", name = "Language"})
        CInt ->                                 -- script : TInterface (Name {namespace = "Pango", name = "Script"})
        IO CInt

    -- | Determines if /@script@/ is one of the scripts used to
    -- write /@language@/.
    --
    -- The returned value is conservative; if nothing is known about
    -- the language tag /@language@/, 'P.True' will be returned, since, as
    -- far as Pango knows, /@script@/ might be used to write /@language@/.
    --
    -- This routine is used in Pango\'s itemization process when
    -- determining if a supplied language tag is relevant to
    -- a particular section of text. It probably is not useful
    -- for applications in most circumstances.
    --
    -- This function uses 'GI.Pango.Structs.Language.languageGetScripts' internally.
    --
    -- /Since: 1.4/
    languageIncludesScript ::
        (B.CallStack.HasCallStack, MonadIO m) =>
        Maybe (Language)
        -- ^ /@language@/: a @PangoLanguage@
        -> Pango.Enums.Script
        -- ^ /@script@/: a @PangoScript@
        -> m Bool
        -- ^ __Returns:__ 'P.True' if /@script@/ is one of the scripts used
        --   to write /@language@/ or if nothing is known about /@language@/
        --   (including the case that /@language@/ is 'P.Nothing'), 'P.False' otherwise.
    languageIncludesScript :: forall (m :: * -> *).
    (HasCallStack, MonadIO m) =>
    Maybe Language -> Script -> m Bool
    languageIncludesScript Maybe Language
    language Script
    script = IO Bool -> m Bool
    forall a. IO a -> m a
    forall (m :: * -> *) a. MonadIO m => IO a -> m a
    liftIO (IO Bool -> m Bool) -> IO Bool -> m Bool
    forall a b. (a -> b) -> a -> b
    $ do
        Ptr Language
    maybeLanguage <- case Maybe Language
    language of
            Maybe Language
    Nothing -> Ptr Language -> IO (Ptr Language)
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return Ptr Language
    forall a. Ptr a
    FP.nullPtr
            Just Language
    jLanguage -> do
                Ptr Language
    jLanguage' <- Language -> IO (Ptr Language)
    forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
    unsafeManagedPtrGetPtr Language
    jLanguage
                Ptr Language -> IO (Ptr Language)
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return Ptr Language
    jLanguage'
        let script' :: CInt
    script' = (Int -> CInt
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral (Int -> CInt) -> (Script -> Int) -> Script -> CInt
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Script -> Int
    forall a. Enum a => a -> Int
    fromEnum) Script
    script
        CInt
    result <- Ptr Language -> CInt -> IO CInt
    pango_language_includes_script Ptr Language
    maybeLanguage CInt
    script'
        let result' :: Bool
    result' = (CInt -> CInt -> Bool
    forall a. Eq a => a -> a -> Bool
    /= CInt
    0) CInt
    result
        Maybe Language -> (Language -> IO ()) -> IO ()
    forall (m :: * -> *) a. Monad m => Maybe a -> (a -> m ()) -> m ()
    whenJust Maybe Language
    language Language -> IO ()
    forall a. ManagedPtrNewtype a => a -> IO ()
    touchManagedPtr
        Bool -> IO Bool
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return Bool
    result'

    #if defined(ENABLE_OVERLOADING)
    data LanguageIncludesScriptMethodInfo
    instance (signature ~ (Pango.Enums.Script -> m Bool), MonadIO m) => O.OverloadedMethod LanguageIncludesScriptMethodInfo Language signature where
        overloadedMethod i = languageIncludesScript (Just i)

    instance O.OverloadedMethodInfo LanguageIncludesScriptMethodInfo Language where
        overloadedMethodInfo = P.Just (O.ResolvedSymbolInfo {
            O.resolvedSymbolName = "GI.Pango.Structs.Language.languageIncludesScript",
            O.resolvedSymbolURL = "https://hackage.haskell.org/package/gi-pango-1.0.30/docs/GI-Pango-Structs-Language.html#v:languageIncludesScript"
            })

    #endif

    -- method Language::matches
    -- method type : OrdinaryMethod
    -- Args: [ Arg
    --           { argCName = "language"
    --           , argType =
    --               TInterface Name { namespace = "Pango" , name = "Language" }
    --           , direction = DirectionIn
    --           , mayBeNull = True
    --           , argDoc =
    --               Documentation
    --                 { rawDocText =
    --                     Just
    --                       "a language tag (see [func@Pango.Language.from_string]),\n  %NULL is allowed and matches nothing but '*'"
    --                 , sinceVersion = Nothing
    --                 }
    --           , argScope = ScopeTypeInvalid
    --           , argClosure = -1
    --           , argDestroy = -1
    --           , argCallerAllocates = False
    --           , argCallbackUserData = False
    --           , transfer = TransferNothing
    --           }
    --       , Arg
    --           { argCName = "range_list"
    --           , argType = TBasicType TUTF8
    --           , direction = DirectionIn
    --           , mayBeNull = False
    --           , argDoc =
    --               Documentation
    --                 { rawDocText =
    --                     Just
    --                       "a list of language ranges, separated by ';', ':',\n  ',', or space characters.\n  Each element must either be '*', or a RFC 3066 language range\n  canonicalized as by [func@Pango.Language.from_string]"
    --                 , sinceVersion = Nothing
    --                 }
    --           , argScope = ScopeTypeInvalid
    --           , argClosure = -1
    --           , argDestroy = -1
    --           , argCallerAllocates = False
    --           , argCallbackUserData = False
    --           , transfer = TransferNothing
    --           }
    --       ]
    -- Lengths: []
    -- returnType: Just (TBasicType TBoolean)
    -- throws : False
    -- Skip return : False

    foreign import ccall "pango_language_matches" pango_language_matches ::
        Ptr Language ->                         -- language : TInterface (Name {namespace = "Pango", name = "Language"})
        CString ->                              -- range_list : TBasicType TUTF8
        IO CInt

    -- | Checks if a language tag matches one of the elements in a list of
    -- language ranges.
    --
    -- A language tag is considered to match a range in the list if the
    -- range is \'*\', the range is exactly the tag, or the range is a prefix
    -- of the tag, and the character after it in the tag is \'-\'.
    languageMatches ::
        (B.CallStack.HasCallStack, MonadIO m) =>
        Maybe (Language)
        -- ^ /@language@/: a language tag (see [func/@pango@/.Language.from_string]),
        --   'P.Nothing' is allowed and matches nothing but \'*\'
        -> T.Text
        -- ^ /@rangeList@/: a list of language ranges, separated by \';\', \':\',
        --   \',\', or space characters.
        --   Each element must either be \'*\', or a RFC 3066 language range
        --   canonicalized as by [func/@pango@/.Language.from_string]
        -> m Bool
        -- ^ __Returns:__ 'P.True' if a match was found
    languageMatches :: forall (m :: * -> *).
    (HasCallStack, MonadIO m) =>
    Maybe Language -> Text -> m Bool
    languageMatches Maybe Language
    language Text
    rangeList = IO Bool -> m Bool
    forall a. IO a -> m a
    forall (m :: * -> *) a. MonadIO m => IO a -> m a
    liftIO (IO Bool -> m Bool) -> IO Bool -> m Bool
    forall a b. (a -> b) -> a -> b
    $ do
        Ptr Language
    maybeLanguage <- case Maybe Language
    language of
            Maybe Language
    Nothing -> Ptr Language -> IO (Ptr Language)
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return Ptr Language
    forall a. Ptr a
    FP.nullPtr
            Just Language
    jLanguage -> do
                Ptr Language
    jLanguage' <- Language -> IO (Ptr Language)
    forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
    unsafeManagedPtrGetPtr Language
    jLanguage
                Ptr Language -> IO (Ptr Language)
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return Ptr Language
    jLanguage'
        CString
    rangeList' <- Text -> IO CString
    textToCString Text
    rangeList
        CInt
    result <- Ptr Language -> CString -> IO CInt
    pango_language_matches Ptr Language
    maybeLanguage CString
    rangeList'
        let result' :: Bool
    result' = (CInt -> CInt -> Bool
    forall a. Eq a => a -> a -> Bool
    /= CInt
    0) CInt
    result
        Maybe Language -> (Language -> IO ()) -> IO ()
    forall (m :: * -> *) a. Monad m => Maybe a -> (a -> m ()) -> m ()
    whenJust Maybe Language
    language Language -> IO ()
    forall a. ManagedPtrNewtype a => a -> IO ()
    touchManagedPtr
        CString -> IO ()
    forall a. Ptr a -> IO ()
    freeMem CString
    rangeList'
        Bool -> IO Bool
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return Bool
    result'

    #if defined(ENABLE_OVERLOADING)
    data LanguageMatchesMethodInfo
    instance (signature ~ (T.Text -> m Bool), MonadIO m) => O.OverloadedMethod LanguageMatchesMethodInfo Language signature where
        overloadedMethod i = languageMatches (Just i)

    instance O.OverloadedMethodInfo LanguageMatchesMethodInfo Language where
        overloadedMethodInfo = P.Just (O.ResolvedSymbolInfo {
            O.resolvedSymbolName = "GI.Pango.Structs.Language.languageMatches",
            O.resolvedSymbolURL = "https://hackage.haskell.org/package/gi-pango-1.0.30/docs/GI-Pango-Structs-Language.html#v:languageMatches"
            })

    #endif

    -- method Language::to_string
    -- method type : OrdinaryMethod
    -- Args: [ Arg
    --           { argCName = "language"
    --           , argType =
    --               TInterface Name { namespace = "Pango" , name = "Language" }
    --           , direction = DirectionIn
    --           , mayBeNull = False
    --           , argDoc =
    --               Documentation
    --                 { rawDocText = Just "a language tag." , sinceVersion = Nothing }
    --           , argScope = ScopeTypeInvalid
    --           , argClosure = -1
    --           , argDestroy = -1
    --           , argCallerAllocates = False
    --           , argCallbackUserData = False
    --           , transfer = TransferNothing
    --           }
    --       ]
    -- Lengths: []
    -- returnType: Just (TBasicType TUTF8)
    -- throws : False
    -- Skip return : False

    foreign import ccall "pango_language_to_string" pango_language_to_string ::
        Ptr Language ->                         -- language : TInterface (Name {namespace = "Pango", name = "Language"})
        IO CString

    -- | Gets the RFC-3066 format string representing the given language tag.
    --
    -- Returns (transfer none): a string representing the language tag
    languageToString ::
        (B.CallStack.HasCallStack, MonadIO m) =>
        Language
        -- ^ /@language@/: a language tag.
        -> m T.Text
    languageToString :: forall (m :: * -> *).
    (HasCallStack, MonadIO m) =>
    Language -> m Text
    languageToString Language
    language = IO Text -> m Text
    forall a. IO a -> m a
    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
        Ptr Language
    language' <- Language -> IO (Ptr Language)
    forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
    unsafeManagedPtrGetPtr Language
    language
        CString
    result <- Ptr Language -> IO CString
    pango_language_to_string Ptr Language
    language'
        Text -> CString -> IO ()
    forall a. HasCallStack => Text -> Ptr a -> IO ()
    checkUnexpectedReturnNULL Text
    "languageToString" CString
    result
        Text
    result' <- HasCallStack => CString -> IO Text
    CString -> IO Text
    cstringToText CString
    result
        Language -> IO ()
    forall a. ManagedPtrNewtype a => a -> IO ()
    touchManagedPtr Language
    language
        Text -> IO Text
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return Text
    result'

    #if defined(ENABLE_OVERLOADING)
    data LanguageToStringMethodInfo
    instance (signature ~ (m T.Text), MonadIO m) => O.OverloadedMethod LanguageToStringMethodInfo Language signature where
        overloadedMethod = languageToString

    instance O.OverloadedMethodInfo LanguageToStringMethodInfo Language where
        overloadedMethodInfo = P.Just (O.ResolvedSymbolInfo {
            O.resolvedSymbolName = "GI.Pango.Structs.Language.languageToString",
            O.resolvedSymbolURL = "https://hackage.haskell.org/package/gi-pango-1.0.30/docs/GI-Pango-Structs-Language.html#v:languageToString"
            })

    #endif

    -- method Language::from_string
    -- method type : MemberFunction
    -- Args: [ Arg
    --           { argCName = "language"
    --           , argType = TBasicType TUTF8
    --           , direction = DirectionIn
    --           , mayBeNull = True
    --           , argDoc =
    --               Documentation
    --                 { rawDocText = Just "a string representing a language tag"
    --                 , sinceVersion = Nothing
    --                 }
    --           , argScope = ScopeTypeInvalid
    --           , argClosure = -1
    --           , argDestroy = -1
    --           , argCallerAllocates = False
    --           , argCallbackUserData = False
    --           , transfer = TransferNothing
    --           }
    --       ]
    -- Lengths: []
    -- returnType: Just (TInterface Name { namespace = "Pango" , name = "Language" })
    -- throws : False
    -- Skip return : False

    foreign import ccall "pango_language_from_string" pango_language_from_string ::
        CString ->                              -- language : TBasicType TUTF8
        IO (Ptr Language)

    -- | Convert a language tag to a @PangoLanguage@.
    --
    -- The language tag must be in a RFC-3066 format. @PangoLanguage@ pointers
    -- can be efficiently copied (copy the pointer) and compared with other
    -- language tags (compare the pointer.)
    --
    -- This function first canonicalizes the string by converting it to
    -- lowercase, mapping \'_\' to \'-\', and stripping all characters other
    -- than letters and \'-\'.
    --
    -- Use [func/@pango@/.Language.get_default] if you want to get the
    -- @PangoLanguage@ for the current locale of the process.
    languageFromString ::
        (B.CallStack.HasCallStack, MonadIO m) =>
        Maybe (T.Text)
        -- ^ /@language@/: a string representing a language tag
        -> m (Maybe Language)
        -- ^ __Returns:__ a @PangoLanguage@
    languageFromString :: forall (m :: * -> *).
    (HasCallStack, MonadIO m) =>
    Maybe Text -> m (Maybe Language)
    languageFromString Maybe Text
    language = IO (Maybe Language) -> m (Maybe Language)
    forall a. IO a -> m a
    forall (m :: * -> *) a. MonadIO m => IO a -> m a
    liftIO (IO (Maybe Language) -> m (Maybe Language))
    -> IO (Maybe Language) -> m (Maybe Language)
    forall a b. (a -> b) -> a -> b
    $ do
        CString
    maybeLanguage <- case Maybe Text
    language of
            Maybe Text
    Nothing -> CString -> IO CString
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return CString
    forall a. Ptr a
    FP.nullPtr
            Just Text
    jLanguage -> do
                CString
    jLanguage' <- Text -> IO CString
    textToCString Text
    jLanguage
                CString -> IO CString
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return CString
    jLanguage'
        Ptr Language
    result <- CString -> IO (Ptr Language)
    pango_language_from_string CString
    maybeLanguage
        Maybe Language
    maybeResult <- Ptr Language
    -> (Ptr Language -> IO Language) -> IO (Maybe Language)
    forall a b. Ptr a -> (Ptr a -> IO b) -> IO (Maybe b)
    convertIfNonNull Ptr Language
    result ((Ptr Language -> IO Language) -> IO (Maybe Language))
    -> (Ptr Language -> IO Language) -> IO (Maybe Language)
    forall a b. (a -> b) -> a -> b
    $ \Ptr Language
    result' -> do
            Language
    result'' <- ((ManagedPtr Language -> Language) -> Ptr Language -> IO Language
    forall a.
    (HasCallStack, GBoxed a) =>
    (ManagedPtr a -> a) -> Ptr a -> IO a
    newBoxed ManagedPtr Language -> Language
    Language) Ptr Language
    result'
            Language -> IO Language
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return Language
    result''
        CString -> IO ()
    forall a. Ptr a -> IO ()
    freeMem CString
    maybeLanguage
        Maybe Language -> IO (Maybe Language)
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return Maybe Language
    maybeResult

    #if defined(ENABLE_OVERLOADING)
    #endif

    -- method Language::get_default
    -- method type : MemberFunction
    -- Args: []
    -- Lengths: []
    -- returnType: Just (TInterface Name { namespace = "Pango" , name = "Language" })
    -- throws : False
    -- Skip return : False

    foreign import ccall "pango_language_get_default" pango_language_get_default ::
        IO (Ptr Language)

    -- | Returns the @PangoLanguage@ for the current locale of the process.
    --
    -- On Unix systems, this is the return value is derived from
    -- @setlocale (LC_CTYPE, NULL)@, and the user can
    -- affect this through the environment variables LC_ALL, LC_CTYPE or
    -- LANG (checked in that order). The locale string typically is in
    -- the form lang_COUNTRY, where lang is an ISO-639 language code, and
    -- COUNTRY is an ISO-3166 country code. For instance, sv_FI for
    -- Swedish as written in Finland or pt_BR for Portuguese as written in
    -- Brazil.
    --
    -- On Windows, the C library does not use any such environment
    -- variables, and setting them won\'t affect the behavior of functions
    -- like @/ctime()/@. The user sets the locale through the Regional Options
    -- in the Control Panel. The C library (in the @/setlocale()/@ function)
    -- does not use country and language codes, but country and language
    -- names spelled out in English.
    -- However, this function does check the above environment
    -- variables, and does return a Unix-style locale string based on
    -- either said environment variables or the thread\'s current locale.
    --
    -- Your application should call @setlocale(LC_ALL, \"\")@ for the user
    -- settings to take effect. GTK does this in its initialization
    -- functions automatically (by calling @/gtk_set_locale()/@).
    -- See the @/setlocale()/@ manpage for more details.
    --
    -- Note that the default language can change over the life of an application.
    --
    -- Also note that this function will not do the right thing if you
    -- use per-thread locales with @/uselocale()/@. In that case, you should
    -- just call 'GI.Pango.Functions.languageFromString' yourself.
    --
    -- /Since: 1.16/
    languageGetDefault ::
        (B.CallStack.HasCallStack, MonadIO m) =>
        m Language
        -- ^ __Returns:__ the default language as a @PangoLanguage@
    languageGetDefault :: forall (m :: * -> *). (HasCallStack, MonadIO m) => m Language
    languageGetDefault  = IO Language -> m Language
    forall a. IO a -> m a
    forall (m :: * -> *) a. MonadIO m => IO a -> m a
    liftIO (IO Language -> m Language) -> IO Language -> m Language
    forall a b. (a -> b) -> a -> b
    $ do
        Ptr Language
    result <- IO (Ptr Language)
    pango_language_get_default
        Text -> Ptr Language -> IO ()
    forall a. HasCallStack => Text -> Ptr a -> IO ()
    checkUnexpectedReturnNULL Text
    "languageGetDefault" Ptr Language
    result
        Language
    result' <- ((ManagedPtr Language -> Language) -> Ptr Language -> IO Language
    forall a.
    (HasCallStack, GBoxed a) =>
    (ManagedPtr a -> a) -> Ptr a -> IO a
    newBoxed ManagedPtr Language -> Language
    Language) Ptr Language
    result
        Language -> IO Language
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return Language
    result'

    #if defined(ENABLE_OVERLOADING)
    #endif

    -- method Language::get_preferred
    -- method type : MemberFunction
    -- Args: []
    -- Lengths: []
    -- returnType: Just
    --               (TCArray
    --                  True
    --                  (-1)
    --                  (-1)
    --                  (TInterface Name { namespace = "Pango" , name = "Language" }))
    -- throws : False
    -- Skip return : False

    foreign import ccall "pango_language_get_preferred" pango_language_get_preferred ::
        IO (Ptr (Ptr Language))

    -- | Returns the list of languages that the user prefers.
    --
    -- The list is specified by the @PANGO_LANGUAGE@ or @LANGUAGE@
    -- environment variables, in order of preference. Note that this
    -- list does not necessarily include the language returned by
    -- [func/@pango@/.Language.get_default].
    --
    -- When choosing language-specific resources, such as the sample
    -- text returned by 'GI.Pango.Structs.Language.languageGetSampleString',
    -- you should first try the default language, followed by the
    -- languages returned by this function.
    --
    -- /Since: 1.48/
    languageGetPreferred ::
        (B.CallStack.HasCallStack, MonadIO m) =>
        m (Maybe [Language])
        -- ^ __Returns:__ a 'P.Nothing'-terminated array
        --   of @PangoLanguage@*
    languageGetPreferred :: forall (m :: * -> *).
    (HasCallStack, MonadIO m) =>
    m (Maybe [Language])
    languageGetPreferred  = IO (Maybe [Language]) -> m (Maybe [Language])
    forall a. IO a -> m a
    forall (m :: * -> *) a. MonadIO m => IO a -> m a
    liftIO (IO (Maybe [Language]) -> m (Maybe [Language]))
    -> IO (Maybe [Language]) -> m (Maybe [Language])
    forall a b. (a -> b) -> a -> b
    $ do
        Ptr (Ptr Language)
    result <- IO (Ptr (Ptr Language))
    pango_language_get_preferred
        Maybe [Language]
    maybeResult <- Ptr (Ptr Language)
    -> (Ptr (Ptr Language) -> IO [Language]) -> IO (Maybe [Language])
    forall a b. Ptr a -> (Ptr a -> IO b) -> IO (Maybe b)
    convertIfNonNull Ptr (Ptr Language)
    result ((Ptr (Ptr Language) -> IO [Language]) -> IO (Maybe [Language]))
    -> (Ptr (Ptr Language) -> IO [Language]) -> IO (Maybe [Language])
    forall a b. (a -> b) -> a -> b
    $ \Ptr (Ptr Language)
    result' -> do
            [Ptr Language]
    result'' <- Ptr (Ptr Language) -> IO [Ptr Language]
    forall a. Ptr (Ptr a) -> IO [Ptr a]
    unpackZeroTerminatedPtrArray Ptr (Ptr Language)
    result'
            [Language]
    result''' <- (Ptr Language -> IO Language) -> [Ptr Language] -> IO [Language]
    forall (t :: * -> *) (m :: * -> *) a b.
    (Traversable t, Monad m) =>
    (a -> m b) -> t a -> m (t b)
    forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
    mapM ((ManagedPtr Language -> Language) -> Ptr Language -> IO Language
    forall a.
    (HasCallStack, GBoxed a) =>
    (ManagedPtr a -> a) -> Ptr a -> IO a
    newBoxed ManagedPtr Language -> Language
    Language) [Ptr Language]
    result''
            [Language] -> IO [Language]
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return [Language]
    result'''
        Maybe [Language] -> IO (Maybe [Language])
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return Maybe [Language]
    maybeResult

    #if defined(ENABLE_OVERLOADING)
    #endif

    #if defined(ENABLE_OVERLOADING)
    type family ResolveLanguageMethod (t :: Symbol) (o :: DK.Type) :: DK.Type where
        ResolveLanguageMethod "includesScript" o = LanguageIncludesScriptMethodInfo
        ResolveLanguageMethod "matches" o = LanguageMatchesMethodInfo
        ResolveLanguageMethod "toString" o = LanguageToStringMethodInfo
        ResolveLanguageMethod "getSampleString" o = LanguageGetSampleStringMethodInfo
        ResolveLanguageMethod "getScripts" o = LanguageGetScriptsMethodInfo
        ResolveLanguageMethod l o = O.MethodResolutionFailed l o

    instance (info ~ ResolveLanguageMethod t Language, O.OverloadedMethod info Language p) => OL.IsLabel t (Language -> p) where
    #if MIN_VERSION_base(4,10,0)
        fromLabel = O.overloadedMethod @info
    #else
        fromLabel _ = O.overloadedMethod @info
    #endif

    #if MIN_VERSION_base(4,13,0)
    instance (info ~ ResolveLanguageMethod t Language, O.OverloadedMethod info Language p, R.HasField t Language p) => R.HasField t Language p where
        getField = O.overloadedMethod @info

    #endif

    instance (info ~ ResolveLanguageMethod t Language, O.OverloadedMethodInfo info Language) => OL.IsLabel t (O.MethodProxy info Language) where
    #if MIN_VERSION_base(4,10,0)
        fromLabel = O.MethodProxy
    #else
        fromLabel _ = O.MethodProxy
    #endif

    #endif