- Timestamp:
- 2007-10-12T00:06:50Z (17 years ago)
- Branches:
- master
- Children:
- 3933853, c78c032, eda54e4
- Parents:
- 285b55d
- Location:
- lib
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/misc.c
r285b55d rd444c09 545 545 return reply; 546 546 } 547 548 /* Word wrapping. Yes, I know this isn't UTF-8 clean. I'm willing to take the risk. */ 549 char *word_wrap( char *msg, int line_len ) 550 { 551 GString *ret = g_string_sized_new( strlen( msg ) + 16 ); 552 553 while( strlen( msg ) > line_len ) 554 { 555 int i; 556 557 /* First try to find out if there's a newline already. Don't 558 want to add more splits than necessary. */ 559 for( i = line_len; i > 0 && msg[i] != '\n'; i -- ); 560 if( msg[i] == '\n' ) 561 { 562 g_string_append_len( ret, msg, i + 1 ); 563 msg += i + 1; 564 continue; 565 } 566 567 for( i = line_len; i > 0; i -- ) 568 { 569 if( msg[i] == '-' ) 570 { 571 g_string_append_len( ret, msg, i + 1 ); 572 g_string_append_c( ret, '\n' ); 573 msg += i + 1; 574 break; 575 } 576 else if( msg[i] == ' ' ) 577 { 578 g_string_append_len( ret, msg, i ); 579 g_string_append_c( ret, '\n' ); 580 msg += i + 1; 581 break; 582 } 583 } 584 if( i == 0 ) 585 { 586 g_string_append_len( ret, msg, line_len ); 587 g_string_append_c( ret, '\n' ); 588 msg += line_len; 589 } 590 } 591 g_string_append( ret, msg ); 592 593 return g_string_free( ret, FALSE ); 594 } -
lib/misc.h
r285b55d rd444c09 64 64 G_MODULE_EXPORT struct ns_srv_reply *srv_lookup( char *service, char *protocol, char *domain ); 65 65 66 G_MODULE_EXPORT char *word_wrap( char *msg, int line_len ); 67 66 68 #endif
Note: See TracChangeset
for help on using the changeset viewer.