-- GENERATED by C->Haskell Compiler, version 0.28.7 Switcheroo, 25 November 2017 (Haskell)
-- Edit the ORIGNAL .chs file instead!


{-# LINE 1 "lib/CPython/Types/Unicode.chs" #-}
{-# LANGUAGE ForeignFunctionInterface #-}

-- Copyright (C) 2009 John Millikin <jmillikin@gmail.com>
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program.  If not, see <http://www.gnu.org/licenses/>.

module CPython.Types.Unicode
  (
  -- * Unicode objects
    Unicode
  , Encoding
  , ErrorHandling (..)
  , unicodeType
  , toUnicode
  , fromUnicode
  , length
  , fromEncodedObject
  , fromObject
  , encode
  , decode
  
  -- * Methods and slot functions
  , append
  , split
  , splitLines
  , translate
  , join
  , MatchDirection (..)
  , tailMatch
  , FindDirection (..)
  , find
  , count
  , replace
  , format
  , contains
  ) where
import qualified Foreign.C.Types as C2HSImp
import qualified Foreign.Marshal.Utils as C2HSImp
import qualified Foreign.Ptr as C2HSImp
import qualified System.IO.Unsafe as C2HSImp





import           Prelude hiding (length)
import           Control.Exception (ErrorCall (..), throwIO)
import qualified Data.Text as T

import           Data.Char (chr, ord)

import           CPython.Internal
import           CPython.Types.Bytes (Bytes)

newtype Unicode = Unicode (ForeignPtr Unicode)

instance Object Unicode where
  toObject :: Unicode -> SomeObject
toObject (Unicode x :: ForeignPtr Unicode
x) = ForeignPtr Unicode -> SomeObject
forall a. Object a => ForeignPtr a -> SomeObject
SomeObject ForeignPtr Unicode
x
  fromForeignPtr :: ForeignPtr Unicode -> Unicode
fromForeignPtr = ForeignPtr Unicode -> Unicode
Unicode

instance Concrete Unicode where
  concreteType :: Unicode -> Type
concreteType _ = Type
unicodeType

type Encoding = T.Text
data ErrorHandling
  = Strict
  | Replace
  | Ignore
  deriving (Int -> ErrorHandling -> ShowS
[ErrorHandling] -> ShowS
ErrorHandling -> String
(Int -> ErrorHandling -> ShowS)
-> (ErrorHandling -> String)
-> ([ErrorHandling] -> ShowS)
-> Show ErrorHandling
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ErrorHandling] -> ShowS
$cshowList :: [ErrorHandling] -> ShowS
show :: ErrorHandling -> String
$cshow :: ErrorHandling -> String
showsPrec :: Int -> ErrorHandling -> ShowS
$cshowsPrec :: Int -> ErrorHandling -> ShowS
Show, ErrorHandling -> ErrorHandling -> Bool
(ErrorHandling -> ErrorHandling -> Bool)
-> (ErrorHandling -> ErrorHandling -> Bool) -> Eq ErrorHandling
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ErrorHandling -> ErrorHandling -> Bool
$c/= :: ErrorHandling -> ErrorHandling -> Bool
== :: ErrorHandling -> ErrorHandling -> Bool
$c== :: ErrorHandling -> ErrorHandling -> Bool
Eq)

withErrors :: ErrorHandling -> (CString -> IO a) -> IO a
withErrors :: ErrorHandling -> (CString -> IO a) -> IO a
withErrors errors :: ErrorHandling
errors = String -> (CString -> IO a) -> IO a
forall a. String -> (CString -> IO a) -> IO a
withCString (String -> (CString -> IO a) -> IO a)
-> String -> (CString -> IO a) -> IO a
forall a b. (a -> b) -> a -> b
$ case ErrorHandling
errors of
  Strict -> "strict"
  Replace -> "replace"
  Ignore -> "ignore"

unicodeType :: (Type)
unicodeType :: Type
unicodeType =
  IO Type -> Type
forall a. IO a -> a
C2HSImp.unsafePerformIO (IO Type -> Type) -> IO Type -> Type
forall a b. (a -> b) -> a -> b
$
  IO (Ptr ())
unicodeType'_ IO (Ptr ()) -> (Ptr () -> IO Type) -> IO Type
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \res :: Ptr ()
res ->
  Ptr () -> IO Type
forall obj a. Object obj => Ptr a -> IO obj
peekStaticObject Ptr ()
res IO Type -> (Type -> IO Type) -> IO Type
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \res' :: Type
res' ->
  Type -> IO Type
forall (m :: * -> *) a. Monad m => a -> m a
return (Type
res')

{-# LINE 87 "lib/CPython/Types/Unicode.chs" #-}


toUnicode :: T.Text -> IO Unicode
toUnicode str = withBuffer toPython >>= stealObject where
  toPython ptr len = let
    len' = fromIntegral len
    ptr' = castPtr ptr
    in hscpython_PyUnicode_FromUnicode ptr' len'
  ords = map (fromIntegral . ord) (T.unpack str) :: [CUInt]
  withBuffer = withArrayLen ords . flip

fromUnicode :: Unicode -> IO T.Text
fromUnicode :: Unicode -> IO Text
fromUnicode obj :: Unicode
obj = Unicode -> (Ptr () -> IO Text) -> IO Text
forall obj a b. Object obj => obj -> (Ptr a -> IO b) -> IO b
withObject Unicode
obj ((Ptr () -> IO Text) -> IO Text) -> (Ptr () -> IO Text) -> IO Text
forall a b. (a -> b) -> a -> b
$ \ptr :: Ptr ()
ptr -> do
  Ptr CInt
buffer <- Ptr () -> IO (Ptr CInt)
hscpython_PyUnicode_AsUnicode Ptr ()
ptr
  CLong
size <- Ptr () -> IO CLong
hscpython_PyUnicode_GetSize Ptr ()
ptr
  [CInt]
raw <- Int -> Ptr CInt -> IO [CInt]
forall a. Storable a => Int -> Ptr a -> IO [a]
peekArray (CLong -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral CLong
size) Ptr CInt
buffer
  Text -> IO Text
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> IO Text) -> (String -> Text) -> String -> IO Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
T.pack (String -> IO Text) -> String -> IO Text
forall a b. (a -> b) -> a -> b
$ (CInt -> Char) -> [CInt] -> String
forall a b. (a -> b) -> [a] -> [b]
map (Int -> Char
chr (Int -> Char) -> (CInt -> Int) -> CInt -> Char
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CInt -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral) [CInt]
raw

length :: (Unicode) -> IO ((Integer))
length :: Unicode -> IO Integer
length a1 :: Unicode
a1 =
  Unicode -> (Ptr () -> IO Integer) -> IO Integer
forall obj a b. Object obj => obj -> (Ptr a -> IO b) -> IO b
withObject Unicode
a1 ((Ptr () -> IO Integer) -> IO Integer)
-> (Ptr () -> IO Integer) -> IO Integer
forall a b. (a -> b) -> a -> b
$ \a1' :: Ptr ()
a1' -> 
  Ptr () -> IO CLong
length'_ Ptr ()
a1' IO CLong -> (CLong -> IO Integer) -> IO Integer
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \res :: CLong
res ->
  CLong -> IO Integer
forall a. Integral a => a -> IO Integer
checkIntReturn CLong
res IO Integer -> (Integer -> IO Integer) -> IO Integer
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \res' :: Integer
res' ->
  Integer -> IO Integer
forall (m :: * -> *) a. Monad m => a -> m a
return (Integer
res')

{-# LINE 115 "lib/CPython/Types/Unicode.chs" #-}


-- | Coerce an encoded object /obj/ to an Unicode object.
--
-- 'Bytes' and other char buffer compatible objects are decoded according to
-- the given encoding and error handling mode.
--
-- All other objects, including 'Unicode' objects, cause a @TypeError@ to be
-- thrown.
fromEncodedObject :: Object obj => (obj) -> (Encoding) -> (ErrorHandling) -> IO ((Unicode))
fromEncodedObject :: obj -> Text -> ErrorHandling -> IO Unicode
fromEncodedObject a1 :: obj
a1 a2 :: Text
a2 a3 :: ErrorHandling
a3 =
  obj -> (Ptr () -> IO Unicode) -> IO Unicode
forall obj a b. Object obj => obj -> (Ptr a -> IO b) -> IO b
withObject obj
a1 ((Ptr () -> IO Unicode) -> IO Unicode)
-> (Ptr () -> IO Unicode) -> IO Unicode
forall a b. (a -> b) -> a -> b
$ \a1' :: Ptr ()
a1' -> 
  Text -> (CString -> IO Unicode) -> IO Unicode
forall a. Text -> (CString -> IO a) -> IO a
withText Text
a2 ((CString -> IO Unicode) -> IO Unicode)
-> (CString -> IO Unicode) -> IO Unicode
forall a b. (a -> b) -> a -> b
$ \a2' :: CString
a2' -> 
  ErrorHandling -> (CString -> IO Unicode) -> IO Unicode
forall a. ErrorHandling -> (CString -> IO a) -> IO a
withErrors ErrorHandling
a3 ((CString -> IO Unicode) -> IO Unicode)
-> (CString -> IO Unicode) -> IO Unicode
forall a b. (a -> b) -> a -> b
$ \a3' :: CString
a3' -> 
  Ptr () -> CString -> CString -> IO (Ptr ())
fromEncodedObject'_ Ptr ()
a1' CString
a2' CString
a3' IO (Ptr ()) -> (Ptr () -> IO Unicode) -> IO Unicode
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \res :: Ptr ()
res ->
  Ptr () -> IO Unicode
forall obj a. Object obj => Ptr a -> IO obj
stealObject Ptr ()
res IO Unicode -> (Unicode -> IO Unicode) -> IO Unicode
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \res' :: Unicode
res' ->
  Unicode -> IO Unicode
forall (m :: * -> *) a. Monad m => a -> m a
return (Unicode
res')

{-# LINE 129 "lib/CPython/Types/Unicode.chs" #-}


-- | Shortcut for @'fromEncodedObject' \"utf-8\" 'Strict'@
fromObject :: Object obj => obj -> IO Unicode
fromObject obj = fromEncodedObject obj (T.pack "utf-8") Strict

-- | Encode a 'Unicode' object and return the result as 'Bytes' object.
-- The encoding and error mode have the same meaning as the parameters of
-- the the @str.encode()@ method. The codec to be used is looked up using
-- the Python codec registry.
encode :: (Unicode) -> (Encoding) -> (ErrorHandling) -> IO ((Bytes))
encode :: Unicode -> Text -> ErrorHandling -> IO Bytes
encode a1 :: Unicode
a1 a2 :: Text
a2 a3 :: ErrorHandling
a3 =
  Unicode -> (Ptr () -> IO Bytes) -> IO Bytes
forall obj a b. Object obj => obj -> (Ptr a -> IO b) -> IO b
withObject Unicode
a1 ((Ptr () -> IO Bytes) -> IO Bytes)
-> (Ptr () -> IO Bytes) -> IO Bytes
forall a b. (a -> b) -> a -> b
$ \a1' :: Ptr ()
a1' -> 
  Text -> (CString -> IO Bytes) -> IO Bytes
forall a. Text -> (CString -> IO a) -> IO a
withText Text
a2 ((CString -> IO Bytes) -> IO Bytes)
-> (CString -> IO Bytes) -> IO Bytes
forall a b. (a -> b) -> a -> b
$ \a2' :: CString
a2' -> 
  ErrorHandling -> (CString -> IO Bytes) -> IO Bytes
forall a. ErrorHandling -> (CString -> IO a) -> IO a
withErrors ErrorHandling
a3 ((CString -> IO Bytes) -> IO Bytes)
-> (CString -> IO Bytes) -> IO Bytes
forall a b. (a -> b) -> a -> b
$ \a3' :: CString
a3' -> 
  Ptr () -> CString -> CString -> IO (Ptr ())
encode'_ Ptr ()
a1' CString
a2' CString
a3' IO (Ptr ()) -> (Ptr () -> IO Bytes) -> IO Bytes
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \res :: Ptr ()
res ->
  Ptr () -> IO Bytes
forall obj a. Object obj => Ptr a -> IO obj
stealObject Ptr ()
res IO Bytes -> (Bytes -> IO Bytes) -> IO Bytes
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \res' :: Bytes
res' ->
  Bytes -> IO Bytes
forall (m :: * -> *) a. Monad m => a -> m a
return (Bytes
res')

{-# LINE 143 "lib/CPython/Types/Unicode.chs" #-}


-- | Create a 'Unicode' object by decoding a 'Bytes' object. The encoding and
-- error mode have the same meaning as the parameters of the the
-- @str.encode()@ method. The codec to be used is looked up using the Python
-- codec registry.
decode :: Bytes -> Encoding -> ErrorHandling -> IO Unicode
decode :: Bytes -> Text -> ErrorHandling -> IO Unicode
decode bytes :: Bytes
bytes enc :: Text
enc errors :: ErrorHandling
errors =
  Bytes -> (Ptr () -> IO Unicode) -> IO Unicode
forall obj a b. Object obj => obj -> (Ptr a -> IO b) -> IO b
withObject Bytes
bytes ((Ptr () -> IO Unicode) -> IO Unicode)
-> (Ptr () -> IO Unicode) -> IO Unicode
forall a b. (a -> b) -> a -> b
$ \bytesPtr :: Ptr ()
bytesPtr ->
  Text -> (CString -> IO Unicode) -> IO Unicode
forall a. Text -> (CString -> IO a) -> IO a
withText Text
enc ((CString -> IO Unicode) -> IO Unicode)
-> (CString -> IO Unicode) -> IO Unicode
forall a b. (a -> b) -> a -> b
$ \encPtr :: CString
encPtr ->
  ErrorHandling -> (CString -> IO Unicode) -> IO Unicode
forall a. ErrorHandling -> (CString -> IO a) -> IO a
withErrors ErrorHandling
errors ((CString -> IO Unicode) -> IO Unicode)
-> (CString -> IO Unicode) -> IO Unicode
forall a b. (a -> b) -> a -> b
$ \errorsPtr :: CString
errorsPtr ->
  (Ptr CString -> IO Unicode) -> IO Unicode
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr CString -> IO Unicode) -> IO Unicode)
-> (Ptr CString -> IO Unicode) -> IO Unicode
forall a b. (a -> b) -> a -> b
$ \bufferPtr :: Ptr CString
bufferPtr ->
  (Ptr CLong -> IO Unicode) -> IO Unicode
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr CLong -> IO Unicode) -> IO Unicode)
-> (Ptr CLong -> IO Unicode) -> IO Unicode
forall a b. (a -> b) -> a -> b
$ \lenPtr :: Ptr CLong
lenPtr -> do
  Ptr () -> Ptr CString -> Ptr CLong -> IO CInt
pyBytesAsStringAndSize Ptr ()
bytesPtr Ptr CString
bufferPtr Ptr CLong
lenPtr
    IO CInt -> (CInt -> IO ()) -> IO ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= CInt -> IO ()
checkStatusCode
  CString
buffer <- Ptr CString -> IO CString
forall a. Storable a => Ptr a -> IO a
peek Ptr CString
bufferPtr
  CLong
len <- Ptr CLong -> IO CLong
forall a. Storable a => Ptr a -> IO a
peek Ptr CLong
lenPtr
  CString -> CLong -> CString -> CString -> IO (Ptr ())
hscpython_PyUnicode_Decode CString
buffer CLong
len CString
encPtr CString
errorsPtr
  IO (Ptr ()) -> (Ptr () -> IO Unicode) -> IO Unicode
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Ptr () -> IO Unicode
forall obj a. Object obj => Ptr a -> IO obj
stealObject

append :: (Unicode) -> (Unicode) -> IO ((Unicode))
append :: Unicode -> Unicode -> IO Unicode
append a1 :: Unicode
a1 a2 :: Unicode
a2 =
  Unicode -> (Ptr () -> IO Unicode) -> IO Unicode
forall obj a b. Object obj => obj -> (Ptr a -> IO b) -> IO b
withObject Unicode
a1 ((Ptr () -> IO Unicode) -> IO Unicode)
-> (Ptr () -> IO Unicode) -> IO Unicode
forall a b. (a -> b) -> a -> b
$ \a1' :: Ptr ()
a1' -> 
  Unicode -> (Ptr () -> IO Unicode) -> IO Unicode
forall obj a b. Object obj => obj -> (Ptr a -> IO b) -> IO b
withObject Unicode
a2 ((Ptr () -> IO Unicode) -> IO Unicode)
-> (Ptr () -> IO Unicode) -> IO Unicode
forall a b. (a -> b) -> a -> b
$ \a2' :: Ptr ()
a2' -> 
  Ptr () -> Ptr () -> IO (Ptr ())
append'_ Ptr ()
a1' Ptr ()
a2' IO (Ptr ()) -> (Ptr () -> IO Unicode) -> IO Unicode
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \res :: Ptr ()
res ->
  Ptr () -> IO Unicode
forall obj a. Object obj => Ptr a -> IO obj
stealObject Ptr ()
res IO Unicode -> (Unicode -> IO Unicode) -> IO Unicode
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \res' :: Unicode
res' ->
  Unicode -> IO Unicode
forall (m :: * -> *) a. Monad m => a -> m a
return (Unicode
res')

{-# LINE 166 "lib/CPython/Types/Unicode.chs" #-}


-- | Split a string giving a 'List' of 'Unicode' objects. If the separator is
-- 'Nothing', splitting will be done at all whitespace substrings. Otherwise,
-- splits occur at the given separator. Separators are not included in the
-- resulting list.
split
  :: Unicode
  -> Maybe Unicode -- ^ Separator
  -> Maybe Integer -- ^ Maximum splits
  -> IO List
split :: Unicode -> Maybe Unicode -> Maybe Integer -> IO List
split s :: Unicode
s sep :: Maybe Unicode
sep maxsplit :: Maybe Integer
maxsplit =
  Unicode -> (Ptr () -> IO List) -> IO List
forall obj a b. Object obj => obj -> (Ptr a -> IO b) -> IO b
withObject Unicode
s ((Ptr () -> IO List) -> IO List) -> (Ptr () -> IO List) -> IO List
forall a b. (a -> b) -> a -> b
$ \sPtr :: Ptr ()
sPtr ->
  (Unicode -> (Ptr () -> IO List) -> IO List)
-> Maybe Unicode -> (Ptr () -> IO List) -> IO List
forall a b c.
(a -> (Ptr b -> IO c) -> IO c)
-> Maybe a -> (Ptr b -> IO c) -> IO c
maybeWith Unicode -> (Ptr () -> IO List) -> IO List
forall obj a b. Object obj => obj -> (Ptr a -> IO b) -> IO b
withObject Maybe Unicode
sep ((Ptr () -> IO List) -> IO List) -> (Ptr () -> IO List) -> IO List
forall a b. (a -> b) -> a -> b
$ \sepPtr :: Ptr ()
sepPtr ->
  let max' :: CLong
max' = CLong -> (Integer -> CLong) -> Maybe Integer -> CLong
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (- 1) Integer -> CLong
forall a. Num a => Integer -> a
fromInteger Maybe Integer
maxsplit in
  Ptr () -> Ptr () -> CLong -> IO (Ptr ())
hscpython_PyUnicode_Split Ptr ()
sPtr Ptr ()
sepPtr CLong
max'
  IO (Ptr ()) -> (Ptr () -> IO List) -> IO List
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Ptr () -> IO List
forall obj a. Object obj => Ptr a -> IO obj
stealObject

-- | Split a 'Unicode' string at line breaks, returning a list of 'Unicode'
-- strings. CRLF is considered to be one line break. If the second parameter
-- is 'False', the line break characters are not included in the resulting
-- strings.
splitLines :: (Unicode) -> (Bool) -> IO ((List))
splitLines :: Unicode -> Bool -> IO List
splitLines a1 :: Unicode
a1 a2 :: Bool
a2 =
  Unicode -> (Ptr () -> IO List) -> IO List
forall obj a b. Object obj => obj -> (Ptr a -> IO b) -> IO b
withObject Unicode
a1 ((Ptr () -> IO List) -> IO List) -> (Ptr () -> IO List) -> IO List
forall a b. (a -> b) -> a -> b
$ \a1' :: Ptr ()
a1' -> 
  let {a2' :: CInt
a2' = Bool -> CInt
forall a. Num a => Bool -> a
C2HSImp.fromBool Bool
a2} in 
  Ptr () -> CInt -> IO (Ptr ())
splitLines'_ Ptr ()
a1' CInt
a2' IO (Ptr ()) -> (Ptr () -> IO List) -> IO List
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \res :: Ptr ()
res ->
  Ptr () -> IO List
forall obj a. Object obj => Ptr a -> IO obj
stealObject Ptr ()
res IO List -> (List -> IO List) -> IO List
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \res' :: List
res' ->
  List -> IO List
forall (m :: * -> *) a. Monad m => a -> m a
return (List
res')

{-# LINE 191 "lib/CPython/Types/Unicode.chs" #-}


-- | Translate a string by applying a character mapping table to it.
--
-- The mapping table must map Unicode ordinal integers to Unicode ordinal
-- integers or @None@ (causing deletion of the character).
--
-- Mapping tables need only provide the @__getitem__()@ interface;
-- dictionaries and sequences work well. Unmapped character ordinals (ones
-- which cause a @LookupError@) are left untouched and are copied as-is.
--
-- The error mode has the usual meaning for codecs.
translate :: Object table => (Unicode) -> (table) -> (ErrorHandling) -> IO ((Unicode))
translate :: Unicode -> table -> ErrorHandling -> IO Unicode
translate a1 :: Unicode
a1 a2 :: table
a2 a3 :: ErrorHandling
a3 =
  Unicode -> (Ptr () -> IO Unicode) -> IO Unicode
forall obj a b. Object obj => obj -> (Ptr a -> IO b) -> IO b
withObject Unicode
a1 ((Ptr () -> IO Unicode) -> IO Unicode)
-> (Ptr () -> IO Unicode) -> IO Unicode
forall a b. (a -> b) -> a -> b
$ \a1' :: Ptr ()
a1' -> 
  table -> (Ptr () -> IO Unicode) -> IO Unicode
forall obj a b. Object obj => obj -> (Ptr a -> IO b) -> IO b
withObject table
a2 ((Ptr () -> IO Unicode) -> IO Unicode)
-> (Ptr () -> IO Unicode) -> IO Unicode
forall a b. (a -> b) -> a -> b
$ \a2' :: Ptr ()
a2' -> 
  ErrorHandling -> (CString -> IO Unicode) -> IO Unicode
forall a. ErrorHandling -> (CString -> IO a) -> IO a
withErrors ErrorHandling
a3 ((CString -> IO Unicode) -> IO Unicode)
-> (CString -> IO Unicode) -> IO Unicode
forall a b. (a -> b) -> a -> b
$ \a3' :: CString
a3' -> 
  Ptr () -> Ptr () -> CString -> IO (Ptr ())
translate'_ Ptr ()
a1' Ptr ()
a2' CString
a3' IO (Ptr ()) -> (Ptr () -> IO Unicode) -> IO Unicode
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \res :: Ptr ()
res ->
  Ptr () -> IO Unicode
forall obj a. Object obj => Ptr a -> IO obj
stealObject Ptr ()
res IO Unicode -> (Unicode -> IO Unicode) -> IO Unicode
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \res' :: Unicode
res' ->
  Unicode -> IO Unicode
forall (m :: * -> *) a. Monad m => a -> m a
return (Unicode
res')

{-# LINE 208 "lib/CPython/Types/Unicode.chs" #-}


-- | Join a sequence of strings using the given separator.
join :: Sequence seq => (Unicode) -> (seq) -> IO ((Unicode))
join :: Unicode -> seq -> IO Unicode
join a1 :: Unicode
a1 a2 :: seq
a2 =
  Unicode -> (Ptr () -> IO Unicode) -> IO Unicode
forall obj a b. Object obj => obj -> (Ptr a -> IO b) -> IO b
withObject Unicode
a1 ((Ptr () -> IO Unicode) -> IO Unicode)
-> (Ptr () -> IO Unicode) -> IO Unicode
forall a b. (a -> b) -> a -> b
$ \a1' :: Ptr ()
a1' -> 
  seq -> (Ptr () -> IO Unicode) -> IO Unicode
forall obj a b. Object obj => obj -> (Ptr a -> IO b) -> IO b
withObject seq
a2 ((Ptr () -> IO Unicode) -> IO Unicode)
-> (Ptr () -> IO Unicode) -> IO Unicode
forall a b. (a -> b) -> a -> b
$ \a2' :: Ptr ()
a2' -> 
  Ptr () -> Ptr () -> IO (Ptr ())
join'_ Ptr ()
a1' Ptr ()
a2' IO (Ptr ()) -> (Ptr () -> IO Unicode) -> IO Unicode
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \res :: Ptr ()
res ->
  Ptr () -> IO Unicode
forall obj a. Object obj => Ptr a -> IO obj
stealObject Ptr ()
res IO Unicode -> (Unicode -> IO Unicode) -> IO Unicode
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \res' :: Unicode
res' ->
  Unicode -> IO Unicode
forall (m :: * -> *) a. Monad m => a -> m a
return (Unicode
res')

{-# LINE 215 "lib/CPython/Types/Unicode.chs" #-}


data MatchDirection = Prefix | Suffix
  deriving (Show, Eq)

-- | Return 'True' if the substring matches @string*[*start:end]@ at the
-- given tail end (either a 'Prefix' or 'Suffix' match), 'False' otherwise.
tailMatch
  :: Unicode -- ^ String
  -> Unicode -- ^ Substring
  -> Integer -- ^ Start
  -> Integer -- ^ End
  -> MatchDirection
  -> IO Bool
tailMatch :: Unicode
-> Unicode -> Integer -> Integer -> MatchDirection -> IO Bool
tailMatch str :: Unicode
str substr :: Unicode
substr start :: Integer
start end :: Integer
end dir :: MatchDirection
dir =
  Unicode -> (Ptr () -> IO Bool) -> IO Bool
forall obj a b. Object obj => obj -> (Ptr a -> IO b) -> IO b
withObject Unicode
str ((Ptr () -> IO Bool) -> IO Bool) -> (Ptr () -> IO Bool) -> IO Bool
forall a b. (a -> b) -> a -> b
$ \strPtr :: Ptr ()
strPtr ->
    Unicode -> (Ptr () -> IO Bool) -> IO Bool
forall obj a b. Object obj => obj -> (Ptr a -> IO b) -> IO b
withObject Unicode
substr ((Ptr () -> IO Bool) -> IO Bool) -> (Ptr () -> IO Bool) -> IO Bool
forall a b. (a -> b) -> a -> b
$ \substrPtr :: Ptr ()
substrPtr ->
      let start' :: CLong
start' = Integer -> CLong
forall a. Num a => Integer -> a
fromInteger Integer
start
          end' :: CLong
end' = Integer -> CLong
forall a. Num a => Integer -> a
fromInteger Integer
end
          dir' :: CInt
dir' = case MatchDirection
dir of Prefix -> -1
                             Suffix -> 1
      in Ptr () -> Ptr () -> CLong -> CLong -> CInt -> IO CInt
hscpython_PyUnicode_Tailmatch Ptr ()
strPtr Ptr ()
substrPtr CLong
start' CLong
end' CInt
dir'
  IO CInt -> (CInt -> IO Bool) -> IO Bool
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= CInt -> IO Bool
checkBoolReturn

data FindDirection = Forwards | Backwards
  deriving (Int -> FindDirection -> ShowS
[FindDirection] -> ShowS
FindDirection -> String
(Int -> FindDirection -> ShowS)
-> (FindDirection -> String)
-> ([FindDirection] -> ShowS)
-> Show FindDirection
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [FindDirection] -> ShowS
$cshowList :: [FindDirection] -> ShowS
show :: FindDirection -> String
$cshow :: FindDirection -> String
showsPrec :: Int -> FindDirection -> ShowS
$cshowsPrec :: Int -> FindDirection -> ShowS
Show, FindDirection -> FindDirection -> Bool
(FindDirection -> FindDirection -> Bool)
-> (FindDirection -> FindDirection -> Bool) -> Eq FindDirection
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FindDirection -> FindDirection -> Bool
$c/= :: FindDirection -> FindDirection -> Bool
== :: FindDirection -> FindDirection -> Bool
$c== :: FindDirection -> FindDirection -> Bool
Eq)

-- | Return the first position of the substring in @string*[*start:end]@
-- using the given direction. The return value is the index of the first
-- match; a value of 'Nothing' indicates that no match was found.
find
  :: Unicode -- ^ String
  -> Unicode -- ^ Substring
  -> Integer -- ^ Start
  -> Integer -- ^ End
  -> FindDirection
  -> IO (Maybe Integer)
find :: Unicode
-> Unicode
-> Integer
-> Integer
-> FindDirection
-> IO (Maybe Integer)
find str :: Unicode
str substr :: Unicode
substr start :: Integer
start end :: Integer
end dir :: FindDirection
dir =
  Unicode -> (Ptr () -> IO (Maybe Integer)) -> IO (Maybe Integer)
forall obj a b. Object obj => obj -> (Ptr a -> IO b) -> IO b
withObject Unicode
str ((Ptr () -> IO (Maybe Integer)) -> IO (Maybe Integer))
-> (Ptr () -> IO (Maybe Integer)) -> IO (Maybe Integer)
forall a b. (a -> b) -> a -> b
$ \strPtr :: Ptr ()
strPtr ->
    Unicode -> (Ptr () -> IO (Maybe Integer)) -> IO (Maybe Integer)
forall obj a b. Object obj => obj -> (Ptr a -> IO b) -> IO b
withObject Unicode
substr ((Ptr () -> IO (Maybe Integer)) -> IO (Maybe Integer))
-> (Ptr () -> IO (Maybe Integer)) -> IO (Maybe Integer)
forall a b. (a -> b) -> a -> b
$ \substrPtr :: Ptr ()
substrPtr ->
      let start' :: CLong
start' = Integer -> CLong
forall a. Num a => Integer -> a
fromInteger Integer
start
          end' :: CLong
end' = Integer -> CLong
forall a. Num a => Integer -> a
fromInteger Integer
end
          dir' :: CInt
dir' = case FindDirection
dir of Forwards -> 1
                             Backwards -> -1
      in do
        CLong
cRes <- Ptr () -> Ptr () -> CLong -> CLong -> CInt -> IO CLong
hscpython_PyUnicode_Find Ptr ()
strPtr Ptr ()
substrPtr CLong
start' CLong
end' CInt
dir'
        Bool -> IO ()
exceptionIf (Bool -> IO ()) -> Bool -> IO ()
forall a b. (a -> b) -> a -> b
$ CLong
cRes CLong -> CLong -> Bool
forall a. Eq a => a -> a -> Bool
== -2
        case CLong
cRes of
          -1 -> Maybe Integer -> IO (Maybe Integer)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Integer
forall a. Maybe a
Nothing
          x :: CLong
x | CLong
x CLong -> CLong -> Bool
forall a. Ord a => a -> a -> Bool
>= 0 -> Maybe Integer -> IO (Maybe Integer)
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe Integer -> IO (Maybe Integer))
-> (CLong -> Maybe Integer) -> CLong -> IO (Maybe Integer)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> Maybe Integer
forall a. a -> Maybe a
Just (Integer -> Maybe Integer)
-> (CLong -> Integer) -> CLong -> Maybe Integer
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CLong -> Integer
forall a. Integral a => a -> Integer
toInteger (CLong -> IO (Maybe Integer)) -> CLong -> IO (Maybe Integer)
forall a b. (a -> b) -> a -> b
$ CLong
x
          x :: CLong
x -> ErrorCall -> IO (Maybe Integer)
forall e a. Exception e => e -> IO a
throwIO (ErrorCall -> IO (Maybe Integer))
-> (String -> ErrorCall) -> String -> IO (Maybe Integer)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ErrorCall
ErrorCall (String -> IO (Maybe Integer)) -> String -> IO (Maybe Integer)
forall a b. (a -> b) -> a -> b
$ "Invalid return code: " String -> ShowS
forall a. [a] -> [a] -> [a]
++ CLong -> String
forall a. Show a => a -> String
show CLong
x

-- | Return the number of non-overlapping occurrences of the substring in
-- @string[start:end]@.
count
  :: Unicode -- ^ String
  -> Unicode -- ^ Substring
  -> Integer -- ^ Start
  -> Integer -- ^ End
  -> IO Integer
count :: Unicode -> Unicode -> Integer -> Integer -> IO Integer
count str :: Unicode
str substr :: Unicode
substr start :: Integer
start end :: Integer
end =
  Unicode -> (Ptr () -> IO Integer) -> IO Integer
forall obj a b. Object obj => obj -> (Ptr a -> IO b) -> IO b
withObject Unicode
str ((Ptr () -> IO Integer) -> IO Integer)
-> (Ptr () -> IO Integer) -> IO Integer
forall a b. (a -> b) -> a -> b
$ \str' :: Ptr ()
str' ->
  Unicode -> (Ptr () -> IO Integer) -> IO Integer
forall obj a b. Object obj => obj -> (Ptr a -> IO b) -> IO b
withObject Unicode
substr ((Ptr () -> IO Integer) -> IO Integer)
-> (Ptr () -> IO Integer) -> IO Integer
forall a b. (a -> b) -> a -> b
$ \substr' :: Ptr ()
substr' ->
  let start' :: CLong
start' = Integer -> CLong
forall a. Num a => Integer -> a
fromInteger Integer
start in
  let end' :: CLong
end' = Integer -> CLong
forall a. Num a => Integer -> a
fromInteger Integer
end in
  Ptr () -> Ptr () -> CLong -> CLong -> IO CLong
hscpython_PyUnicode_Count Ptr ()
str' Ptr ()
substr' CLong
start' CLong
end'
  IO CLong -> (CLong -> IO Integer) -> IO Integer
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= CLong -> IO Integer
forall a. Integral a => a -> IO Integer
checkIntReturn

-- | Replace occurrences of the substring with a given replacement. If the
-- maximum count is 'Nothing', replace all occurences.
replace
  :: Unicode -- ^ String
  -> Unicode -- ^ Substring
  -> Unicode -- ^ Replacement
  -> Maybe Integer -- ^ Maximum count
  -> IO Unicode
replace :: Unicode -> Unicode -> Unicode -> Maybe Integer -> IO Unicode
replace str :: Unicode
str substr :: Unicode
substr replstr :: Unicode
replstr maxcount :: Maybe Integer
maxcount =
  Unicode -> (Ptr () -> IO Unicode) -> IO Unicode
forall obj a b. Object obj => obj -> (Ptr a -> IO b) -> IO b
withObject Unicode
str ((Ptr () -> IO Unicode) -> IO Unicode)
-> (Ptr () -> IO Unicode) -> IO Unicode
forall a b. (a -> b) -> a -> b
$ \strPtr :: Ptr ()
strPtr ->
    Unicode -> (Ptr () -> IO Unicode) -> IO Unicode
forall obj a b. Object obj => obj -> (Ptr a -> IO b) -> IO b
withObject Unicode
substr ((Ptr () -> IO Unicode) -> IO Unicode)
-> (Ptr () -> IO Unicode) -> IO Unicode
forall a b. (a -> b) -> a -> b
$ \substrPtr :: Ptr ()
substrPtr ->
      Unicode -> (Ptr () -> IO Unicode) -> IO Unicode
forall obj a b. Object obj => obj -> (Ptr a -> IO b) -> IO b
withObject Unicode
replstr ((Ptr () -> IO Unicode) -> IO Unicode)
-> (Ptr () -> IO Unicode) -> IO Unicode
forall a b. (a -> b) -> a -> b
$ \replstrPtr :: Ptr ()
replstrPtr ->
        let maxcount' :: CLong
maxcount' = case Maybe Integer
maxcount of Nothing -> -1
                                         Just x :: Integer
x -> Integer -> CLong
forall a. Num a => Integer -> a
fromInteger Integer
x 
        in Ptr () -> Ptr () -> Ptr () -> CLong -> IO (Ptr ())
hscpython_PyUnicode_Replace Ptr ()
strPtr Ptr ()
substrPtr Ptr ()
replstrPtr CLong
maxcount'
  IO (Ptr ()) -> (Ptr () -> IO Unicode) -> IO Unicode
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Ptr () -> IO Unicode
forall obj a. Object obj => Ptr a -> IO obj
stealObject

-- | Return a new 'Unicode' object from the given format and args; this is
-- analogous to @format % args@.
format :: (Unicode) -> (Tuple) -> IO ((Unicode))
format :: Unicode -> Tuple -> IO Unicode
format a1 :: Unicode
a1 a2 :: Tuple
a2 =
  Unicode -> (Ptr () -> IO Unicode) -> IO Unicode
forall obj a b. Object obj => obj -> (Ptr a -> IO b) -> IO b
withObject Unicode
a1 ((Ptr () -> IO Unicode) -> IO Unicode)
-> (Ptr () -> IO Unicode) -> IO Unicode
forall a b. (a -> b) -> a -> b
$ \a1' :: Ptr ()
a1' -> 
  Tuple -> (Ptr () -> IO Unicode) -> IO Unicode
forall obj a b. Object obj => obj -> (Ptr a -> IO b) -> IO b
withObject Tuple
a2 ((Ptr () -> IO Unicode) -> IO Unicode)
-> (Ptr () -> IO Unicode) -> IO Unicode
forall a b. (a -> b) -> a -> b
$ \a2' :: Ptr ()
a2' -> 
  Ptr () -> Ptr () -> IO (Ptr ())
format'_ Ptr ()
a1' Ptr ()
a2' IO (Ptr ()) -> (Ptr () -> IO Unicode) -> IO Unicode
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \res :: Ptr ()
res ->
  Ptr () -> IO Unicode
forall obj a. Object obj => Ptr a -> IO obj
stealObject Ptr ()
res IO Unicode -> (Unicode -> IO Unicode) -> IO Unicode
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \res' :: Unicode
res' ->
  Unicode -> IO Unicode
forall (m :: * -> *) a. Monad m => a -> m a
return (Unicode
res')

{-# LINE 305 "lib/CPython/Types/Unicode.chs" #-}


-- | Check whether /element/ is contained in a string.
--
-- /element/ has to coerce to a one element string.
contains :: Object element => (Unicode) -> (element) -> IO ((Bool))
contains :: Unicode -> element -> IO Bool
contains a1 :: Unicode
a1 a2 :: element
a2 =
  Unicode -> (Ptr () -> IO Bool) -> IO Bool
forall obj a b. Object obj => obj -> (Ptr a -> IO b) -> IO b
withObject Unicode
a1 ((Ptr () -> IO Bool) -> IO Bool) -> (Ptr () -> IO Bool) -> IO Bool
forall a b. (a -> b) -> a -> b
$ \a1' :: Ptr ()
a1' -> 
  element -> (Ptr () -> IO Bool) -> IO Bool
forall obj a b. Object obj => obj -> (Ptr a -> IO b) -> IO b
withObject element
a2 ((Ptr () -> IO Bool) -> IO Bool) -> (Ptr () -> IO Bool) -> IO Bool
forall a b. (a -> b) -> a -> b
$ \a2' :: Ptr ()
a2' -> 
  Ptr () -> Ptr () -> IO CInt
contains'_ Ptr ()
a1' Ptr ()
a2' IO CInt -> (CInt -> IO Bool) -> IO Bool
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \res :: CInt
res ->
  CInt -> IO Bool
checkBoolReturn CInt
res IO Bool -> (Bool -> IO Bool) -> IO Bool
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \res' :: Bool
res' ->
  Bool -> IO Bool
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool
res')

{-# LINE 314 "lib/CPython/Types/Unicode.chs" #-}


foreign import ccall unsafe "CPython/Types/Unicode.chs.h hscpython_PyUnicode_Type"
  unicodeType'_ :: (IO (C2HSImp.Ptr ()))

foreign import ccall safe "CPython/Types/Unicode.chs.h hscpython_PyUnicode_FromUnicode"
  hscpython_PyUnicode_FromUnicode :: ((C2HSImp.Ptr C2HSImp.CInt) -> (C2HSImp.CLong -> (IO (C2HSImp.Ptr ()))))

foreign import ccall safe "CPython/Types/Unicode.chs.h hscpython_PyUnicode_AsUnicode"
  hscpython_PyUnicode_AsUnicode :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr C2HSImp.CInt)))

foreign import ccall safe "CPython/Types/Unicode.chs.h hscpython_PyUnicode_GetSize"
  hscpython_PyUnicode_GetSize :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CLong))

foreign import ccall safe "CPython/Types/Unicode.chs.h hscpython_PyUnicode_GetSize"
  length'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CLong))

foreign import ccall safe "CPython/Types/Unicode.chs.h hscpython_PyUnicode_FromEncodedObject"
  fromEncodedObject'_ :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr C2HSImp.CChar) -> ((C2HSImp.Ptr C2HSImp.CChar) -> (IO (C2HSImp.Ptr ())))))

foreign import ccall safe "CPython/Types/Unicode.chs.h hscpython_PyUnicode_AsEncodedString"
  encode'_ :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr C2HSImp.CChar) -> ((C2HSImp.Ptr C2HSImp.CChar) -> (IO (C2HSImp.Ptr ())))))

foreign import ccall safe "CPython/Types/Unicode.chs.h PyBytes_AsStringAndSize"
  pyBytesAsStringAndSize :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> ((C2HSImp.Ptr C2HSImp.CLong) -> (IO C2HSImp.CInt))))

foreign import ccall safe "CPython/Types/Unicode.chs.h hscpython_PyUnicode_Decode"
  hscpython_PyUnicode_Decode :: ((C2HSImp.Ptr C2HSImp.CChar) -> (C2HSImp.CLong -> ((C2HSImp.Ptr C2HSImp.CChar) -> ((C2HSImp.Ptr C2HSImp.CChar) -> (IO (C2HSImp.Ptr ()))))))

foreign import ccall safe "CPython/Types/Unicode.chs.h hscpython_PyUnicode_Concat"
  append'_ :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ()))))

foreign import ccall safe "CPython/Types/Unicode.chs.h hscpython_PyUnicode_Split"
  hscpython_PyUnicode_Split :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr ()) -> (C2HSImp.CLong -> (IO (C2HSImp.Ptr ())))))

foreign import ccall safe "CPython/Types/Unicode.chs.h hscpython_PyUnicode_Splitlines"
  splitLines'_ :: ((C2HSImp.Ptr ()) -> (C2HSImp.CInt -> (IO (C2HSImp.Ptr ()))))

foreign import ccall safe "CPython/Types/Unicode.chs.h hscpython_PyUnicode_Translate"
  translate'_ :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr C2HSImp.CChar) -> (IO (C2HSImp.Ptr ())))))

foreign import ccall safe "CPython/Types/Unicode.chs.h hscpython_PyUnicode_Join"
  join'_ :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ()))))

foreign import ccall safe "CPython/Types/Unicode.chs.h hscpython_PyUnicode_Tailmatch"
  hscpython_PyUnicode_Tailmatch :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr ()) -> (C2HSImp.CLong -> (C2HSImp.CLong -> (C2HSImp.CInt -> (IO C2HSImp.CInt))))))

foreign import ccall safe "CPython/Types/Unicode.chs.h hscpython_PyUnicode_Find"
  hscpython_PyUnicode_Find :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr ()) -> (C2HSImp.CLong -> (C2HSImp.CLong -> (C2HSImp.CInt -> (IO C2HSImp.CLong))))))

foreign import ccall safe "CPython/Types/Unicode.chs.h hscpython_PyUnicode_Count"
  hscpython_PyUnicode_Count :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr ()) -> (C2HSImp.CLong -> (C2HSImp.CLong -> (IO C2HSImp.CLong)))))

foreign import ccall safe "CPython/Types/Unicode.chs.h hscpython_PyUnicode_Replace"
  hscpython_PyUnicode_Replace :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr ()) -> (C2HSImp.CLong -> (IO (C2HSImp.Ptr ()))))))

foreign import ccall safe "CPython/Types/Unicode.chs.h hscpython_PyUnicode_Format"
  format'_ :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ()))))

foreign import ccall safe "CPython/Types/Unicode.chs.h hscpython_PyUnicode_Contains"
  contains'_ :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr ()) -> (IO C2HSImp.CInt)))