aboutsummaryrefslogtreecommitdiffstats
path: root/libempathy/empathy-utils.c
diff options
context:
space:
mode:
authorXavier Claessens <xclaesse@gmail.com>2007-09-27 04:16:00 +0800
committerXavier Claessens <xclaesse@src.gnome.org>2007-09-27 04:16:00 +0800
commit8c22592a9a13ac09f8e7c0357fafcfd163910a4c (patch)
tree59b0436d072c06b8c423038064dc79728f619614 /libempathy/empathy-utils.c
parentbf1079017d1d5d78147619a6377ef00e62010bf4 (diff)
downloadgsoc2013-empathy-8c22592a9a13ac09f8e7c0357fafcfd163910a4c.tar
gsoc2013-empathy-8c22592a9a13ac09f8e7c0357fafcfd163910a4c.tar.gz
gsoc2013-empathy-8c22592a9a13ac09f8e7c0357fafcfd163910a4c.tar.bz2
gsoc2013-empathy-8c22592a9a13ac09f8e7c0357fafcfd163910a4c.tar.lz
gsoc2013-empathy-8c22592a9a13ac09f8e7c0357fafcfd163910a4c.tar.xz
gsoc2013-empathy-8c22592a9a13ac09f8e7c0357fafcfd163910a4c.tar.zst
gsoc2013-empathy-8c22592a9a13ac09f8e7c0357fafcfd163910a4c.zip
Cache avatars and RequestAvatars only when needed.
2007-09-26 Xavier Claessens <xclaesse@gmail.com> * libempathy/empathy-utils.c: * libempathy/empathy-utils.h: * libempathy/empathy-avatar.c: * libempathy/empathy-avatar.h: * libempathy/empathy-contact-factory.c: Cache avatars and RequestAvatars only when needed. svn path=/trunk/; revision=320
Diffstat (limited to 'libempathy/empathy-utils.c')
-rw-r--r--libempathy/empathy-utils.c90
1 files changed, 76 insertions, 14 deletions
diff --git a/libempathy/empathy-utils.c b/libempathy/empathy-utils.c
index a1404f403..06442fe05 100644
--- a/libempathy/empathy-utils.c
+++ b/libempathy/empathy-utils.c
@@ -198,6 +198,82 @@ empathy_strncasecmp (const gchar *s1,
return ret_val;
}
+/* Stolen from telepathy-glib */
+gboolean
+empathy_strdiff (const gchar *left, const gchar *right)
+{
+ if ((NULL == left) != (NULL == right))
+ return TRUE;
+
+ else if (left == right)
+ return FALSE;
+
+ else
+ return (0 != strcmp (left, right));
+}
+
+/* Stolen from telepathy-glib */
+static inline gboolean
+_esc_ident_bad (gchar c, gboolean is_first)
+{
+ return ((c < 'a' || c > 'z') &&
+ (c < 'A' || c > 'Z') &&
+ (c < '0' || c > '9' || is_first));
+}
+
+/* Stolen from telepathy-glib */
+gchar *
+empathy_escape_as_identifier (const gchar *name)
+{
+ gboolean bad = FALSE;
+ size_t len = 0;
+ GString *op;
+ const gchar *ptr, *first_ok;
+
+ g_return_val_if_fail (name != NULL, NULL);
+
+ for (ptr = name; *ptr; ptr++)
+ {
+ if (_esc_ident_bad (*ptr, ptr == name))
+ {
+ bad = TRUE;
+ len += 3;
+ }
+ else
+ len++;
+ }
+
+ /* fast path if it's clean */
+ if (!bad)
+ return g_strdup (name);
+
+ /* If strictly less than ptr, first_ok is the first uncopied safe character.
+ */
+ first_ok = name;
+ op = g_string_sized_new (len);
+ for (ptr = name; *ptr; ptr++)
+ {
+ if (_esc_ident_bad (*ptr, ptr == name))
+ {
+ /* copy preceding safe characters if any */
+ if (first_ok < ptr)
+ {
+ g_string_append_len (op, first_ok, ptr - first_ok);
+ }
+ /* escape the unsafe character */
+ g_string_append_printf (op, "_%02x", (unsigned char)(*ptr));
+ /* restart after it */
+ first_ok = ptr + 1;
+ }
+ }
+ /* copy trailing safe characters if any */
+ if (first_ok < ptr)
+ {
+ g_string_append_len (op, first_ok, ptr - first_ok);
+ }
+ return g_string_free (op, FALSE);
+}
+
gboolean
empathy_xml_validate (xmlDoc *doc,
const gchar *dtd_filename)
@@ -385,17 +461,3 @@ empathy_inspect_handle (McAccount *account,
return name;
}
-/* Stolen from telepathy-glib */
-gboolean
-empathy_strdiff (const gchar *left, const gchar *right)
-{
- if ((NULL == left) != (NULL == right))
- return TRUE;
-
- else if (left == right)
- return FALSE;
-
- else
- return (0 != strcmp (left, right));
-}
-