Mercurial > pidgin
comparison libpurple/protocols/qq/utils.c @ 24925:1300601041ac
g_strsplit_set is new in glib 2.4
g_strv_length is new in glib 2.6
This is one reason I didn't get around to making RPMs for 2.5.3, I don't
(yet) know if there are other glib version dependencies to deal with...
author | Stu Tomlinson <stu@nosnilmot.com> |
---|---|
date | Wed, 07 Jan 2009 01:15:36 +0000 |
parents | fecedf6d9ee1 |
children | 151004519917 |
comparison
equal
deleted
inserted
replaced
24924:380e7149a777 | 24925:1300601041ac |
---|---|
93 * check the number of field matches the expected_fields (<=0 means all) | 93 * check the number of field matches the expected_fields (<=0 means all) |
94 * return gchar* array (needs to be freed by g_strfreev later), or NULL */ | 94 * return gchar* array (needs to be freed by g_strfreev later), or NULL */ |
95 gchar **split_data(guint8 *data, gint len, const gchar *delimit, gint expected_fields) | 95 gchar **split_data(guint8 *data, gint len, const gchar *delimit, gint expected_fields) |
96 { | 96 { |
97 guint8 *input; | 97 guint8 *input; |
98 gchar **segments; | 98 gchar **segments, **seg; |
99 gint count, j; | 99 gint count = 0, j; |
100 | 100 |
101 g_return_val_if_fail(data != NULL && len != 0 && delimit != 0, NULL); | 101 g_return_val_if_fail(data != NULL && len != 0 && delimit != 0, NULL); |
102 | 102 |
103 /* as the last field would be string, but data is not ended with 0x00 | 103 /* as the last field would be string, but data is not ended with 0x00 |
104 * we have to duplicate the data and append a 0x00 at the end */ | 104 * we have to duplicate the data and append a 0x00 at the end */ |
105 input = g_newa(guint8, len + 1); | 105 input = g_newa(guint8, len + 1); |
106 g_memmove(input, data, len); | 106 g_memmove(input, data, len); |
107 input[len] = 0x00; | 107 input[len] = 0x00; |
108 | 108 |
109 segments = g_strsplit_set((gchar *) input, delimit, 0); | 109 segments = g_strsplit((gchar *) input, delimit, 0); |
110 if (expected_fields <= 0) | 110 if (expected_fields <= 0) |
111 return segments; | 111 return segments; |
112 | 112 |
113 count = g_strv_length(segments); | 113 for (seg = segments; *seg != NULL; seg++) |
114 count++; | |
114 if (count < expected_fields) { /* not enough fields */ | 115 if (count < expected_fields) { /* not enough fields */ |
115 purple_debug_error("QQ", "Less fields %d then %d\n", count, expected_fields); | 116 purple_debug_error("QQ", "Less fields %d then %d\n", count, expected_fields); |
116 return NULL; | 117 return NULL; |
117 } else if (count > expected_fields) { /* more fields, OK */ | 118 } else if (count > expected_fields) { /* more fields, OK */ |
118 purple_debug_warning("QQ", "More fields %d than %d\n", count, expected_fields); | 119 purple_debug_warning("QQ", "More fields %d than %d\n", count, expected_fields); |