Mercurial > pidgin
comparison src/xmlnode.c @ 9838:ad7fab671e6f
[gaim-migrate @ 10715]
this is a little cleaner
committer: Tailor Script <tailor@pidgin.im>
author | Nathan Walp <nwalp@pidgin.im> |
---|---|
date | Mon, 23 Aug 2004 05:17:59 +0000 |
parents | dafebadcf8d2 |
children | 20df7dd1c57c |
comparison
equal
deleted
inserted
replaced
9837:dafebadcf8d2 | 9838:ad7fab671e6f |
---|---|
244 } | 244 } |
245 | 245 |
246 return ret; | 246 return ret; |
247 } | 247 } |
248 | 248 |
249 static char *xmlnode_to_str_helper(xmlnode *node, int *len, gboolean pretty, int depth) | 249 static char *xmlnode_to_str_helper(xmlnode *node, int *len, gboolean formatting, int depth) |
250 { | 250 { |
251 char *ret; | 251 char *ret; |
252 GString *text = g_string_new(""); | 252 GString *text = g_string_new(""); |
253 xmlnode *c; | 253 xmlnode *c; |
254 char *node_name, *esc, *esc2, *tab = NULL; | 254 char *node_name, *esc, *esc2, *tab = NULL; |
255 gboolean need_end = FALSE, has_data = FALSE; | 255 gboolean need_end = FALSE, pretty = formatting; |
256 #ifdef _WIN32 | 256 #ifdef _WIN32 |
257 static const char *newline = "\r\n"; | 257 static const char *newline = "\r\n"; |
258 #else | 258 #else |
259 static const char *newline = "\n"; | 259 static const char *newline = "\n"; |
260 #endif | 260 #endif |
275 g_string_append_printf(text, " %s='%s'", esc, esc2); | 275 g_string_append_printf(text, " %s='%s'", esc, esc2); |
276 g_free(esc); | 276 g_free(esc); |
277 g_free(esc2); | 277 g_free(esc2); |
278 } else if(c->type == XMLNODE_TYPE_TAG || c->type == XMLNODE_TYPE_DATA) { | 278 } else if(c->type == XMLNODE_TYPE_TAG || c->type == XMLNODE_TYPE_DATA) { |
279 if(c->type == XMLNODE_TYPE_DATA) | 279 if(c->type == XMLNODE_TYPE_DATA) |
280 has_data = TRUE; | 280 pretty = FALSE; |
281 need_end = TRUE; | 281 need_end = TRUE; |
282 } | 282 } |
283 } | 283 } |
284 | 284 |
285 if(need_end) { | 285 if(need_end) { |
286 g_string_append_printf(text, ">%s", (pretty && !has_data) ? newline : ""); | 286 g_string_append_printf(text, ">%s", pretty ? newline : ""); |
287 | 287 |
288 for(c = node->child; c; c = c->next) | 288 for(c = node->child; c; c = c->next) |
289 { | 289 { |
290 if(c->type == XMLNODE_TYPE_TAG) { | 290 if(c->type == XMLNODE_TYPE_TAG) { |
291 int esc_len; | 291 int esc_len; |
292 esc = xmlnode_to_str_helper(c, &esc_len, (pretty && !has_data), depth+1); | 292 esc = xmlnode_to_str_helper(c, &esc_len, pretty, depth+1); |
293 text = g_string_append_len(text, esc, esc_len); | 293 text = g_string_append_len(text, esc, esc_len); |
294 g_free(esc); | 294 g_free(esc); |
295 } else if(c->type == XMLNODE_TYPE_DATA) { | 295 } else if(c->type == XMLNODE_TYPE_DATA) { |
296 esc = g_markup_escape_text(c->data, c->data_sz); | 296 esc = g_markup_escape_text(c->data, c->data_sz); |
297 text = g_string_append(text, esc); | 297 text = g_string_append(text, esc); |
298 g_free(esc); | 298 g_free(esc); |
299 } | 299 } |
300 } | 300 } |
301 | 301 |
302 if(tab && pretty && !has_data) | 302 if(tab && pretty) |
303 text = g_string_append(text, tab); | 303 text = g_string_append(text, tab); |
304 g_string_append_printf(text, "</%s>%s", node_name, pretty ? newline : ""); | 304 g_string_append_printf(text, "</%s>%s", node_name, pretty ? newline : ""); |
305 } else { | 305 } else { |
306 g_string_append_printf(text, "/>%s", pretty ? newline : ""); | 306 g_string_append_printf(text, "/>%s", pretty ? newline : ""); |
307 } | 307 } |