- Timestamp:
- 2013-04-20T13:05:55Z (12 years ago)
- Branches:
- master
- Children:
- dd95ce4
- Parents:
- 9b2a8c1 (diff), bfafb99 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- lib
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/xmltree.c
r9b2a8c1 re31e5b8 282 282 } 283 283 284 static void xt_to_string_real( struct xt_node *node, GString *str )284 static void xt_to_string_real( struct xt_node *node, GString *str, int indent ) 285 285 { 286 286 char *buf; … … 288 288 int i; 289 289 290 if( indent > 1 ) 291 g_string_append_len( str, "\n\t\t\t\t\t\t\t\t", 292 indent < 8 ? indent : 8 ); 293 290 294 g_string_append_printf( str, "<%s", node->name ); 291 295 … … 312 316 313 317 for( c = node->children; c; c = c->next ) 314 xt_to_string_real( c, str ); 318 xt_to_string_real( c, str, indent ? indent + 1 : 0 ); 319 320 if( indent > 0 && node->children ) 321 g_string_append_len( str, "\n\t\t\t\t\t\t\t\t", 322 indent < 8 ? indent : 8 ); 315 323 316 324 g_string_append_printf( str, "</%s>", node->name ); … … 320 328 { 321 329 GString *ret; 322 char *real;323 330 324 331 ret = g_string_new( "" ); 325 xt_to_string_real( node, ret ); 326 327 real = ret->str; 328 g_string_free( ret, FALSE ); 329 330 return real; 332 xt_to_string_real( node, ret, 0 ); 333 return g_string_free( ret, FALSE ); 334 } 335 336 /* WITH indentation! */ 337 char *xt_to_string_i( struct xt_node *node ) 338 { 339 GString *ret; 340 341 ret = g_string_new( "" ); 342 xt_to_string_real( node, ret, 1 ); 343 return g_string_free( ret, FALSE ); 331 344 } 332 345 333 346 void xt_print( struct xt_node *node ) 334 347 { 335 int i; 336 struct xt_node *c; 337 338 /* Indentation */ 339 for( c = node; c->parent; c = c->parent ) 340 fprintf( stderr, " " ); 341 342 /* Start the tag */ 343 fprintf( stderr, "<%s", node->name ); 344 345 /* Print the attributes */ 346 for( i = 0; node->attr[i].key; i ++ ) 347 { 348 char *v = g_markup_escape_text( node->attr[i].value, -1 ); 349 fprintf( stderr, " %s=\"%s\"", node->attr[i].key, v ); 350 g_free( v ); 351 } 352 353 /* /> in case there's really *nothing* inside this tag, otherwise 354 just >. */ 355 /* If this tag doesn't have any content at all... */ 356 if( node->text == NULL && node->children == NULL ) 357 { 358 fprintf( stderr, "/>\n" ); 359 return; 360 /* Then we're finished! */ 361 } 362 363 /* Otherwise... */ 364 fprintf( stderr, ">" ); 365 366 /* Only print the text if it contains more than whitespace (TEST). */ 367 if( node->text_len > 0 ) 368 { 369 for( i = 0; node->text[i] && isspace( node->text[i] ); i ++ ); 370 if( node->text[i] ) 371 { 372 char *v = g_markup_escape_text( node->text, -1 ); 373 fprintf( stderr, "%s", v ); 374 g_free( v ); 375 } 376 } 377 378 if( node->children ) 379 fprintf( stderr, "\n" ); 380 381 for( c = node->children; c; c = c->next ) 382 xt_print( c ); 383 384 if( node->children ) 385 for( c = node; c->parent; c = c->parent ) 386 fprintf( stderr, " " ); 387 388 /* Non-empty tag is now finished. */ 389 fprintf( stderr, "</%s>\n", node->name ); 348 char *str = xt_to_string_i( node ); 349 fprintf( stderr, "%s", str ); 350 g_free( str ); 390 351 } 391 352 -
lib/xmltree.h
r9b2a8c1 re31e5b8 84 84 struct xt_node *xt_from_string( const char *in, int text_len ); 85 85 char *xt_to_string( struct xt_node *node ); 86 char *xt_to_string_i( struct xt_node *node ); 86 87 void xt_print( struct xt_node *node ); 87 88 struct xt_node *xt_dup( struct xt_node *node );
Note: See TracChangeset
for help on using the changeset viewer.