comparison src/xmlnode.c @ 10415:5b7a74d397cc

[gaim-migrate @ 11665] Ability to save statuses. committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Sat, 25 Dec 2004 19:54:24 +0000
parents 20df7dd1c57c
children 3232e1a33899
comparison
equal deleted inserted replaced
10414:26eac2362c32 10415:5b7a74d397cc
83 parent->child = child; 83 parent->child = child;
84 } 84 }
85 } 85 }
86 86
87 void 87 void
88 xmlnode_insert_data(xmlnode *parent, const char *data, size_t size) 88 xmlnode_insert_data(xmlnode *node, const char *data, size_t size)
89 { 89 {
90 xmlnode *node; 90 xmlnode *child;
91 size_t real_size; 91 size_t real_size;
92 92
93 g_return_if_fail(parent != NULL); 93 g_return_if_fail(node != NULL);
94 g_return_if_fail(data != NULL); 94 g_return_if_fail(data != NULL);
95 g_return_if_fail(size != 0); 95 g_return_if_fail(size != 0);
96 96
97 real_size = size == -1 ? strlen(data) : size; 97 real_size = size == -1 ? strlen(data) : size;
98 98
99 node = new_node(NULL, XMLNODE_TYPE_DATA); 99 child = new_node(NULL, XMLNODE_TYPE_DATA);
100 100
101 node->data = g_memdup(data, real_size); 101 child->data = g_memdup(data, real_size);
102 node->data_sz = real_size; 102 child->data_sz = real_size;
103 103
104 xmlnode_insert_child(parent, node); 104 xmlnode_insert_child(node, child);
105 } 105 }
106 106
107 void 107 void
108 xmlnode_remove_attrib(xmlnode *node, const char *attr) 108 xmlnode_remove_attrib(xmlnode *node, const char *attr)
109 { 109 {
241 return NULL; 241 return NULL;
242 242
243 return g_string_free(str, FALSE); 243 return g_string_free(str, FALSE);
244 } 244 }
245 245
246 static char *xmlnode_to_str_helper(xmlnode *node, int *len, gboolean formatting, int depth) 246 static gchar *xmlnode_to_str_helper(xmlnode *node, int *len, gboolean formatting, int depth)
247 { 247 {
248 GString *text = g_string_new(""); 248 GString *text = g_string_new("");
249 xmlnode *c; 249 xmlnode *c;
250 char *node_name, *esc, *esc2, *tab = NULL; 250 char *node_name, *esc, *esc2, *tab = NULL;
251 gboolean need_end = FALSE, pretty = formatting; 251 gboolean need_end = FALSE, pretty = formatting;
295 } 295 }
296 } 296 }
297 297
298 if(tab && pretty) 298 if(tab && pretty)
299 text = g_string_append(text, tab); 299 text = g_string_append(text, tab);
300 g_string_append_printf(text, "</%s>%s", node_name, pretty ? newline : ""); 300 g_string_append_printf(text, "</%s>%s", node_name, formatting ? newline : "");
301 } else { 301 } else {
302 g_string_append_printf(text, "/>%s", pretty ? newline : ""); 302 g_string_append_printf(text, "/>%s", formatting ? newline : "");
303 } 303 }
304 304
305 g_free(node_name); 305 g_free(node_name);
306 306
307 if(tab) 307 if(tab)
311 *len = text->len; 311 *len = text->len;
312 312
313 return g_string_free(text, FALSE); 313 return g_string_free(text, FALSE);
314 } 314 }
315 315
316 char *xmlnode_to_str(xmlnode *node, int *len) { 316 gchar *xmlnode_to_str(xmlnode *node, int *len) {
317 return xmlnode_to_str_helper(node, len, FALSE, 0); 317 return xmlnode_to_str_helper(node, len, FALSE, 0);
318 } 318 }
319 319
320 char *xmlnode_to_formatted_str(xmlnode *node, int *len) { 320 gchar *xmlnode_to_formatted_str(xmlnode *node, int *len) {
321 return xmlnode_to_str_helper(node, len, TRUE, 0); 321 gchar *xml, *xml_with_declaration;
322
323 xml = xmlnode_to_str_helper(node, len, TRUE, 0);
324 xml_with_declaration =
325 g_strdup_printf("<?xml version='1.0' encoding='UTF-8' ?>\n\n%s", xml);
326 g_free(xml);
327
328 return xml_with_declaration;
322 } 329 }
323 330
324 struct _xmlnode_parser_data { 331 struct _xmlnode_parser_data {
325 xmlnode *current; 332 xmlnode *current;
326 }; 333 };