Utilities

Utilities — Non-Telepathy utility functions

Synopsis


#include <telepathy-glib/util.h>


gboolean            tp_g_ptr_array_contains             (GPtrArray *haystack,
                                                         gpointer needle);
void                tp_g_value_slice_free               (GValue *value);
gboolean            tp_strdiff                          (const gchar *left,
                                                         const gchar *right);
gpointer            tp_mixin_offset_cast                (gpointer instance,
                                                         guint offset);
gchar*              tp_escape_as_identifier             (const gchar *name);

Description

Some utility functions used in telepathy-glib which could have been in GLib, but aren't.

Details

tp_g_ptr_array_contains ()

gboolean            tp_g_ptr_array_contains             (GPtrArray *haystack,
                                                         gpointer needle);

haystack : The pointer array to be searched
needle : The pointer to look for
Returns : TRUE if needle is one of the elements of haystack

tp_g_value_slice_free ()

void                tp_g_value_slice_free               (GValue *value);

Unset and free a slice-allocated GValue.

value : A GValue which was allocated with the g_slice API

tp_strdiff ()

gboolean            tp_strdiff                          (const gchar *left,
                                                         const gchar *right);

Return TRUE if the given strings are different. Unlike strcmp this function will handle null pointers, treating them as distinct from any string.

left : The first string to compare (may be NULL)
right : The second string to compare (may be NULL)
Returns : FALSE if left and right are both NULL, or if neither is NULL and both have the same contents; TRUE otherwise

tp_mixin_offset_cast ()

gpointer            tp_mixin_offset_cast                (gpointer instance,
                                                         guint offset);

Extend a pointer by an offset, provided the offset is not 0. This is used to cast from an object instance to one of the telepathy-glib mixin classes.

instance : A pointer to a structure
offset : The offset of a structure member in bytes, which must not be 0
Returns : a pointer offset bytes beyond instance

tp_escape_as_identifier ()

gchar*              tp_escape_as_identifier             (const gchar *name);

Escape an arbitrary string so it follows the rules for a C identifier, and hence an object path component, interface element component, bus name component or member name in D-Bus.

Unlike g_strcanon this is a reversible encoding, so it preserves distinctness.

The escaping consists of replacing all non-alphanumerics, and the first character if it's a digit, with an underscore and two lower-case hex digits:

"0123abc_xyz\x01\xff" -> _30123abc_5fxyz_01_ff

i.e. similar to URI encoding, but with _ taking the role of %, and a smaller allowed set.

name : The string to be escaped
Returns : the escaped string, which must be freed by the caller with g_free