libpurple/protocols/gg/utils.c

changeset 35357
389e413e3414
parent 35144
3590ceb242b5
child 35361
efdbd45604f1
equal deleted inserted replaced
35356:3a71df246d07 35357:389e413e3414
51 } 51 }
52 52
53 const char * ggp_uin_to_str(uin_t uin) 53 const char * ggp_uin_to_str(uin_t uin)
54 { 54 {
55 static char buff[GGP_UIN_LEN_MAX + 1]; 55 static char buff[GGP_UIN_LEN_MAX + 1];
56 56
57 g_snprintf(buff, GGP_UIN_LEN_MAX + 1, "%u", uin); 57 g_snprintf(buff, GGP_UIN_LEN_MAX + 1, "%u", uin);
58 58
59 return buff; 59 return buff;
60 } 60 }
61 61
62 uin_t ggp_get_my_uin(PurpleConnection *gc) 62 uin_t ggp_get_my_uin(PurpleConnection *gc)
63 { 63 {
64 g_return_val_if_fail(gc != NULL, 0); 64 g_return_val_if_fail(gc != NULL, 0);
65 65
66 return ggp_str_to_uin(purple_account_get_username( 66 return ggp_str_to_uin(purple_account_get_username(
67 purple_connection_get_account(gc))); 67 purple_connection_get_account(gc)));
68 } 68 }
69 69
70 static gchar * ggp_convert(const gchar *src, const char *srcenc, 70 static gchar * ggp_convert(const gchar *src, const char *srcenc,
116 gchar *end_ptr; 116 gchar *end_ptr;
117 if (str == NULL) 117 if (str == NULL)
118 return NULL; 118 return NULL;
119 if (raw_len <= n) 119 if (raw_len <= n)
120 return g_strdup(str); 120 return g_strdup(str);
121 121
122 end_ptr = g_utf8_offset_to_pointer(str, g_utf8_pointer_to_offset(str, &str[n])); 122 end_ptr = g_utf8_offset_to_pointer(str, g_utf8_pointer_to_offset(str, &str[n]));
123 raw_len = end_ptr - str; 123 raw_len = end_ptr - str;
124 124
125 if (raw_len > n) 125 if (raw_len > n)
126 { 126 {
127 end_ptr = g_utf8_prev_char(end_ptr); 127 end_ptr = g_utf8_prev_char(end_ptr);
128 raw_len = end_ptr - str; 128 raw_len = end_ptr - str;
129 } 129 }
130 130
131 g_assert(raw_len <= n); 131 g_assert(raw_len <= n);
132 132
133 return g_strndup(str, raw_len); 133 return g_strndup(str, raw_len);
134 } 134 }
135 135
136 GSList * ggp_list_copy_to_slist_deep(GList *list, GCopyFunc func, 136 GSList * ggp_list_copy_to_slist_deep(GList *list, GCopyFunc func,
137 gpointer user_data) 137 gpointer user_data)
138 { 138 {
139 GSList *new_list = NULL; 139 GSList *new_list = NULL;
140 GList *it; 140 GList *it;
141 141
142 it = g_list_first(list); 142 it = g_list_first(list);
143 while (it) 143 while (it)
144 { 144 {
145 new_list = g_slist_append(new_list, func(it->data, user_data)); 145 new_list = g_slist_append(new_list, func(it->data, user_data));
146 it = g_list_next(it); 146 it = g_list_next(it);
151 GList * ggp_strsplit_list(const gchar *string, const gchar *delimiter, 151 GList * ggp_strsplit_list(const gchar *string, const gchar *delimiter,
152 gint max_tokens) 152 gint max_tokens)
153 { 153 {
154 gchar **splitted, **it; 154 gchar **splitted, **it;
155 GList *list = NULL; 155 GList *list = NULL;
156 156
157 it = splitted = g_strsplit(string, delimiter, max_tokens); 157 it = splitted = g_strsplit(string, delimiter, max_tokens);
158 while (*it) 158 while (*it)
159 { 159 {
160 list = g_list_append(list, *it); 160 list = g_list_append(list, *it);
161 it++; 161 it++;
162 } 162 }
163 g_free(splitted); 163 g_free(splitted);
164 164
165 return list; 165 return list;
166 } 166 }
167 167
168 gchar * ggp_strjoin_list(const gchar *separator, GList *list) 168 gchar * ggp_strjoin_list(const gchar *separator, GList *list)
169 { 169 {
170 gchar **str_array; 170 gchar **str_array;
171 gchar *joined; 171 gchar *joined;
172 gint list_len, i; 172 gint list_len, i;
173 GList *it; 173 GList *it;
174 174
175 list_len = g_list_length(list); 175 list_len = g_list_length(list);
176 str_array = g_new(gchar*, list_len + 1); 176 str_array = g_new(gchar*, list_len + 1);
177 177
178 it = g_list_first(list); 178 it = g_list_first(list);
179 i = 0; 179 i = 0;
180 while (it) 180 while (it)
181 { 181 {
182 str_array[i++] = it->data; 182 str_array[i++] = it->data;
183 it = g_list_next(it); 183 it = g_list_next(it);
184 } 184 }
185 str_array[i] = NULL; 185 str_array[i] = NULL;
186 186
187 joined = g_strjoinv(separator, str_array); 187 joined = g_strjoinv(separator, str_array);
188 g_free(str_array); 188 g_free(str_array);
189 189
190 return joined; 190 return joined;
191 } 191 }
192 192
193 const gchar * ggp_ipv4_to_str(uint32_t raw_ip) 193 const gchar * ggp_ipv4_to_str(uint32_t raw_ip)
194 { 194 {
227 227
228 const gchar * ggp_date_strftime(const gchar *format, time_t date) 228 const gchar * ggp_date_strftime(const gchar *format, time_t date)
229 { 229 {
230 GDate g_date; 230 GDate g_date;
231 static gchar buff[30]; 231 static gchar buff[30];
232 232
233 g_date_set_time_t(&g_date, date); 233 g_date_set_time_t(&g_date, date);
234 if (0 == g_date_strftime(buff, sizeof(buff), format, &g_date)) 234 if (0 == g_date_strftime(buff, sizeof(buff), format, &g_date))
235 return NULL; 235 return NULL;
236 return buff; 236 return buff;
237 } 237 }
238 238
239 time_t ggp_date_from_iso8601(const gchar *str) 239 time_t ggp_date_from_iso8601(const gchar *str)
240 { 240 {
241 GTimeVal g_timeval; 241 GTimeVal g_timeval;
242 242
243 if (!str) 243 if (!str)
244 return 0; 244 return 0;
245 if (!g_time_val_from_iso8601(str, &g_timeval)) 245 if (!g_time_val_from_iso8601(str, &g_timeval))
246 return 0; 246 return 0;
247 return g_timeval.tv_sec; 247 return g_timeval.tv_sec;

mercurial