Copyright | Will Thompson and Iñaki García Etxebarria |
---|---|
License | LGPL-2.1 |
Maintainer | Iñaki García Etxebarria |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
GI.GLib.Structs.String
Contents
Description
A GString
is an object that handles the memory management of a C string.
The emphasis of GString
is on text, typically UTF-8. Crucially, the "str" member
of a GString
is guaranteed to have a trailing nul character, and it is therefore
always safe to call functions such as strchr()
or strdup()
on it.
However, a GString
can also hold arbitrary binary data, because it has a "len" member,
which includes any possible embedded nul characters in the data. Conceptually then,
GString
is like a GByteArray
with the addition of many convenience methods for
text, and a guaranteed nul terminator.
Synopsis
- newtype String = String (ManagedPtr String)
- newZeroString :: MonadIO m => m String
- stringAppend :: (HasCallStack, MonadIO m) => String -> Text -> m String
- stringAppendC :: (HasCallStack, MonadIO m) => String -> Int8 -> m String
- stringAppendLen :: (HasCallStack, MonadIO m) => String -> Text -> Int64 -> m String
- stringAppendUnichar :: (HasCallStack, MonadIO m) => String -> Char -> m String
- stringAppendUriEscaped :: (HasCallStack, MonadIO m) => String -> Text -> Text -> Bool -> m String
- stringAsciiDown :: (HasCallStack, MonadIO m) => String -> m String
- stringAsciiUp :: (HasCallStack, MonadIO m) => String -> m String
- stringAssign :: (HasCallStack, MonadIO m) => String -> Text -> m String
- stringDown :: (HasCallStack, MonadIO m) => String -> m String
- stringEqual :: (HasCallStack, MonadIO m) => String -> String -> m Bool
- stringErase :: (HasCallStack, MonadIO m) => String -> Int64 -> Int64 -> m String
- stringFree :: (HasCallStack, MonadIO m) => String -> Bool -> m (Maybe Text)
- stringFreeAndSteal :: (HasCallStack, MonadIO m) => String -> m Text
- stringFreeToBytes :: (HasCallStack, MonadIO m) => String -> m Bytes
- stringHash :: (HasCallStack, MonadIO m) => String -> m Word32
- stringInsert :: (HasCallStack, MonadIO m) => String -> Int64 -> Text -> m String
- stringInsertC :: (HasCallStack, MonadIO m) => String -> Int64 -> Int8 -> m String
- stringInsertLen :: (HasCallStack, MonadIO m) => String -> Int64 -> Text -> Int64 -> m String
- stringInsertUnichar :: (HasCallStack, MonadIO m) => String -> Int64 -> Char -> m String
- stringNew :: (HasCallStack, MonadIO m) => Maybe Text -> m String
- stringNewLen :: (HasCallStack, MonadIO m) => Text -> Int64 -> m String
- stringNewTake :: (HasCallStack, MonadIO m) => Maybe Text -> m String
- stringOverwrite :: (HasCallStack, MonadIO m) => String -> CSize -> Text -> m String
- stringOverwriteLen :: (HasCallStack, MonadIO m) => String -> CSize -> Text -> Int64 -> m String
- stringPrepend :: (HasCallStack, MonadIO m) => String -> Text -> m String
- stringPrependC :: (HasCallStack, MonadIO m) => String -> Int8 -> m String
- stringPrependLen :: (HasCallStack, MonadIO m) => String -> Text -> Int64 -> m String
- stringPrependUnichar :: (HasCallStack, MonadIO m) => String -> Char -> m String
- stringReplace :: (HasCallStack, MonadIO m) => String -> Text -> Text -> Word32 -> m Word32
- stringSetSize :: (HasCallStack, MonadIO m) => String -> CSize -> m String
- stringSizedNew :: (HasCallStack, MonadIO m) => CSize -> m String
- stringTruncate :: (HasCallStack, MonadIO m) => String -> CSize -> m String
- stringUp :: (HasCallStack, MonadIO m) => String -> m String
- getStringAllocatedLen :: MonadIO m => String -> m CSize
- setStringAllocatedLen :: MonadIO m => String -> CSize -> m ()
- getStringLen :: MonadIO m => String -> m CSize
- setStringLen :: MonadIO m => String -> CSize -> m ()
- clearStringStr :: MonadIO m => String -> m ()
- getStringStr :: MonadIO m => String -> m (Maybe Text)
- setStringStr :: MonadIO m => String -> CString -> m ()
Exported types
Memory-managed wrapper type.
Instances
Eq String Source # | |
GBoxed String Source # | |
Defined in GI.GLib.Structs.String | |
ManagedPtrNewtype String Source # | |
Defined in GI.GLib.Structs.String Methods toManagedPtr :: String -> ManagedPtr String | |
TypedObject String Source # | |
Defined in GI.GLib.Structs.String | |
HasParentTypes String Source # | |
Defined in GI.GLib.Structs.String | |
tag ~ 'AttrSet => Constructible String tag Source # | |
IsGValue (Maybe String) Source # | Convert |
Defined in GI.GLib.Structs.String Methods gvalueGType_ :: IO GType gvalueSet_ :: Ptr GValue -> Maybe String -> IO () gvalueGet_ :: Ptr GValue -> IO (Maybe String) | |
type ParentTypes String Source # | |
Defined in GI.GLib.Structs.String |
Methods
Click to display all available methods, including inherited ones
Methods
append, appendC, appendLen, appendUnichar, appendUriEscaped, asciiDown, asciiUp, assign, down, equal, erase, free, freeAndSteal, freeToBytes, hash, insert, insertC, insertLen, insertUnichar, overwrite, overwriteLen, prepend, prependC, prependLen, prependUnichar, replace, truncate, up.
Getters
None.
Setters
append
Arguments
:: (HasCallStack, MonadIO m) | |
=> String |
|
-> Text |
|
-> m String | Returns: |
Adds a string onto the end of a String
, expanding
it if necessary.
appendC
Arguments
:: (HasCallStack, MonadIO m) | |
=> String |
|
-> Int8 |
|
-> m String | Returns: |
Adds a byte onto the end of a String
, expanding
it if necessary.
appendLen
Arguments
:: (HasCallStack, MonadIO m) | |
=> String |
|
-> Text |
|
-> Int64 |
|
-> m String | Returns: |
Appends len
bytes of val
to string
.
If len
is positive, val
may contain embedded nuls and need
not be nul-terminated. It is the caller's responsibility to
ensure that val
has at least len
addressable bytes.
If len
is negative, val
must be nul-terminated and len
is considered to request the entire string length. This
makes stringAppendLen
equivalent to stringAppend
.
appendUnichar
Arguments
:: (HasCallStack, MonadIO m) | |
=> String |
|
-> Char |
|
-> m String | Returns: |
Converts a Unicode character into UTF-8, and appends it to the string.
appendUriEscaped
stringAppendUriEscaped Source #
Arguments
:: (HasCallStack, MonadIO m) | |
=> String |
|
-> Text |
|
-> Text |
|
-> Bool |
|
-> m String | Returns: |
Appends unescaped
to string
, escaping any characters that
are reserved in URIs using URI-style escape sequences.
Since: 2.16
asciiDown
Arguments
:: (HasCallStack, MonadIO m) | |
=> String |
|
-> m String | Returns: passed-in |
Converts all uppercase ASCII letters to lowercase ASCII letters.
asciiUp
Arguments
:: (HasCallStack, MonadIO m) | |
=> String |
|
-> m String | Returns: passed-in |
Converts all lowercase ASCII letters to uppercase ASCII letters.
assign
Arguments
:: (HasCallStack, MonadIO m) | |
=> String |
|
-> Text |
|
-> m String | Returns: |
Copies the bytes from a string into a String
,
destroying any previous contents. It is rather like
the standard strcpy()
function, except that you do not
have to worry about having enough space to copy the string.
down
Deprecated: (Since version 2.2)This function uses the locale-specific tolower()
function, which is almost never the right thing. Use stringAsciiDown
or utf8Strdown
instead.
Converts a String
to lowercase.
equal
erase
free
freeAndSteal
Arguments
:: (HasCallStack, MonadIO m) | |
=> String |
|
-> m Text | Returns: the character data of |
freeToBytes
Arguments
:: (HasCallStack, MonadIO m) | |
=> String |
|
-> m Bytes | Returns: A newly allocated |
Transfers ownership of the contents of string
to a newly allocated
Bytes
. The String
structure itself is deallocated, and it is
therefore invalid to use string
after invoking this function.
Note that while String
ensures that its buffer always has a
trailing nul character (not reflected in its "len"), the returned
Bytes
does not include this extra nul; i.e. it has length exactly
equal to the "len" member.
Since: 2.34
hash
Arguments
:: (HasCallStack, MonadIO m) | |
=> String |
|
-> m Word32 | Returns: hash code for |
Creates a hash code for str
; for use with HashTable
.
insert
Arguments
:: (HasCallStack, MonadIO m) | |
=> String |
|
-> Int64 |
|
-> Text |
|
-> m String | Returns: |
Inserts a copy of a string into a String
,
expanding it if necessary.
insertC
Arguments
:: (HasCallStack, MonadIO m) | |
=> String |
|
-> Int64 |
|
-> Int8 |
|
-> m String | Returns: |
Inserts a byte into a String
, expanding it if necessary.
insertLen
Arguments
:: (HasCallStack, MonadIO m) | |
=> String |
|
-> Int64 |
|
-> Text |
|
-> Int64 |
|
-> m String | Returns: |
Inserts len
bytes of val
into string
at pos
.
If len
is positive, val
may contain embedded nuls and need
not be nul-terminated. It is the caller's responsibility to
ensure that val
has at least len
addressable bytes.
If len
is negative, val
must be nul-terminated and len
is considered to request the entire string length.
If pos
is -1, bytes are inserted at the end of the string.
insertUnichar
Arguments
:: (HasCallStack, MonadIO m) | |
=> String |
|
-> Int64 |
|
-> Char |
|
-> m String | Returns: |
Converts a Unicode character into UTF-8, and insert it into the string at the given position.
new
Arguments
:: (HasCallStack, MonadIO m) | |
=> Maybe Text |
|
-> m String | Returns: the new |
Creates a new String
, initialized with the given string.
newLen
Arguments
:: (HasCallStack, MonadIO m) | |
=> Text |
|
-> Int64 |
|
-> m String | Returns: a new |
Creates a new String
with len
bytes of the init
buffer.
Because a length is provided, init
need not be nul-terminated,
and can contain embedded nul bytes.
Since this function does not stop at nul bytes, it is the caller's
responsibility to ensure that init
has at least len
addressable
bytes.
newTake
overwrite
Arguments
:: (HasCallStack, MonadIO m) | |
=> String |
|
-> CSize |
|
-> Text |
|
-> m String | Returns: |
Overwrites part of a string, lengthening it if necessary.
Since: 2.14
overwriteLen
Arguments
:: (HasCallStack, MonadIO m) | |
=> String |
|
-> CSize |
|
-> Text |
|
-> Int64 |
|
-> m String | Returns: |
Overwrites part of a string, lengthening it if necessary. This function will work with embedded nuls.
Since: 2.14
prepend
Arguments
:: (HasCallStack, MonadIO m) | |
=> String |
|
-> Text |
|
-> m String | Returns: |
Adds a string on to the start of a String
,
expanding it if necessary.
prependC
Arguments
:: (HasCallStack, MonadIO m) | |
=> String |
|
-> Int8 |
|
-> m String | Returns: |
Adds a byte onto the start of a String
,
expanding it if necessary.
prependLen
Arguments
:: (HasCallStack, MonadIO m) | |
=> String |
|
-> Text |
|
-> Int64 |
|
-> m String | Returns: |
Prepends len
bytes of val
to string
.
If len
is positive, val
may contain embedded nuls and need
not be nul-terminated. It is the caller's responsibility to
ensure that val
has at least len
addressable bytes.
If len
is negative, val
must be nul-terminated and len
is considered to request the entire string length. This
makes stringPrependLen
equivalent to stringPrepend
.
prependUnichar
Arguments
:: (HasCallStack, MonadIO m) | |
=> String |
|
-> Char |
|
-> m String | Returns: |
Converts a Unicode character into UTF-8, and prepends it to the string.
replace
Arguments
:: (HasCallStack, MonadIO m) | |
=> String |
|
-> Text |
|
-> Text |
|
-> Word32 |
|
-> m Word32 | Returns: the number of find and replace operations performed. |
Replaces the string find
with the string replace
in a String
up to
limit
times. If the number of instances of find
in the String
is
less than limit
, all instances are replaced. If limit
is 0
,
all instances of find
are replaced.
If find
is the empty string, since versions 2.69.1 and 2.68.4 the
replacement will be inserted no more than once per possible position
(beginning of string, end of string and between characters). This did
not work correctly in earlier versions.
Since: 2.68
setSize
Arguments
:: (HasCallStack, MonadIO m) | |
=> String |
|
-> CSize |
|
-> m String | Returns: |
Sets the length of a String
. If the length is less than
the current length, the string will be truncated. If the
length is greater than the current length, the contents
of the newly added area are undefined. (However, as
always, string->str[string->len] will be a nul byte.)
sizedNew
Arguments
:: (HasCallStack, MonadIO m) | |
=> CSize |
|
-> m String | Returns: the new |
Creates a new String
, with enough space for dflSize
bytes. This is useful if you are going to add a lot of
text to the string and don't want it to be reallocated
too often.
truncate
Arguments
:: (HasCallStack, MonadIO m) | |
=> String |
|
-> CSize |
|
-> m String | Returns: |
Cuts off the end of the GString, leaving the first len
bytes.
up
Arguments
:: (HasCallStack, MonadIO m) | |
=> String |
|
-> m String | Returns: |
Deprecated: (Since version 2.2)This function uses the locale-specific toupper()
function, which is almost never the right thing. Use stringAsciiUp
or utf8Strup
instead.
Converts a String
to uppercase.
Properties
allocatedLen
the number of bytes that can be stored in the
string before it needs to be reallocated. May be larger than len
.
getStringAllocatedLen :: MonadIO m => String -> m CSize Source #
Get the value of the “allocated_len
” field.
When overloading is enabled, this is equivalent to
get
string #allocatedLen
setStringAllocatedLen :: MonadIO m => String -> CSize -> m () Source #
Set the value of the “allocated_len
” field.
When overloading is enabled, this is equivalent to
set
string [ #allocatedLen:=
value ]
len
contains the length of the string, not including the terminating nul byte.
getStringLen :: MonadIO m => String -> m CSize Source #
Get the value of the “len
” field.
When overloading is enabled, this is equivalent to
get
string #len
setStringLen :: MonadIO m => String -> CSize -> m () Source #
Set the value of the “len
” field.
When overloading is enabled, this is equivalent to
set
string [ #len:=
value ]
str
points to the character data. It may move as text is added.
The str
field is null-terminated and so
can be used as an ordinary C string.
clearStringStr :: MonadIO m => String -> m () Source #
Set the value of the “str
” field to Nothing
.
When overloading is enabled, this is equivalent to
clear
#str
getStringStr :: MonadIO m => String -> m (Maybe Text) Source #
Get the value of the “str
” field.
When overloading is enabled, this is equivalent to
get
string #str
setStringStr :: MonadIO m => String -> CString -> m () Source #
Set the value of the “str
” field.
When overloading is enabled, this is equivalent to
set
string [ #str:=
value ]