Mercurial > pidgin.yaz
comparison src/xmlnode.c @ 12041:da44f68fb4d2
[gaim-migrate @ 14334]
Lee Roach noticed a little line ending inconsitency. This fixes it.
committer: Tailor Script <tailor@pidgin.im>
| author | Daniel Atallah <daniel.atallah@gmail.com> |
|---|---|
| date | Fri, 11 Nov 2005 05:13:02 +0000 |
| parents | 0906a3e9626c |
| children | 9679b615edb8 |
comparison
equal
deleted
inserted
replaced
| 12040:d225a55927df | 12041:da44f68fb4d2 |
|---|---|
| 32 #include <string.h> | 32 #include <string.h> |
| 33 #include <glib.h> | 33 #include <glib.h> |
| 34 | 34 |
| 35 #include "xmlnode.h" | 35 #include "xmlnode.h" |
| 36 | 36 |
| 37 #ifdef _WIN32 | |
| 38 # define NEWLINE_S "\r\n" | |
| 39 #else | |
| 40 # define NEWLINE_S "\n" | |
| 41 #endif | |
| 42 | |
| 37 static xmlnode* | 43 static xmlnode* |
| 38 new_node(const char *name, XMLNodeType type) | 44 new_node(const char *name, XMLNodeType type) |
| 39 { | 45 { |
| 40 xmlnode *node = g_new0(xmlnode, 1); | 46 xmlnode *node = g_new0(xmlnode, 1); |
| 41 | 47 |
| 250 { | 256 { |
| 251 GString *text = g_string_new(""); | 257 GString *text = g_string_new(""); |
| 252 xmlnode *c; | 258 xmlnode *c; |
| 253 char *node_name, *esc, *esc2, *tab = NULL; | 259 char *node_name, *esc, *esc2, *tab = NULL; |
| 254 gboolean need_end = FALSE, pretty = formatting; | 260 gboolean need_end = FALSE, pretty = formatting; |
| 255 #ifdef _WIN32 | |
| 256 static const char *newline = "\r\n"; | |
| 257 #else | |
| 258 static const char *newline = "\n"; | |
| 259 #endif | |
| 260 | 261 |
| 261 if(pretty && depth) { | 262 if(pretty && depth) { |
| 262 tab = g_strnfill(depth, '\t'); | 263 tab = g_strnfill(depth, '\t'); |
| 263 text = g_string_append(text, tab); | 264 text = g_string_append(text, tab); |
| 264 } | 265 } |
| 280 need_end = TRUE; | 281 need_end = TRUE; |
| 281 } | 282 } |
| 282 } | 283 } |
| 283 | 284 |
| 284 if(need_end) { | 285 if(need_end) { |
| 285 g_string_append_printf(text, ">%s", pretty ? newline : ""); | 286 g_string_append_printf(text, ">%s", pretty ? NEWLINE_S : ""); |
| 286 | 287 |
| 287 for(c = node->child; c; c = c->next) | 288 for(c = node->child; c; c = c->next) |
| 288 { | 289 { |
| 289 if(c->type == XMLNODE_TYPE_TAG) { | 290 if(c->type == XMLNODE_TYPE_TAG) { |
| 290 int esc_len; | 291 int esc_len; |
| 298 } | 299 } |
| 299 } | 300 } |
| 300 | 301 |
| 301 if(tab && pretty) | 302 if(tab && pretty) |
| 302 text = g_string_append(text, tab); | 303 text = g_string_append(text, tab); |
| 303 g_string_append_printf(text, "</%s>%s", node_name, formatting ? newline : ""); | 304 g_string_append_printf(text, "</%s>%s", node_name, formatting ? NEWLINE_S : ""); |
| 304 } else { | 305 } else { |
| 305 g_string_append_printf(text, "/>%s", formatting ? newline : ""); | 306 g_string_append_printf(text, "/>%s", formatting ? NEWLINE_S : ""); |
| 306 } | 307 } |
| 307 | 308 |
| 308 g_free(node_name); | 309 g_free(node_name); |
| 309 | 310 |
| 310 if(tab) | 311 if(tab) |
| 327 { | 328 { |
| 328 char *xml, *xml_with_declaration; | 329 char *xml, *xml_with_declaration; |
| 329 | 330 |
| 330 xml = xmlnode_to_str_helper(node, len, TRUE, 0); | 331 xml = xmlnode_to_str_helper(node, len, TRUE, 0); |
| 331 xml_with_declaration = | 332 xml_with_declaration = |
| 332 g_strdup_printf("<?xml version='1.0' encoding='UTF-8' ?>\n\n%s", xml); | 333 g_strdup_printf("<?xml version='1.0' encoding='UTF-8' ?>" NEWLINE_S NEWLINE_S "%s", xml); |
| 333 g_free(xml); | 334 g_free(xml); |
| 334 | 335 |
| 335 return xml_with_declaration; | 336 return xml_with_declaration; |
| 336 } | 337 } |
| 337 | 338 |
