/soc/2013/ankitkv/gobjectification: 1adfec3dcff6: Added purple_v...
Ankit Vani
a at nevitus.org
Sun Jan 19 16:40:48 EST 2014
Changeset: 1adfec3dcff68df07e968d800d036a9b6348c372
Author: Ankit Vani <a at nevitus.org>
Date: 2014-01-20 03:02 +0530
Branch: soc.2013.gobjectification.plugins
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/1adfec3dcff6
Description:
Added purple_version_strcmp.
Will use this for comparing "version" attribute of our XMLs in prefs migration.
diffstat:
libpurple/util.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
libpurple/util.h | 14 ++++++++++++++
2 files changed, 60 insertions(+), 0 deletions(-)
diffs (80 lines):
diff --git a/libpurple/util.c b/libpurple/util.c
--- a/libpurple/util.c
+++ b/libpurple/util.c
@@ -3811,6 +3811,52 @@ purple_utf16_wipe(gunichar2 *str)
g_free(str);
}
+gint
+purple_version_strcmp(const gchar *v1, const gchar *v2)
+{
+ gchar **version[2];
+ gint major[2] = {0}, minor[2] = {0}, micro[2] = {0};
+ gint i, t;
+
+ if (!v1 && v2)
+ return -1;
+ else if (v1 && !v2)
+ return 1;
+ else if (!v1 && !v2)
+ return 0;
+
+ version[0] = g_strsplit(v1, ".", 3);
+ version[1] = g_strsplit(v2, ".", 3);
+
+ for (i = 0; i < 2; ++i) {
+ major[i] = atoi(version[i][0]);
+
+ if (version[i][1]) {
+ minor[i] = atoi(version[i][1]);
+
+ if (version[i][2])
+ micro[i] = atoi(version[i][2]);
+ }
+
+ g_strfreev(version[i]);
+ }
+
+ t = major[0] - major[1];
+ if (t != 0)
+ return t < 0 ? -1 : 1;
+
+ t = minor[0] - minor[1];
+ if (t != 0)
+ return t < 0 ? -1 : 1;
+
+ t = micro[0] - micro[1];
+
+ if (t != 0)
+ return t < 0 ? -1 : 1;
+ else
+ return 0;
+}
+
/**************************************************************************
* URI/URL Functions
**************************************************************************/
diff --git a/libpurple/util.h b/libpurple/util.h
--- a/libpurple/util.h
+++ b/libpurple/util.h
@@ -1178,6 +1178,20 @@ void purple_str_wipe(gchar *str);
*/
void purple_utf16_wipe(gunichar2 *str);
+/**
+ * Compares two strings representing versions in the typical
+ * MAJOR.MINOR.MICRO format. Any characters after the micro version are
+ * ignored.
+ *
+ * @param v1 The first version to compare
+ * @param v2 The second version to compare
+ *
+ * @return -1 if @v1 is less than @v2.
+ * 0 if @v1 is equal to @v2.
+ * 1 if @v1 is greater than @v2.
+ */
+gint purple_version_strcmp(const gchar *v1, const gchar *v2);
+
/*@}*/
More information about the Commits
mailing list