Copyright | (c) The FFI task force 2001 |
---|---|
License | BSD-style (see the file libraries/base/LICENSE) |
Maintainer | ffi@haskell.org |
Stability | provisional |
Portability | portable |
Safe Haskell | Trustworthy |
Language | Haskell2010 |
Foreign.C.String
Description
Utilities for primitive marshalling of C strings.
The marshalling converts each Haskell character, representing a Unicode code point, to one or more bytes in a manner that, by default, is determined by the current locale. As a consequence, no guarantees can be made about the relative length of a Haskell string and its corresponding C string, and therefore all the marshalling routines include memory allocation. The translation between Unicode and the encoding of the current locale may be lossy.
A C string is a reference to an array of C characters terminated by NUL.
typeCStringLen = (PtrCChar,Int)Source#
A string with explicit length information in bytes instead of a terminating NUL (allowing NUL characters in the middle of the string).
These functions are different from theirCAString
counterparts in that they will use an encoding determined by the current locale, rather than always assuming ASCII.
peekCStringLen ::CStringLen ->IOStringSource#
Marshal a C string with explicit length into a Haskell string.
newCString ::String ->IOCStringSource#
Marshal a Haskell string into a NUL terminated C string.
free
orfinalizerFree
.newCStringLen ::String ->IOCStringLenSource#
Marshal a Haskell string into a C string (ie, character array) with explicit length information.
free
orfinalizerFree
.withCString ::String -> (CString ->IO a) ->IO aSource#
Marshal a Haskell string into a NUL terminated C string using temporary storage.
withCStringLen ::String -> (CStringLen ->IO a) ->IO aSource#
Marshal a Haskell string into a C string (ie, character array) in temporary storage, with explicit length information.
These variants of the above functions are for use with C libraries that are ignorant of Unicode. These functions should be used with care, as a loss of information can occur.
castCharToCChar ::Char ->CCharSource#
Convert a Haskell character to a C character. This function is only safe on the first 256 characters.
castCCharToChar ::CChar ->CharSource#
Convert a C byte, representing a Latin-1 character, to the corresponding Haskell character.
castCharToCUChar ::Char ->CUCharSource#
Convert a Haskell character to a Cunsigned char
. This function is only safe on the first 256 characters.
castCUCharToChar ::CUChar ->CharSource#
Convert a Cunsigned char
, representing a Latin-1 character, to the corresponding Haskell character.
castCharToCSChar ::Char ->CSCharSource#
Convert a Haskell character to a Csigned char
. This function is only safe on the first 256 characters.
castCSCharToChar ::CSChar ->CharSource#
Convert a Csigned char
, representing a Latin-1 character, to the corresponding Haskell character.
peekCAStringLen ::CStringLen ->IOStringSource#
Marshal a C string with explicit length into a Haskell string.
newCAString ::String ->IOCStringSource#
Marshal a Haskell string into a NUL terminated C string.
free
orfinalizerFree
.newCAStringLen ::String ->IOCStringLenSource#
Marshal a Haskell string into a C string (ie, character array) with explicit length information.
free
orfinalizerFree
.withCAString ::String -> (CString ->IO a) ->IO aSource#
Marshal a Haskell string into a NUL terminated C string using temporary storage.
withCAStringLen ::String -> (CStringLen ->IO a) ->IO aSource#
Marshal a Haskell string into a C string (ie, character array) in temporary storage, with explicit length information.
These variants of the above functions are for use with C libraries that encode Unicode using the Cwchar_t
type in a system-dependent way. The only encodings supported are
201706L
), ortypeCWString =PtrCWcharSource#
A C wide string is a reference to an array of C wide characters terminated by NUL.
typeCWStringLen = (PtrCWchar,Int)Source#
A wide character string with explicit length information inCWchar
s instead of a terminating NUL (allowing NUL characters in the middle of the string).
peekCWString ::CWString ->IOStringSource#
Marshal a NUL terminated C wide string into a Haskell string.
peekCWStringLen ::CWStringLen ->IOStringSource#
Marshal a C wide string with explicit length into a Haskell string.
newCWString ::String ->IOCWStringSource#
Marshal a Haskell string into a NUL terminated C wide string.
free
orfinalizerFree
.newCWStringLen ::String ->IOCWStringLenSource#
Marshal a Haskell string into a C wide string (ie, wide character array) with explicit length information.
free
orfinalizerFree
.withCWString ::String -> (CWString ->IO a) ->IO aSource#
Marshal a Haskell string into a NUL terminated C wide string using temporary storage.
withCWStringLen ::String -> (CWStringLen ->IO a) ->IO aSource#
Marshal a Haskell string into a C wide string (i.e. wide character array) in temporary storage, with explicit length information.
Produced byHaddock version 2.24.0