From 07115d43d007f52d9b5a64d2c52b64443d969465 Mon Sep 17 00:00:00 2001 From: qarkai Date: Fri, 24 Mar 2017 13:01:08 +0300 Subject: [PATCH] Use g_strcmp0() for code simplification --HG-- branch : string-comparison-r2 --- libpurple/protocols/jabber/google/gmail.c | 3 +-- libpurple/protocols/jabber/jabber.c | 24 +++++++++--------------- pidgin/gtkconv.c | 19 +++++++++---------- 3 files changed, 19 insertions(+), 27 deletions(-) diff --git a/libpurple/protocols/jabber/google/gmail.c b/libpurple/protocols/jabber/google/gmail.c index 3d3f5bf971..78a4928e62 100644 --- a/libpurple/protocols/jabber/google/gmail.c +++ b/libpurple/protocols/jabber/google/gmail.c @@ -116,8 +116,7 @@ jabber_gmail_parse(JabberStream *js, const char *from, urls[i] = url; tid = xmlnode_get_attrib(message, "tid"); - if (tid && - (js->gmail_last_tid == NULL || strcmp(tid, js->gmail_last_tid) > 0)) { + if (g_strcmp0(tid, js->gmail_last_tid) > 0) { g_free(js->gmail_last_tid); js->gmail_last_tid = g_strdup(tid); } diff --git a/libpurple/protocols/jabber/jabber.c b/libpurple/protocols/jabber/jabber.c index 9d9bdc4f16..93f7dd673f 100644 --- a/libpurple/protocols/jabber/jabber.c +++ b/libpurple/protocols/jabber/jabber.c @@ -2023,23 +2023,17 @@ jabber_identity_compare(gconstpointer a, gconstpointer b) ac = a; bc = b; - if ((cat_cmp = strcmp(ac->category, bc->category)) == 0) { - if ((typ_cmp = strcmp(ac->type, bc->type)) == 0) { - if (!ac->lang && !bc->lang) { - return 0; - } else if (ac->lang && !bc->lang) { - return 1; - } else if (!ac->lang && bc->lang) { - return -1; - } else { - return strcmp(ac->lang, bc->lang); - } - } else { - return typ_cmp; - } - } else { + cat_cmp = strcmp(ac->category, bc->category); + if (cat_cmp != 0) { return cat_cmp; } + + typ_cmp = strcmp(ac->type, bc->type); + if (typ_cmp != 0) { + return typ_cmp; + } + + return g_strcmp0(ac->lang, bc->lang); } void jabber_add_identity(const gchar *category, const gchar *type, diff --git a/pidgin/gtkconv.c b/pidgin/gtkconv.c index fa2db3f3c3..b98c6375ef 100644 --- a/pidgin/gtkconv.c +++ b/pidgin/gtkconv.c @@ -4370,16 +4370,15 @@ sort_chat_users(GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, gpointer us f2 &= PURPLE_CBFLAGS_VOICE | PURPLE_CBFLAGS_HALFOP | PURPLE_CBFLAGS_OP | PURPLE_CBFLAGS_FOUNDER; - if (user1 == NULL || user2 == NULL) { - if (!(user1 == NULL && user2 == NULL)) - ret = (user1 == NULL) ? -1: 1; - } else if (f1 != f2) { - /* sort more important users first */ - ret = (f1 > f2) ? -1 : 1; - } else if (buddy1 != buddy2) { - ret = (buddy1 > buddy2) ? -1 : 1; - } else { - ret = strcmp(user1, user2); + ret = g_strcmp0(user1, user2); + + if (user1 != NULL && user2 != NULL) { + if (f1 != f2) { + /* sort more important users first */ + ret = (f1 > f2) ? -1 : 1; + } else if (buddy1 != buddy2) { + ret = (buddy1 > buddy2) ? -1 : 1; + } } g_free(user1); -- 2.11.4.GIT