Function
GLibset_str
since: 2.76
Declaration [src]
static inline gboolean
g_set_str (
char** str_pointer,
const char* new_str
)
Description [src]
Updates a pointer to a string to a copy of new_str
and returns whether the
string was changed.
If new_str
matches the previous string, this function is a no-op. If
new_str
is different, a copy of it will be assigned to str_pointer
and
the previous string pointed to by str_pointer
will be freed with
g_free()
.
str_pointer
must not be NULL
, but can point to a NULL
value.
One convenient usage of this function is in implementing property settings:
void
foo_set_bar (Foo *foo,
const char *new_bar)
{
g_return_if_fail (IS_FOO (foo));
if (g_set_str (&foo->bar, new_bar))
g_object_notify (foo, "bar");
}
Available since: 2.76
This function is not directly available to language bindings.
Parameters
str_pointer
-
Type:
char**
A pointer to either a string or
NULL
.The argument will be modified by the function. The caller of the function takes ownership of the returned data, and is responsible for freeing it. The value is a NUL terminated UTF-8 string. new_str
-
Type:
const char*
A string to assign to
str_pointer
.The argument can be NULL
.The data is owned by the caller of the function. The value is a NUL terminated UTF-8 string.